How to Fix onnxruntime_providers_cuda.dll LoadLibrary Error 126

If you’re diving into ONNX Runtime with CUDA and run into the LoadLibrary Error 126 with onnxruntime_providers_cuda.dll, don’t worry—it’s usually related to your CUDA or driver setup. Let’s walk through a few steps to help you troubleshoot and get things running properly again.

1. Update Your GPU Drivers

First, ensure your NVIDIA GPU drivers are up to date. You can download the latest drivers from the NVIDIA website. Sometimes, the latest drivers might not do the trick, and in that case, rolling back to a previous version could help.

2. Match CUDA Toolkit and cuDNN Versions

Make sure you’re using the right versions of CUDA Toolkit and cuDNN that are compatible with your ONNX Runtime. For example, ONNX Runtime 1.18.1 works with CUDA 12.x and cuDNN 9.x, so if you’re using different versions, it could lead to problems. For a complete list of the compatibility, please refer to this page.

3. Add CUDA and cuDNN to the PATH Variable

For Windows to find your CUDA and cuDNN files, you need to add them to your PATH environment variable. Here’s how:

  • Add your CUDA bin path:
    • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\bin (adjust for your CUDA version)
  • Add your cuDNN bin directory:
    • C:\tools\cuda\bin (or wherever your cuDNN is installed)

This step is super important. Without these paths, the system won’t be able to locate the necessary files, leading to the dreaded error. Note that sometimes the DLLs are not in the bin directory. For example, the cuDNN DLLs are in “C:\Program Files\NVIDIA\CUDNN\v9.3\bin\12.6” for my computer.

4. Verify Your CUDA Setup

Check that your CUDA installation is working by running the following commands in a command prompt:

  • nvidia-smi
    This will show your GPU status and whether the CUDA driver is installed properly.
  • nvcc --version
    This checks if the CUDA toolkit itself is correctly installed.

If these commands show everything is in order, then your CUDA installation is probably fine.

5. Ensure ONNX Runtime and CUDA Compatibility

Double-check that the version of ONNX Runtime you’re using is compatible with your CUDA and cuDNN versions. Sometimes a mismatch between versions can cause the LoadLibrary 126 error.

6. Check for Missing Dependencies

Use a tool like Dependency Walker or dumpbin to scan the onnxruntime_providers_cuda.dll file and look for any missing dependencies. If there are missing files, that could explain the error.

7. Switch to CPU Temporarily

If you’re in a rush and need to bypass the error quickly, you can switch to CPU execution temporarily by setting your ONNX Runtime provider to CPUExecutionProvider. It’s not a permanent solution if you need CUDA, but it will let you keep working while you fix the issue.


With these steps—including adding both CUDA and cuDNN to your PATH variable—you should be able to resolve the LoadLibrary Error 126 and get everything running smoothly. If the issue persists, reinstalling CUDA and cuDNN might clear up any lingering configuration issues.

Hope this helps!


This post may contain affiliated links. When you click on the link and purchase a product, we receive a small commision to keep us running. Thanks.


Be the first to comment

Leave a Reply