Skip to main content

Execution Providers in C/C++

Execution Providers (EPs) enable ONNX Runtime to execute models on different hardware accelerators like GPUs, NPUs, and other specialized devices.

Available Providers

GetAvailableProviders

Get the list of all available execution providers. Parameters:
  • out_ptr: Array of provider name strings (must be freed with ReleaseAvailableProviders)
  • provider_length: Number of providers
Returns: NULL on success Example:
Note: A provider being “available” doesn’t guarantee it’s usable. It may fail if system dependencies are missing.

CUDA Execution Provider

OrtCUDAProviderOptions

cuDNN Convolution Algorithm Search:

SessionOptionsAppendExecutionProvider_CUDA

Append CUDA execution provider to session options. Parameters:
  • options: Session options
  • cuda_options: CUDA provider configuration
Returns: Error if CUDA is not available Example:

CUDA Provider V2 (Advanced)

Example:

ROCm Execution Provider

OrtROCMProviderOptions

SessionOptionsAppendExecutionProvider_ROCM

Append ROCm execution provider. Example:

TensorRT Execution Provider

OrtTensorRTProviderOptions

SessionOptionsAppendExecutionProvider_TensorRT

Example:

TensorRT Provider V2

Example:

OpenVINO Execution Provider

OrtOpenVINOProviderOptions

SessionOptionsAppendExecutionProvider_OpenVINO

Example:

MIGraphX Execution Provider

OrtMIGraphXProviderOptions

SessionOptionsAppendExecutionProvider_MIGraphX

Generic Provider Configuration

SessionOptionsAppendExecutionProvider

Append any execution provider using key-value configuration. Parameters:
  • options: Session options
  • provider_name: Name of the provider (e.g., “CUDAExecutionProvider”)
  • provider_options_keys: Array of configuration keys
  • provider_options_values: Array of configuration values
  • num_keys: Number of key-value pairs
Example:

Device Management

SetCurrentGpuDeviceId

Set the current GPU device ID for CUDA/TensorRT/ROCm providers. Parameters:
  • device_id: Device ID (must be less than total device count)
Example:

GetCurrentGpuDeviceId

Get the current GPU device ID.

Memory Arena Configuration

CreateArenaCfg

Deprecated: Use CreateArenaCfgV2 instead.

CreateArenaCfgV2

Create arena configuration for memory management. Configuration Keys:
  • "max_mem": Maximum memory (0 = let ORT decide)
  • "arena_extend_strategy": 0=kNextPowerOfTwo, 1=kSameAsRequested (-1=default)
  • "initial_chunk_size_bytes": First allocation size (-1=default)
  • "max_dead_bytes_per_chunk": Threshold for chunk splitting (-1=default)
  • "initial_growth_chunk_size_bytes": Second allocation size (-1=default)
  • "max_power_of_two_extend_bytes": Max extension size for kNextPowerOfTwo (-1=default 1GB)
Example:

ReleaseArenaCfg

Free arena configuration.

Custom Operators

RegisterCustomOpsLibrary_V2

Register custom operators from a shared library. Parameters:
  • options: Session options
  • library_path: Path to shared library (.dll, .so, .dylib)
Expected Entry Point:

EnableOrtCustomOps

Enable built-in custom operators from onnxruntime-extensions.

Provider Priority

Providers are tried in the order they are added. Add the most preferred provider first:

Complete Example

See Also