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,
impl<T> GraphBuffer<T>where
T: DeviceRepr,
Sourcepub fn context(&self) -> &Arc<Context> ⓘ
pub fn context(&self) -> &Arc<Context> ⓘ
Returns the context retained by the buffer allocation.
Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns the CUDA-accessible element pointer without synchronizing graph work.
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
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.
Sourcepub fn copy_from_host(&mut self, host_slice: &[T]) -> Result<()>
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.
Sourcepub fn copy_to_host(&self, host_slice: &mut [T]) -> Result<()>where
T: AnyBitPatternDeviceRepr,
pub fn copy_to_host(&self, host_slice: &mut [T]) -> Result<()>where
T: AnyBitPatternDeviceRepr,
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.
Sourcepub unsafe fn copy_to_host_unchecked(&self, host_slice: &mut [T]) -> Result<()>
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.
Sourcepub fn copy_from_buffer<S: DeviceSlice<T> + ?Sized>(
&mut self,
src: &S,
) -> Result<()>
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.
Sourcepub fn copy_to_host_vec(&self) -> Result<Vec<T>>where
T: AnyBitPatternDeviceRepr,
pub fn copy_to_host_vec(&self) -> Result<Vec<T>>where
T: AnyBitPatternDeviceRepr,
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.
Sourcepub unsafe fn copy_to_host_vec_unchecked(&self) -> Result<Vec<T>>
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.
Sourcepub fn allocation(&self) -> &Arc<DeviceAllocation> ⓘ
pub fn allocation(&self) -> &Arc<DeviceAllocation> ⓘ
Returns the allocation retained by graph definitions, executables, and foreign owners.
Sourcepub fn view(&self) -> DeviceView<'_, T>
pub fn view(&self) -> DeviceView<'_, T>
Borrows the initialized buffer as a shared device view.
Sourcepub fn view_mut(&mut self) -> DeviceViewMut<'_, T>
pub fn view_mut(&mut self) -> DeviceViewMut<'_, T>
Borrows the initialized buffer as an exclusive device view.
Sourcepub fn cast<U: AnyBitPatternDeviceRepr>(self) -> StdResult<GraphBuffer<U>, Self>where
T: NoUninitDeviceRepr,
pub fn cast<U: AnyBitPatternDeviceRepr>(self) -> StdResult<GraphBuffer<U>, Self>where
T: NoUninitDeviceRepr,
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.
Sourcepub fn into_uninit(self) -> GraphBuffer<MaybeUninit<T>>
pub fn into_uninit(self) -> GraphBuffer<MaybeUninit<T>>
Erases initialization while preserving graph-retained allocation ownership.
Source§impl<T: DeviceRepr> GraphBuffer<MaybeUninit<T>>
impl<T: DeviceRepr> GraphBuffer<MaybeUninit<T>>
Sourcepub fn output(&mut self) -> DeviceOutputView<'_, T>
pub fn output(&mut self) -> DeviceOutputView<'_, T>
Borrows the uninitialized buffer as a write-only destination of T values.
Sourcepub unsafe fn assume_init(self) -> GraphBuffer<T>
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.