pub struct SharedArray<T> { /* private fields */ }Expand description
A block-wide __shared__ array. Obtain one with ThreadCtx::shared.
Implementations§
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn read(&self, ctx: &ThreadCtx<'_>, index: usize) -> T
pub fn read(&self, ctx: &ThreadCtx<'_>, index: usize) -> T
Examples found in repository?
examples/reduction.rs (line 21)
12fn reduce(t: &ThreadCtx<'_>, input: &GlobalBuf<u32>, partial: &GlobalBuf<u32>, buggy: bool) {
13 let tile = t.shared::<u32>("tile", BLOCK as usize);
14 let i = t.thread_linear();
15 tile.write(t, i, input.read(t, t.global_linear()));
16 t.sync_threads();
17
18 let mut stride = BLOCK as usize / 2;
19 while stride > 0 {
20 if i < stride {
21 let sum = tile.read(t, i) + tile.read(t, i + stride);
22 tile.write(t, i, sum);
23 }
24 if !buggy {
25 t.sync_threads();
26 }
27 stride /= 2;
28 }
29
30 if i == 0 {
31 partial.write(t, t.block_linear(), tile.read(t, 0));
32 }
33}More examples
examples/shrink.rs (line 37)
26fn structural() {
27 const THREADS: u32 = 64;
28 let config = LaunchConfig::new(1, THREADS);
29
30 let found = Explore::new(&config).seeds(64).run_with(|| {
31 let out = GlobalBuf::new("out", vec![0u32; THREADS as usize]);
32 move |t: &ThreadCtx<'_>| {
33 let tile = t.shared::<u32>("tile", THREADS as usize);
34 let i = t.thread_linear();
35 tile.write(t, i, i as u32);
36 // BUG: no t.sync_threads() before reading a neighbour's slot.
37 out.write(t, i, tile.read(t, (i + 1) % THREADS as usize));
38 }
39 });
40
41 println!("== missing barrier");
42 print!("{found}");
43
44 if let Some(f) = &found.failure {
45 if let Some(s) = f.shrink.schedule() {
46 println!(
47 " {} decisions shrunk to {}: {:?}",
48 f.decisions,
49 s.len(),
50 s.plan()
51 );
52 if s.is_empty() {
53 println!(" an empty schedule means threads in order already hit it");
54 }
55 }
56 }
57}Sourcepub fn write(&self, ctx: &ThreadCtx<'_>, index: usize, value: T)
pub fn write(&self, ctx: &ThreadCtx<'_>, index: usize, value: T)
Examples found in repository?
examples/reduction.rs (line 15)
12fn reduce(t: &ThreadCtx<'_>, input: &GlobalBuf<u32>, partial: &GlobalBuf<u32>, buggy: bool) {
13 let tile = t.shared::<u32>("tile", BLOCK as usize);
14 let i = t.thread_linear();
15 tile.write(t, i, input.read(t, t.global_linear()));
16 t.sync_threads();
17
18 let mut stride = BLOCK as usize / 2;
19 while stride > 0 {
20 if i < stride {
21 let sum = tile.read(t, i) + tile.read(t, i + stride);
22 tile.write(t, i, sum);
23 }
24 if !buggy {
25 t.sync_threads();
26 }
27 stride /= 2;
28 }
29
30 if i == 0 {
31 partial.write(t, t.block_linear(), tile.read(t, 0));
32 }
33}More examples
examples/shrink.rs (line 35)
26fn structural() {
27 const THREADS: u32 = 64;
28 let config = LaunchConfig::new(1, THREADS);
29
30 let found = Explore::new(&config).seeds(64).run_with(|| {
31 let out = GlobalBuf::new("out", vec![0u32; THREADS as usize]);
32 move |t: &ThreadCtx<'_>| {
33 let tile = t.shared::<u32>("tile", THREADS as usize);
34 let i = t.thread_linear();
35 tile.write(t, i, i as u32);
36 // BUG: no t.sync_threads() before reading a neighbour's slot.
37 out.write(t, i, tile.read(t, (i + 1) % THREADS as usize));
38 }
39 });
40
41 println!("== missing barrier");
42 print!("{found}");
43
44 if let Some(f) = &found.failure {
45 if let Some(s) = f.shrink.schedule() {
46 println!(
47 " {} decisions shrunk to {}: {:?}",
48 f.decisions,
49 s.len(),
50 s.plan()
51 );
52 if s.is_empty() {
53 println!(" an empty schedule means threads in order already hit it");
54 }
55 }
56 }
57}Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more