cassiebreviu / StableDiffusion

Inference Stable Diffusion with C# and ONNX Runtime
MIT License
218 stars 49 forks source link

LoadLibrary Failed with error 126 when trying to load onnxruntime_providers_cuda.dll #4

Closed softnodelabs closed 10 months ago

softnodelabs commented 1 year ago

Hi,

I'm trying this sample but I'm getting the following error:

[ErrorCode:RuntimeException] D:\a_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1106 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "E:\Development\ThirdParty\StableDiffusion-main\StableDiffusion\bin\Debug\net6.0\runtimes\win-x64\native\onnxruntime_providers_cuda.dll"

I installed CUDA Toolkit 12.1 and cudnn for Cuda12. Both are in the path. I'm running Windows 11 and Visual Studio 2022.

What am I doing wrong?

Thanks in advance!

Spatacoli commented 1 year ago

I had the exact same problem. I solved it by uninstalling CUDA Toolkit 12.1. Installed CUDA Toolkit 11.8. I got a different message that cublasLt64_12.dll was missing so I installed CUDA Toolkit 12 again (Without removing 11.8) and it seems to work now.

pocki commented 1 year ago

I have a similar problem, but with ortextensions.dll [ErrorCode:Fail] LoadLibrary failed with error 126 "" when trying to load "ortextensions.dll" File exists and is in correct working directory - also tried with absolut path, but the same.

I also uninstalled all CUDA Toolkit versions and reinstalled 11.8 and than 12.1 like @Spatacoli I use the latest version with the included fix of #3

Windows 11, Visual Studio 2022

cassiebreviu commented 1 year ago

The current supported version of CUDA Toolkit for ONNX Runtime v1.14 is CUDA 11.6. Glad to hear 11.8 was able to fix the issue as well. Thanks!

cassiebreviu commented 1 year ago

I have a similar problem, but with ortextensions.dll [ErrorCode:Fail] LoadLibrary failed with error 126 "" when trying to load "ortextensions.dll" File exists and is in correct working directory - also tried with absolut path, but the same.

I also uninstalled all CUDA Toolkit versions and reinstalled 11.8 and than 12.1 like @Spatacoli I use the latest version with the included fix of #3

Windows 11, Visual Studio 2022

Are you still having the ortextensions.dll issue? Can you target x64?

pocki commented 1 year ago

Before I also had CUDA 11.6 installed. I also have the same ortextensions.dll issue, also on x64 target.

Is it somehow possible to check what dependency of ortextensions.dll is missing/creates the issue?

pinkli commented 1 year ago

Before I also had CUDA 11.6 installed. I also have the same ortextensions.dll issue, also on x64 target.

Is it somehow possible to check what dependency of ortextensions.dll is missing/creates the issue?

I have the same issue here. File exists and is in correct working directory. Windows 10, using the direct-ML-EP branch, since I don't have CUDA supported graphic card. Stack as follows: Unhandled exception. Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:Fail] LoadLibrary failed with error 126 "" when trying to load "D:\Projects\StableDiffusion\StableDiffusion\ortextensions.dll" at Microsoft.ML.OnnxRuntime.NativeApiStatus.VerifySuccess(IntPtr nativeStatus) at Microsoft.ML.OnnxRuntime.SessionOptions.RegisterCustomOpLibraryV2(String libraryPath, IntPtr& libraryHandle) at StableDiffusion.TextProcessing.TokenizeText(String text) in D:\Projects\StableDiffusion\StableDiffusion\TextProcessing.cs:line 17 at StableDiffusion.Program.Main(String[] args) in D:\Projects\StableDiffusion\StableDiffusion\Program.cs:line 26

hannespreishuber commented 1 year ago

nearly same here Windows 11 Surface Pro 8 (so no CUDA my guess) uses direct-ML-EP branch

pocki commented 1 year ago

My graphic card supports CUDA, but is maybe to old (GTX1070). I am using the latest Driver v531.29 which also supports CUDA 12.1 Changed to direct-ML-EP branch but still the same error.

softnodelabs commented 1 year ago

Before I also had CUDA 11.6 installed. I also have the same ortextensions.dll issue, also on x64 target. Is it somehow possible to check what dependency of ortextensions.dll is missing/creates the issue?

I have the same issue here. File exists and is in correct working directory. Windows 10, using the direct-ML-EP branch, since I don't have CUDA supported graphic card. Stack as follows: Unhandled exception. Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:Fail] LoadLibrary failed with error 126 "" when trying to load "D:\Projects\StableDiffusion\StableDiffusion\ortextensions.dll" at Microsoft.ML.OnnxRuntime.NativeApiStatus.VerifySuccess(IntPtr nativeStatus) at Microsoft.ML.OnnxRuntime.SessionOptions.RegisterCustomOpLibraryV2(String libraryPath, IntPtr& libraryHandle) at StableDiffusion.TextProcessing.TokenizeText(String text) in D:\Projects\StableDiffusion\StableDiffusion\TextProcessing.cs:line 17 at StableDiffusion.Program.Main(String[] args) in D:\Projects\StableDiffusion\StableDiffusion\Program.cs:line 26

The problem with ortextension.dll I fixed enabling the option to copy the file to build directory. I still have the Cuda problem, though.

pinkli commented 1 year ago

Before I also had CUDA 11.6 installed. I also have the same ortextensions.dll issue, also on x64 target. Is it somehow possible to check what dependency of ortextensions.dll is missing/creates the issue?

I have the same issue here. File exists and is in correct working directory. Windows 10, using the direct-ML-EP branch, since I don't have CUDA supported graphic card. Stack as follows: Unhandled exception. Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:Fail] LoadLibrary failed with error 126 "" when trying to load "D:\Projects\StableDiffusion\StableDiffusion\ortextensions.dll" at Microsoft.ML.OnnxRuntime.NativeApiStatus.VerifySuccess(IntPtr nativeStatus) at Microsoft.ML.OnnxRuntime.SessionOptions.RegisterCustomOpLibraryV2(String libraryPath, IntPtr& libraryHandle) at StableDiffusion.TextProcessing.TokenizeText(String text) in D:\Projects\StableDiffusion\StableDiffusion\TextProcessing.cs:line 17 at StableDiffusion.Program.Main(String[] args) in D:\Projects\StableDiffusion\StableDiffusion\Program.cs:line 26

Finally I solved this issue, by build the ortextension.dll from source, and use the freshly built out dll. the repo is https://github.com/microsoft/onnxruntime-extensions clone the repo and run build.bat in Developer command prompt vs 2022. the dll is in the out/Windows/bin/RelWithDebInfo folder when build success.

pocki commented 1 year ago

Thanks @pinkli I build the onnx-extensions with Release 0.7 (Branch rel-0.7) and fixes this problem. But get also stuck with error #9

Hint: If you get only "file not found" output at build.bat check if you have C++-CMake-Tools for Windows installed in your Visual Studio.

IronFox commented 1 year ago

Okay, I can't fix this. I've installed CUDA toolkit up and down the version ladder and I always get LoadLibrary failed with error 126 on onnxruntime_providers_cuda.dll when executing AppendExecutionProvider_CUDA(). Where does this DLL actually come from? Maybe I can recompile that?

IronFox commented 1 year ago

Or is there any way to get an error printout of what the issue actually is? Code 126 is uniquely unspecific.

logikstate commented 1 year ago

I have a similar problem Unable to find an entry point named 'OrtSessionOptionsAppendExecutionProvider_CUDA' in DLL 'onnxruntime'.... if I open up a commandline inside of the build directory and manually delete onnxruntime.dll I still get the error Unable to find an entry point named 'OrtSessionOptionsAppendExecutionProvider_CUDA' in DLL 'onnxruntime'. which leads me to believe that the onnxruntime.dll is being loaded from some other place? I appear to have onnxruntime.dll's inside of Windows/System32 as well as Windows/SysWOW64 ... I have various CUDA toolkits installed and my CUDA_PATH is currently set to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6 and the CUDA toolkit path is FIRST thing in my %PATH% dir before the other gazillion versions I appear to have installed... If I try and delete the .dll's inside of Windows dir its not letting me which suggests that those files are open and are being used instead of the .dll's in the build dir.... no idea where these came from... I'm presuming CUDA toolkit doesn't install to Windows dir?