Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: A dynamic link library (DLL) initialization routine failed after building source with Visual Studio 17.10 #21024

Closed
tianleiwu opened this issue Jun 12, 2024 · 8 comments
Labels
platform:windows issues related to the Windows platform

Comments

@tianleiwu
Copy link
Contributor

tianleiwu commented Jun 12, 2024

Describe the issue

After building from source, onnxruntime cannot be imported from python in a conda environment.

To reproduce

Upgrade Visual Studio to latest stable version (Version 17.10.2), and build the main branch like the following

build.bat --cmake_generator "Visual Studio 17 2022" --config Release --build_dir build\cuda12 --build_wheel --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=89" ^
          --parallel --build_shared_lib --use_cuda --cuda_version "12.5" --cuda_home "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5" ^
		  --cudnn_home "C:\nvidia\CuDNN\9.1.1.17_cuda12" ^
		  --use_tensorrt --tensorrt_home "C:\nvidia\TensorRT\10.0.1.6.cuda-12.4" --use_tensorrt_builtin_parser ^
                  --parallel 4 --nvcc_threads 1 ^
		  --skip_tests ^
		  --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=ON

Then import onnxruntime in python under a conda environment. It shows error:

ImportError: DLL load failed while importing onnxruntime_pybind11_state: A dynamic link library (DLL) initialization routine failed.

In Windows event viewer, I saw an event with information like:

Faulting application name: python.exe, version: 3.10.14150.1013, time stamp: 0x663933b3
Faulting module name: MSVCP140.dll, version: 14.29.30153.0, time stamp: 0x653aa208
Exception code: 0xc0000005
Fault offset: 0x0000000000013080
Faulting process id: 0x0x86A8
Faulting application start time: 0x0x1DABD0F2E51B8F9
Faulting application start time: 0x0x1DABD0F2E51B8F9
Faulting application path: C:\Users\%USERNAME%\.conda\envs\my_env\python.exe
Faulting module path: C:\Users\%USERNAME%\.conda\envs\my_env\MSVCP140.dll

Note that the code has included #21005.

Urgency

No response

Platform

Windows

OS Version

Windows 11 Enterprise 10.0.22631 Build 22631

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

a2b0a69

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@github-actions github-actions bot added ep:CUDA issues related to the CUDA execution provider ep:TensorRT issues related to TensorRT execution provider platform:windows issues related to the Windows platform labels Jun 12, 2024
@yufenglee
Copy link
Member

does it persist if you revert the change?

@tianleiwu
Copy link
Contributor Author

tianleiwu commented Jun 12, 2024

One workaround I found is like the following: copy DLLs from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Redist\MSVC\14.40.33807\onecore\x64\Microsoft.VC143.CRT to my conda environment C:\Users\%USERNAME%\.conda\envs\my_env to overwrite existing DLLs.

Note that installing latest VC Runtime does not work (the downloaded VC Runtime is older than the one installed with latest Visual Studio).

@tianleiwu
Copy link
Contributor Author

tianleiwu commented Jun 12, 2024

does it persist if you revert the change?

Yes, I encountered the issue before the change.

@tianleiwu tianleiwu changed the title ImportError: A dynamic link library (DLL) initialization routine failed ImportError: A dynamic link library (DLL) initialization routine failed after building source with Visual Studio 17.10 Jun 12, 2024
@yufenglee
Copy link
Member

conda uses old vc runtime and it is not compatible with new visual studio compiler. You can run "conda install conda-forge::vs2015_runtime" to upgrade your vc runtime version in conda.

@snnn snnn closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2024
@snnn
Copy link
Member

snnn commented Jun 13, 2024

One workaround I found is like the following: copy DLLs from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Redist\MSVC\14.40.33807\onecore\x64\Microsoft.VC143.CRT to my conda environment C:\Users\%USERNAME%\.conda\envs\my_env to overwrite existing DLLs.

Note that installing latest VC Runtime does not work (the downloaded VC Runtime is older than the one installed with latest Visual Studio).

Or just delete the DLLs in conda's directories.

@snnn snnn removed ep:CUDA issues related to the CUDA execution provider ep:TensorRT issues related to TensorRT execution provider labels Jun 13, 2024
@snnn
Copy link
Member

snnn commented Jun 13, 2024

Faulting module name: MSVCP140.dll, version: 14.29.30153.0, time stamp: 0x653aa208

In theory this should work ... Could it be a different issue?

@snnn
Copy link
Member

snnn commented Jun 13, 2024

Oh, @tianleiwu, when you build the code you need to add "--use_binskim_compliant_compile_flags" to your build command, otherwise the changes in #21005 wouldn't take effect. It was because I asked the author to scope the change to a smaller scope that wouldn't effect most people.

@tianleiwu
Copy link
Contributor Author

Adding --use_binskim_compliant_compile_flags solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:windows issues related to the Windows platform
Projects
None yet
Development

No branches or pull requests

3 participants