
Choose the GPU execution provider used by ONNX Runtime
Source:R/utils_dl_providers.R
pliman_gpu_provider.RdEvery deep-learning function in pliman that takes engine = "gpu" runs its ONNX
models through an ONNX Runtime execution provider. pliman_gpu_provider() reads or
sets which provider is tried first:
"auto"(default): CUDA when the loaded ONNX Runtime library includes it, otherwise DirectML (Windows). This reproduces the previous behaviour with the libraries installed byonnx_install()."dml": DirectML (Windows 10/11, any DirectX 12 GPU: NVIDIA, AMD, Intel)."cuda": NVIDIA CUDA. Needs the CUDA build of ONNX Runtime (onnx_install(engine = "cuda")) plus the NVIDIA CUDA 12 runtime, cuBLAS and cuDNN 9 libraries on the library search path (seecuda_path)."tensorrt": NVIDIA TensorRT on top of CUDA (also needs the TensorRT libraries). Engines are compiled the first time a model is loaded, which can take minutes; they are cached intrt_cache_dirso later sessions start quickly."coreml": Apple CoreML (macOS builds of ONNX Runtime)."openvino": Intel OpenVINO (requires an OpenVINO build of ONNX Runtime). The device is taken from the environment variablePLIMAN_OPENVINO_DEVICE(default"AUTO:GPU,CPU").
A provider that the loaded library does not contain, or that fails to initialise
(missing driver or CUDA libraries), is skipped: pliman then tries CUDA, DirectML and
finally the CPU, so inference never fails just because of this setting. Use
pliman_session_info() (column provider) to see which provider actually serves
each model, and onnx_available_providers() to list what the library offers.
Usage
pliman_gpu_provider(
provider = NULL,
trt_cache_dir = NULL,
trt_fp16 = NULL,
cuda_path = NULL
)Arguments
- provider
One of
"auto","dml","cuda","tensorrt","coreml","openvino".NULL(default) only returns the current setting.- trt_cache_dir
Directory for TensorRT engine and timing caches. Defaults to
file.path(pliman_model_dir(), "trt_cache")whenprovider = "tensorrt".- trt_fp16
Logical. Let TensorRT build FP16 kernels.
NULLkeeps the current setting (initiallyFALSE).- cuda_path
Optional character vector of directories holding the CUDA runtime, cuBLAS and cuDNN libraries (e.g.
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin"). They are prepended toPATH(Windows) orLD_LIBRARY_PATHfor the current R process, before the first GPU session is created.
Hardware dependence
Speed-ups depend entirely on the GPU, its driver and, for CUDA/TensorRT, the
installed NVIDIA libraries. TensorRT with trt_fp16 = TRUE and FP16 models only
accelerate on GPUs with native half-precision throughput (NVIDIA Tensor Cores, RTX
20xx and newer); on GPUs without it (e.g. GTX 10xx/16xx) they can be slower than FP32
because of casting. Always compare with yolo_benchmark() on your own machine.
Examples
if (FALSE) { # interactive()
library(pliman)
pliman_gpu_provider() # "auto"
onnx_available_providers() # what the installed runtime offers
# NVIDIA CUDA (after onnx_install(engine = "cuda"))
pliman_gpu_provider("cuda", cuda_path = "C:/cuda/bin")
img <- image_pliman("soybean_touch.jpg")
res <- image_detect_dl(img, model = "yolo26n", plot = FALSE)
pliman_session_info()[, c("model", "provider")]
pliman_gpu_provider("auto") # back to the default
}