[Migrated] Language feature: barriers
まだ誰も着手していません。
評価
調査の方向性
まず、issue にある GroupSharedArray、GroupSharedWriter、GroupSharedReader、および barrier の例を確認します。記載されている DerefMut/IndexMut の制限と、書き込みまたは読み取りの繰り返しを許可するケースを調査します。完了条件は、現在の不完全なプロトタイプではなく、barrier を強制するための明確で健全な設計が決定されていることです。
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- Rust
- スター
- 3.4k
- フォーク
- 126
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Rust-GPU/rust-gpu のほかの issue
-
enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
-
enhancement
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
Rust-GPU/rust-gpu の issue をすべて見る
似ている issue
-
risk:low runtime status:in-progress type:test
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
EricSpencer00/Resilient#4835 · コメント 1 件 ·
-
agent:ready documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cesarferreira/stax#890 ·
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100