[Migrated] Language feature: barriers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng việc xem xét GroupSharedArray, GroupSharedWriter, GroupSharedReader và ví dụ barrier trong issue. Điều tra hạn chế DerefMut/IndexMut đã nêu và các trường hợp cho phép ghi hoặc đọc lặp lại; công việc chỉ được xem là hoàn tất khi có một thiết kế rõ ràng, hợp lý để thực thi các barrier, thay vì prototype chưa hoàn chỉnh hiện tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Issue automatically imported from old repo: https://github.com/EmbarkStudios/rust-gpu/issues/8
Old labels: t: design
Originally creatd by Jasper-Bekkers on 2020-08-18T17:33:10Z
We want to have the same types of safety on the GPU as we do on the CPU. One of those areas that make it easy to introduce race conditions is with memory barriers. HLSL and GLSL require the programmer to explicitly put them in the right locations without any formal verifiction.
This is an attempt at solving that within the Rust type system (attempt still has racy bugs and is largely incomplete).
use core::ops::Deref;
use core::ops::DerefMut;
use core::ops::Index;
use core::ops::IndexMut;
struct MyFoo {
test: GroupSharedArray<u32>,
}
struct GroupSharedArray<T>
where
T: Default + Copy,
{
data: Box<[T]>,
size: usize,
}
impl<T: Default + Copy> GroupSharedArray<T> {
fn new() -> Self {
Self {
size: 100,
data: Box::new([T::default(); 100]),
}
}
}
struct GroupSharedWriter<T> {
data: T,
}
impl<T> Deref for GroupSharedWriter<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl<T> DerefMut for GroupSharedWriter<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.data
}
}
impl<T> GroupSharedWriter<T> {
fn new(data: T) -> Self {
Self { data }
}
fn barrier(self) -> GroupSharedReader<T> {
GroupSharedReader { data: self.data }
}
}
struct GroupSharedReader<T> {
data: T,
}
impl<T> Deref for GroupSharedReader<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl<T> GroupSharedReader<T> {
fn barrier(self) -> GroupSharedWriter<T> {
GroupSharedWriter { data: self.data }
}
}
impl<T: Default + Copy> Index<Uniform<u32>> for GroupSharedArray<T> {
type Output = T;
fn index(&self, index: Uniform<u32>) -> &Self::Output {
&self.data[index.data as usize]
}
}
impl<T: Default + Copy> IndexMut<Uniform<u32>> for GroupSharedArray<T> {
fn index_mut(&mut self, index: Uniform<u32>) -> &mut Self::Output {
&mut self.data[index.data as usize]
}
}
struct Uniform<T> {
data: T,
}
impl<T> Uniform<T> {
fn new(data: T) -> Self {
Self { data }
}
}
fn thread_idx() -> Uniform<u32> {
Uniform::new(0)
}
fn main() {
let mut data = GroupSharedWriter::new(MyFoo {
test: GroupSharedArray::new(),
}); // new does barrier
data.test[thread_idx()] = thread_idx().data;
data.test[thread_idx()] = 666; // should be illegal
let value = data.test[thread_idx()]; // should be illegal
//data.test[0] = thread_idx().data; // what happens in this case? it's unsafe/unsound. race cnd over contents of `test`
let other_data = data.barrier(); // `barrier` return GroupSharedReader
// some race-y cases handled correctly:
// data.test[thread_idx()] = 666; // is correctly marked illegal
// other_data.test[thread_idx()] = 666; // is correctly marked illegal
let test = other_data.data.test[thread_idx()];
}
// tl;dr
// - use move semantics to enforce barriers betwen reading and writing
// - broken right now because DerefMut and IndexMut require Deref and Index to be implemented
// - broken right now because we can write to the same location multiple times (data race)
- Ngôn ngữ chính
- Rust
- Star
- 3.4k
- Fork
- 126
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Rust-GPU/rust-gpu
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
enhancement
Rust-GPU/rust-gpu#643 · 2 bình luận · 1 reaction · 1 người được giao ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
async functions cause ICE Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Tất cả issue của Rust-GPU/rust-gpu
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100