Skip to main content

GraphBuffer

Struct GraphBuffer 

Source
pub struct GraphBuffer<T: DeviceRepr> { /* private fields */ }
Expand description

Device memory whose allocation is retained by CUDA graph objects.

GraphBuffer values are created through Graph::create_buffer_uninit, Graph::zeroed_buffer, or Graph::buffer_from_slice. Graph and executable-graph APIs that accept GraphBuffer retain the underlying allocation so graph replay cannot outlive the device pointers baked into CUDA graph nodes. Each resource snapshot retains a given allocation owner once, including after graph updates and child-graph merges.

Implementations§

Source§

impl<T> GraphBuffer<T>
where T: DeviceRepr,

Source

pub fn len(&self) -> usize

Returns the number of exposed elements.

Source

pub fn is_empty(&self) -> bool

Returns whether the exposed element range is empty.

Source

pub fn byte_len(&self) -> usize

Returns the byte length of the exposed element range.

Source

pub fn context(&self) -> &Arc<Context> ⓘ

Returns the context retained by the buffer allocation.

Source

pub fn as_ptr(&self) -> *const T

Returns the CUDA-accessible element pointer without synchronizing graph work.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Returns the CUDA-accessible mutable element pointer.

The caller must order raw accesses against graph launches using this allocation.

Source

pub fn copy_from_host(&mut self, host_slice: &[T]) -> Result<()>

Copies a host slice into this graph-retained device buffer.

This updates the stable allocation used by graph-buffer node APIs. The caller is still responsible for ordering this copy against graph launches that read or write the same allocation.

§Errors

Returns an error if host_slice does not have the same length as this buffer or if CUDA rejects the copy.

Source

pub fn copy_to_host(&self, host_slice: &mut [T]) -> Result<()>

Copies this graph-retained device buffer into a host slice.

§Errors

Returns an error if host_slice does not have the same length as this buffer or if CUDA rejects the copy.

Source

pub unsafe fn copy_to_host_unchecked(&self, host_slice: &mut [T]) -> Result<()>

Copies graph-buffer values whose validity follows from the graph’s kernels.

§Safety

Every copied element must be initialized and valid for T. The copy must be ordered after all graph writes to this buffer.

§Errors

Returns an error for unequal element counts or byte-size overflow. Also propagates context-binding, stream-capture, CUDA copy, and stream synchronization errors.

Source

pub fn copy_from_buffer<S: DeviceSlice<T> + ?Sized>( &mut self, src: &S, ) -> Result<()>

Copies another graph-retained buffer into this buffer.

§Errors

Returns an error if the buffers have different lengths or if CUDA rejects the copy.

Source

pub fn copy_to_host_vec(&self) -> Result<Vec<T>>

Copies every element into a new host vector and waits for completion.

§Errors

Propagates byte-size, context-binding, stream-capture, CUDA copy, and stream synchronization errors. No initialized vector is returned unless the transfer completes.

Source

pub unsafe fn copy_to_host_vec_unchecked(&self) -> Result<Vec<T>>

Reads graph output values whose validity follows from the producing kernels.

§Safety

All elements must be initialized and valid for T, and graph writes must finish before this readback.

§Errors

Propagates byte-size, context-binding, stream-capture, CUDA copy, and stream synchronization errors. No initialized vector is returned unless the transfer completes.

Source

pub fn allocation(&self) -> &Arc<DeviceAllocation> ⓘ

Returns the allocation retained by graph definitions, executables, and foreign owners.

Source

pub fn view(&self) -> DeviceView<'_, T>

Borrows the initialized buffer as a shared device view.

Source

pub fn view_mut(&mut self) -> DeviceViewMut<'_, T>

Borrows the initialized buffer as an exclusive device view.

Source

pub fn cast<U: AnyBitPatternDeviceRepr>(self) -> StdResult<GraphBuffer<U>, Self>

Reinterprets initialized bytes without changing graph-retained allocation ownership.

§Errors

Returns the original buffer if the destination type is zero-sized, its size does not divide the exposed byte length, or a nonempty range is not aligned for the destination type.

Source

pub fn into_uninit(self) -> GraphBuffer<MaybeUninit<T>>

Erases initialization while preserving graph-retained allocation ownership.

Source§

impl<T: DeviceRepr> GraphBuffer<MaybeUninit<T>>

Source

pub fn output(&mut self) -> DeviceOutputView<'_, T>

Borrows the uninitialized buffer as a write-only destination of T values.

Source

pub unsafe fn assume_init(self) -> GraphBuffer<T>

Marks all values initialized after their producing work completes.

§Safety

Every element must be valid, and producing work must complete or be ordered before every consumer. Recording a graph does not establish initialization; only its successful execution can do so.

Source

pub unsafe fn assume_init_prefix(self, length: usize) -> Result<GraphBuffer<T>>

Exposes only a produced prefix while retaining the full graph allocation.

§Safety

Every prefix element must be valid, with producer completion and ordering satisfying assume_init.

§Errors

Returns an error if length exceeds the currently exposed element count.

Trait Implementations§

Source§

impl<T: Debug + DeviceRepr> Debug for GraphBuffer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: DeviceRepr> DeviceOutput<T> for GraphBuffer<T>

Source§

fn as_mut_ptr(&mut self) -> *mut T

Returns a pointer to the writable device output range. Read more
Source§

impl<T: DeviceRepr> DeviceOutput<T> for GraphBuffer<MaybeUninit<T>>

Source§

fn as_mut_ptr(&mut self) -> *mut T

Returns a pointer to the writable device output range. Read more
Source§

impl<T: DeviceRepr> DeviceRange<T> for GraphBuffer<T>

Source§

fn as_device_ptr(&self) -> *const T

Returns the device input pointer without asserting that its values are initialized. Read more
Source§

fn len(&self) -> usize

Returns the number of input elements.
Source§

fn context(&self) -> &Arc<Context> ⓘ

Returns the context associated with the input allocation.
Source§

fn is_empty(&self) -> bool

Returns whether the input range contains no elements.
Source§

fn byte_len(&self) -> Result<usize>

Returns the input range length in bytes. Read more
Source§

impl<T: DeviceRepr> DeviceRange<T> for GraphBuffer<MaybeUninit<T>>

Source§

fn len(&self) -> usize

Returns the number of input elements.
Source§

fn context(&self) -> &Arc<Context> ⓘ

Returns the context associated with the input allocation.
Source§

fn as_device_ptr(&self) -> *const T

Returns the device input pointer without asserting that its values are initialized. Read more
Source§

fn is_empty(&self) -> bool

Returns whether the input range contains no elements.
Source§

fn byte_len(&self) -> Result<usize>

Returns the input range length in bytes. Read more
Source§

impl<T: DeviceRepr> DeviceRegionProvider for GraphBuffer<T>

Source§

fn region(&self) -> DeviceRegion<'_>

Borrows the exact allocation range described by this provider’s pointers.
Source§

impl<T: DeviceRepr> DeviceSlice<T> for GraphBuffer<T>

Source§

impl<T: DeviceRepr> DeviceSliceMut<T> for GraphBuffer<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for GraphBuffer<T>

§

impl<T> !UnwindSafe for GraphBuffer<T>

§

impl<T> Forget for GraphBuffer<T>

§

impl<T> Freeze for GraphBuffer<T>
where DeviceMemory<T>: Freeze,

§

impl<T> Move for GraphBuffer<T>

§

impl<T> Send for GraphBuffer<T>
where DeviceMemory<T>: Send,

§

impl<T> Sync for GraphBuffer<T>
where DeviceMemory<T>: Sync,

§

impl<T> Unpin for GraphBuffer<T>
where DeviceMemory<T>: Unpin,

§

impl<T> UnsafeUnpin for GraphBuffer<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.