Skip to main content

CudaGraphModel

Struct CudaGraphModel 

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

A CUDA graph compiled from a LoadedModel for fixed-batch inference.

Created via LoadedModel::capture_graph. All device buffers are pre-allocated; the kernel sequence is captured once and replayed on each [run] call with a single cuGraphLaunch + cuStreamSynchronize.

Implementations§

Source§

impl CudaGraphModel

Source

pub fn output_shapes(&self) -> &[Vec<usize>]

Concrete shapes of the output tensors, in the order of output_node_indices.

Source

pub fn run_timed(&self, inputs: &[&[f32]]) -> Result<(Vec<Vec<f32>>, f32)>

Like [run] but also returns GPU execution time in milliseconds.

The GPU time is measured with CUDA events bracketing only cuGraphLaunch (pure kernel execution, excluding host↔device copies). The returned f32 is milliseconds of GPU time for the whole batch.

Source

pub fn run(&self, inputs: &[&[f32]]) -> Result<Vec<Vec<f32>>>

Copy f32 inputs to device, replay the CUDA graph, copy f32 outputs to host.

Returns one Vec<f32> per requested output node (same order as output_node_indices passed to LoadedModel::capture_graph).

Source

pub fn input_slice_mut(&mut self, i: usize) -> &mut [f32]

Mutable slice into the i-th pinned (page-locked) input staging buffer.

Write your input data here before calling [run_inplace] / [run_timed_inplace] to avoid the intermediate CPU copy that [run] / [run_timed] perform when given a pageable &[f32].

§Safety

The slice is valid until this CudaGraphModel is dropped.

Source

pub fn output_slice(&self, i: usize) -> &[f32]

Immutable slice into the i-th pinned (page-locked) output staging buffer. Valid after [run_inplace] / [run_timed_inplace] returns.

Source

pub fn run_inplace(&self) -> Result<()>

Copy pinned inputs → device, launch graph, copy device → pinned outputs.

Callers must fill [input_slice_mut] before calling and read [output_slice] afterwards. No heap allocations are performed.

Source

pub fn run_timed_inplace(&self) -> Result<f32>

Like [run_inplace] but also returns GPU execution time in milliseconds.

Trait Implementations§

Source§

impl Drop for CudaGraphModel

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for CudaGraphModel

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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