The warning you're encountering indicates that the CUDAExecutionProvider is not available in your current ONNX Runtime setup. Instead, ONNX Runtime is defaulting to using the DmlExecutionProvider (DirectML) and the CPUExecutionProvider. To resolve this issue and enable GPU acceleration with CUDA, follow the steps below:
1. Verify Your Hardware and Software Compatibility
-
NVIDIA GPU: Ensure that your system has an NVIDIA GPU that supports CUDA. You can check your GPU model by:
- Windows: Open
Device Manager > Display adapters.
- Command Line: Run
nvidia-smi if NVIDIA drivers are installed.
-
CUDA Toolkit: Confirm that the CUDA Toolkit version is compatible with the version required by onnxruntime-gpu. ONNX Runtime typically requires a specific CUDA version. Check the ONNX Runtime GPU installation guide for compatibility details.
2. Install the GPU-Enabled ONNX Runtime
The standard onnxruntime package doesn't include GPU support. You need to install onnxruntime-gpu instead.
3. Install the Appropriate CUDA Toolkit and cuDNN
-
Download CUDA Toolkit: Visit the NVIDIA CUDA Toolkit Download page and install the version compatible with your onnxruntime-gpu package.
-
Install cuDNN: Download cuDNN from the NVIDIA cuDNN page. Follow the installation instructions to integrate it with your CUDA Toolkit.
4. Verify the Installation
After installing onnxruntime-gpu and the necessary CUDA components, verify that the CUDAExecutionProvider is available.
import onnxruntime as ort
print("Available Providers:", ort.get_available_providers())
You should see CUDAExecutionProvider listed among the available providers:
Available Providers: ['CUDAExecutionProvider', 'DmlExecutionProvider', 'CPUExecutionProvider']
5. Modify Your Inference Code (If Necessary)
Ensure that your code explicitly selects the CUDAExecutionProvider. Here's an example of how to set it:
import onnxruntime as ort
providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
session = ort.InferenceSession('your_model.onnx', providers=providers)
6. Troubleshooting Tips
-
Driver Issues: Ensure that your NVIDIA drivers are up-to-date. Outdated drivers can cause compatibility issues with CUDA.
-
Environment Variables: Make sure that CUDA and cuDNN paths are correctly set in your system's environment variables (PATH, CUDA_HOME, etc.).
-
Check Installation: Run a simple CUDA program or use nvidia-smi to ensure that CUDA is functioning correctly on your system.
Alternative: Use DirectML or CPU Providers
If you cannot use CUDA (due to hardware limitations or other reasons), you can continue using the DmlExecutionProvider or CPUExecutionProvider. Modify your code to select the available providers without specifying CUDA.
import onnxruntime as ort
providers = ['DmlExecutionProvider', 'CPUExecutionProvider']
session = ort.InferenceSession('your_model.onnx', providers=providers)
While DmlExecutionProvider can offer GPU acceleration on Windows machines with compatible GPUs, it might not match the performance provided by CUDA.
Summary
To fix the warning about the unavailable CUDAExecutionProvider:
- Ensure you have a compatible NVIDIA GPU.
- Install
onnxruntime-gpu instead of the standard onnxruntime.
- Install the appropriate CUDA Toolkit and cuDNN versions.
- Verify the installation and modify your code to use
CUDAExecutionProvider.
By following these steps, you should be able to leverage GPU acceleration with ONNX Runtime using CUDA.
If you need further assistance or encounter additional issues, feel free to ask!