1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! GPU execution provider selection: per-vendor feature flags, session-level config.
//!
//! Each GPU EP is gated behind its own Cargo feature (`ort-cuda`, `ort-rocm`, etc.).
//! When no GPU features are enabled, an empty vec is returned — ORT uses CPU only.
//! When a GPU feature IS enabled but the GPU is unavailable, ORT silently falls back
//! to the next EP in the list; we emit [`tracing::warn!`] so users know.
/// Build the list of GPU execution providers in registration-priority order.
pub fn gpu_execution_providers() -> Vec<ort::ep::ExecutionProviderDispatch> {
#[allow(unused_mut)]
let mut eps: Vec<ort::ep::ExecutionProviderDispatch> = Vec::new();
#[cfg(feature = "ort-cuda")]
{
tracing::info!("Enabling CUDA execution provider for ONNX Runtime");
eps.push(ort::ep::CUDA::default().build());
}
#[cfg(feature = "ort-rocm")]
{
tracing::info!("Enabling ROCm execution provider for ONNX Runtime");
eps.push(ort::ep::ROCm::default().build());
}
#[cfg(feature = "ort-webgpu")]
{
tracing::info!("Enabling WebGPU execution provider for ONNX Runtime");
eps.push(ort::ep::WebGPU::default().build());
}
#[cfg(all(target_os = "windows", feature = "ort-directml"))]
{
tracing::info!("Enabling DirectML execution provider for ONNX Runtime");
eps.push(ort::ep::DirectML::default().build());
}
#[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "ort-coreml"))]
{
tracing::info!("Enabling CoreML execution provider for ONNX Runtime");
eps.push(ort::ep::CoreML::default().build());
}
if eps.is_empty() {
tracing::debug!("No GPU execution providers configured — using CPU only");
}
eps.push(ort::ep::CPU::default().build());
eps
}