Skip to main content

StreamCapture

Struct StreamCapture 

Source
pub struct StreamCapture { /* private fields */ }
Expand description

Records GPU operations submitted to a stream into a Graph.

Stream capture intercepts operations that would normally be submitted to a CUDA stream and instead records them as graph nodes. The captured operations can then be replayed efficiently via GraphExec.

§Usage

let mut capture = StreamCapture::begin(&stream)?;

capture.record_kernel("my_kernel", (4, 1, 1), (256, 1, 1), 0);
capture.record_memcpy(MemcpyDirection::DeviceToHost, 1024);

let graph = capture.end()?;
assert_eq!(graph.node_count(), 2);

Implementations§

Source§

impl StreamCapture

Source

pub fn begin(_stream: &Stream) -> CudaResult<Self>

Begins capturing operations on the given stream.

On a real CUDA system, this would call cuStreamBeginCapture(stream, CU_STREAM_CAPTURE_MODE_GLOBAL).

§Errors

Returns CudaError::NotInitialized if the CUDA driver is not available.

Source

pub fn record_kernel( &mut self, function_name: &str, grid: (u32, u32, u32), block: (u32, u32, u32), shared_mem: u32, )

Records a kernel launch operation in the capture.

§Parameters
  • function_name - Name of the kernel function.
  • grid - Grid dimensions (x, y, z).
  • block - Block dimensions (x, y, z).
  • shared_mem - Dynamic shared memory in bytes.
Source

pub fn record_memcpy(&mut self, direction: MemcpyDirection, size: usize)

Records a memory copy operation in the capture.

§Parameters
  • direction - Direction of the memory copy.
  • size - Size of the transfer in bytes.
Source

pub fn record_memset(&mut self, size: usize, value: u8)

Records a memset operation in the capture.

§Parameters
  • size - Number of bytes to set.
  • value - Byte value to fill with.
Source

pub fn recorded_count(&self) -> usize

Returns the number of operations recorded so far.

Source

pub fn is_active(&self) -> bool

Returns whether the capture is still active.

Source

pub fn end(self) -> CudaResult<Graph>

Ends the capture and returns the resulting Graph.

On a real CUDA system, this would call cuStreamEndCapture and return the captured graph handle.

The captured nodes are connected in a linear chain (each node depends on the previous one) to preserve the order in which operations were recorded.

§Errors

Returns CudaError::StreamCaptureUnmatched if the capture was already ended.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more