Skip to main content

Grid

Struct Grid 

Source
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

Source

pub fn new(n_harts: u32) -> Self

Build from the current hart’s id and the number of participating harts.

Source

pub fn hart(&self) -> u32

Source

pub fn n_harts(&self) -> u32

Source

pub fn active(&self) -> bool

Whether this hart participates (the launch runs every hart of the shire, so surplus harts opt out).

Source

pub fn my_slice<'a, T>(&self, data: &'a [T]) -> &'a [T]

Borrow this hart’s disjoint sub-slice of data.

Source

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).

Auto Trait Implementations§

§

impl Freeze for Grid

§

impl RefUnwindSafe for Grid

§

impl Send for Grid

§

impl Sync for Grid

§

impl Unpin for Grid

§

impl UnsafeUnpin for Grid

§

impl UnwindSafe for Grid

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.