Skip to main content

SharedArray

Struct SharedArray 

Source
pub struct SharedArray<T> { /* private fields */ }
Expand description

A block-wide __shared__ array. Obtain one with ThreadCtx::shared.

Implementations§

Source§

impl<T: Copy + Default + Send + 'static> SharedArray<T>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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
Hide additional 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}
Source

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
Hide additional 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§

Source§

impl<T> Clone for SharedArray<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Forget for SharedArray<T>

§

impl<T> Freeze for SharedArray<T>
where Arc<SharedInner<T>>: Freeze,

§

impl<T> Move for SharedArray<T>

§

impl<T> RefUnwindSafe for SharedArray<T>
where Arc<SharedInner<T>>: RefUnwindSafe,

§

impl<T> Send for SharedArray<T>
where Arc<SharedInner<T>>: Send,

§

impl<T> Sync for SharedArray<T>
where Arc<SharedInner<T>>: Sync,

§

impl<T> Unpin for SharedArray<T>
where Arc<SharedInner<T>>: Unpin,

§

impl<T> UnsafeUnpin for SharedArray<T>
where Arc<SharedInner<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for SharedArray<T>
where Arc<SharedInner<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.