pub struct Grid { /* private fields */ }Expand description
A hart’s view of an SPMD launch: its identity within n_harts participants.
The safety story of the reduction demo lives here. A kernel body, given a
Grid, can obtain only its own disjoint slice of the input and its own
output cell – it has no way to name another hart’s data, so cross-hart data
races are unrepresentable in the (safe) kernel body. The small unsafe
boundary that turns device addresses into slices is confined to this module.
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn new(n_harts: u32) -> Self
pub fn new(n_harts: u32) -> Self
Build from the current hart’s id and the number of participating harts.
pub fn hart(&self) -> u32
pub fn n_harts(&self) -> u32
Sourcepub fn active(&self) -> bool
pub fn active(&self) -> bool
Whether this hart participates (the launch runs every hart of the shire, so surplus harts opt out).
Sourcepub fn my_slice<'a, T>(&self, data: &'a [T]) -> &'a [T]
pub fn my_slice<'a, T>(&self, data: &'a [T]) -> &'a [T]
Borrow this hart’s disjoint sub-slice of data.
Sourcepub unsafe fn output_cell<'a, T>(&self, base: usize) -> &'a mut T
pub unsafe fn output_cell<'a, T>(&self, base: usize) -> &'a mut T
Borrow this hart’s own output cell from an array of one cache-line-padded
T per hart based at device address base.
§Safety
base must address at least n_harts * CACHE_LINE writable bytes of
device memory. Disjointness across harts is guaranteed by construction
(distinct hart ids map to distinct cache lines).