Skip to main content

CUDA

Struct CUDA 

Source
pub struct CUDA { /* private fields */ }
Available on crate feature cuda only.
Expand description

CUDA execution provider for NVIDIA CUDA-enabled GPUs.

Implementations§

Source§

impl CUDA

Source§

impl CUDA

Source

pub fn with_device_id(self, device_id: i32) -> Self

Configures which device the EP should use.

let ep = ep::CUDA::default().with_device_id(0).build();
Source

pub fn with_memory_limit(self, limit: usize) -> Self

Configure the size limit of the device memory arena in bytes.

This only controls how much memory can be allocated to the arena - actual memory usage may be higher due to internal CUDA allocations, like those required for different ConvAlgorithmSearch options.

let ep = ep::CUDA::default().with_memory_limit(2 * 1024 * 1024 * 1024).build();
Source

pub fn with_arena_extend_strategy(self, strategy: ArenaExtendStrategy) -> Self

Configure the strategy for extending the device’s memory arena.

let ep = ep::CUDA::default()
	.with_arena_extend_strategy(ArenaExtendStrategy::SameAsRequested)
	.build();

Controls the search mode used to select a kernel for Conv nodes.

cuDNN, the library used by ONNX Runtime’s CUDA EP for many operations, provides many different implementations of the Conv node. Each of these implementations has different performance characteristics depending on the exact hardware and model/input size used. This option controls how cuDNN should determine which implementation to use.

The default search algorithm, Exhaustive, will benchmark all available implementations and use the most performant one. This option is very resource intensive (both computationally on first run and peak-memory-wise), but ensures best performance. It is roughly equivalent to setting torch.backends.cudnn.benchmark = True with PyTorch. See also CUDA::with_conv_max_workspace to configure how much memory the exhaustive search can use (the default is unlimited).

A less resource-intensive option is Heuristic. Rather than benchmarking every implementation, an optimal implementation is chosen based on a set of heuristics, thus saving compute. Heuristic should generally choose an optimal convolution algorithm, except in some corner cases.

Default can also be passed to instruct cuDNN to always use the default implementation (which is rarely the most optimal). Note that the “Default” here refers to the default convolution algorithm being used, it is not the default behavior (that would be Exhaustive).

let ep = ep::CUDA::default()
	.with_conv_algorithm_search(ep::cuda::ConvAlgorithmSearch::Heuristic)
	.build();
Source

pub fn with_conv_max_workspace(self, enable: bool) -> Self

Configure whether the Exhaustive search can use as much memory as it needs.

The default is true. When false, the memory used for the search is limited to 32 MB, which will impact its ability to find an optimal convolution algorithm.

let ep = ep::CUDA::default().with_conv_max_workspace(false).build();
Source

pub fn with_conv1d_pad_to_nc1d(self, enable: bool) -> Self

Configure whether or not to pad 3-dimensional convolutions to [N, C, 1, D] (as opposed to the default [N, C, D, 1]).

Enabling this option might significantly improve performance on devices like the A100. This does not affect convolution operations that do not use 3-dimensional input shapes, or the result of such operations.

let ep = ep::CUDA::default().with_conv1d_pad_to_nc1d(true).build();
Source

pub fn with_cuda_graph(self, enable: bool) -> Self

Configures whether to create a CUDA graph.

CUDA graphs eliminate the overhead of launching kernels sequentially by capturing the launch sequence into a graph that is ‘replayed’ across runs, reducing CPU overhead and possibly improving performance.

Using CUDA graphs comes with limitations, notably:

  • Models with control flow operators (like If, Loop, or Scan) are not supported.
  • Input/output shapes cannot change across inference calls.
  • The address of inputs/outputs cannot change across inference calls, so IoBinding must be used.
  • Sessions using CUDA graphs are technically not Send or Sync.

Consult the ONNX Runtime documentation on CUDA graphs for more information.

let ep = ep::CUDA::default().with_cuda_graph(true).build();
Source

pub fn with_skip_layer_norm_strict_mode(self, enable: bool) -> Self

Enable ‘strict’ mode for SkipLayerNorm nodes (created via fusion of Add & LayerNorm nodes).

SkipLayerNorm’s strict mode trades performance for accuracy. The default is false (strict mode disabled).

let ep = ep::CUDA::default().with_skip_layer_norm_strict_mode(true).build();
Source

pub fn with_tf32(self, enable: bool) -> Self

Enable the usage of the reduced-precision TensorFloat-32 format for matrix multiplications & convolutions.

TensorFloat-32 is a reduced-precision floating point format available on NVIDIA GPUs since the Ampere microarchitecture. It allows MatMul & Conv to run much faster on Ampere’s Tensor cores. This option is disabled by default.

This option is roughly equivalent to torch.backends.cudnn.allow_tf32 = True & torch.backends.cuda.matmul.allow_tf32 = True or torch.set_float32_matmul_precision("medium") in PyTorch.

let ep = ep::CUDA::default().with_tf32(true).build();
Source

pub fn with_prefer_nhwc(self, enable: bool) -> Self

Configure whether to prefer [N, H, W, C] layout operations over the default [N, C, H, W] layout.

Tensor cores usually operate more efficiently with the NHWC layout, so enabling this option for convolution-heavy models on Tensor core-enabled GPUs may provide a significant performance improvement.

let ep = ep::CUDA::default().with_prefer_nhwc(true).build();
Source

pub unsafe fn with_compute_stream(self, stream: *mut ()) -> Self

Use a custom CUDA device stream rather than the default one.

§Safety

The provided stream must outlive the environment/session configured to use this execution provider.

Source

pub fn with_attention_backend(self, flags: AttentionBackend) -> Self

Configures the available backends used for Attention nodes.

let ep = ep::CUDA::default()
	.with_attention_backend(
		ep::cuda::AttentionBackend::FLASH_ATTENTION | ep::cuda::AttentionBackend::TRT_FUSED_ATTENTION
	)
	.build();
Source

pub fn with_fuse_conv_bias(self, enable: bool) -> Self

Trait Implementations§

Source§

impl ArbitrarilyConfigurableExecutionProvider for CUDA

Source§

fn with_arbitrary_config(self, key: impl ToString, value: impl ToString) -> Self

Source§

impl Clone for CUDA

Source§

fn clone(&self) -> CUDA

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CUDA

Source§

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

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

impl Default for CUDA

Source§

fn default() -> CUDA

Returns the “default value” for a type. Read more
Source§

impl ExecutionProvider for CUDA

Source§

fn name(&self) -> &'static str

Returns the identifier of this execution provider used internally by ONNX Runtime. Read more
Source§

fn register(&self, session_builder: &mut SessionBuilder) -> Result<()>

Attempts to register this execution provider on the given session.
Source§

fn is_available(&self) -> Result<bool>

Returns Ok(true) if ONNX Runtime was compiled with support for this execution provider, and Ok(false) otherwise. Read more
Source§

impl From<CUDA> for ExecutionProviderDispatch

Source§

fn from(value: CUDA) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for CUDA

§

impl RefUnwindSafe for CUDA

§

impl Send for CUDA

§

impl Sync for CUDA

§

impl Unpin for CUDA

§

impl UnsafeUnpin for CUDA

§

impl UnwindSafe for CUDA

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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