-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Adding optional CUDA DLLs when installing onnxruntime_gpu #22506
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
65b0f6b
Adding optional CUDA DLLs when installing onnxruntime_gpu
jchen351 a335dc6
Lintrunner -a
jchen351 87c51fb
Merge branch 'main' into Cjian/cuda_pip
jchen351 c95dbce
Update python code
jchen351 990752e
update python lint to 3.12
jchen351 e15e3e0
update python lint to 3.12
jchen351 5e70dd0
Revert lint python to 3.10
jchen351 3bf6817
Merge branch 'main' into Cjian/cuda_pip
jchen351 faa6e3a
Use the regex to match .so , .so.nn where nn is a digital number
jchen351 2efad16
Import missing re
jchen351 f4f9d35
Adding nvidia-curand and nvidia-cuda-runtime
jchen351 c025719
Fix typo
jchen351 c7d0951
lintrunner -a
jchen351 5fea4d4
Adding 2 second output to os.walk()
jchen351 ca752b6
Merge branch 'main' into Cjian/cuda_pip
jchen351 f27a566
Try to install onnxruntime-gpu from local wheel with [cuda_dlls]
jchen351 120ddf9
Try to install onnxruntime-gpu from local wheel with [cuda_dlls]
jchen351 644b52e
Update onnxruntime/python/onnxruntime_cuda_temp_env.py
jchen351 f557c1e
Using os.add_dll_directory and ctypes.CDLL to load dynamic library
jchen351 f170664
Merge remote-tracking branch 'origin/Cjian/cuda_pip' into Cjian/cuda_pip
jchen351 5a0e3fb
linrunner -a
jchen351 cddc500
Move nvidia dll loading to __init__.py
jchen351 81ef596
rolling back accidentally added yml files
jchen351 05e8441
Merge branch 'main' into Cjian/cuda_pip
jchen351 513522f
rolling back accidentally added yml files
jchen351 77ac10a
add __package__ == "onnxruntime-gpu" condition
jchen351 fa785d7
preload both windows and linux dlibs
jchen351 cf7ba65
Move load nvidia dll to an other __init__.py
jchen351 d24c96c
Move load nvidia dll to an other __init__.py
jchen351 e9b913f
Move load nvidia dll to an other __init__.py
jchen351 144f066
Move load nvidia dll to an other __init__.py
jchen351 0560de9
remove print statements
jchen351 053d0a3
Merge remote-tracking branch 'origin/main' into Cjian/cuda_pip
jchen351 457f4a2
Refactor CUDA library regex patterns for Windows environments to sear…
jchen351 014833f
Refactor CUDA library regex patterns to search nvidia libraries.
jchen351 d2cbf27
Refactor CUDA library regex patterns to search nvidia libraries.
jchen351 02c73c6
Use site.getsitepackages()[-1] for both Windows and Linux.
jchen351 cd02bdb
Logging exception error and add "libcublasLt.so" to the list of libar…
jchen351 b342c18
Change the regex to exact match of lib files, ignore the case
jchen351 11b2604
Lintrunner -a
jchen351 74b8a91
change log level to debug
jchen351 5ddfc0f
change log level to debug
jchen351 287bd46
Change logging error to debugs and update messages
jchen351 dff876c
Update "libnvrtc.so.11", toi "libnvrtc.so.11.2"
jchen351 5923d1b
#This is not a mistake, it links to more specific version like libnvr…
jchen351 cf612fc
lintrunner -a
jchen351 d0ffbaf
change cuda_version() to cuda version
jchen351 ad0cf6b
Update save_build_and_package_info to allow to be used in non trainin…
jchen351 fad62cb
check linux before calling find_cudart_versions. Also remove if has_o…
jchen351 f2aa262
Merge branch 'main' into Cjian/cuda_pip
jchen351 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import os | ||
|
||
| import platform | ||
| import site | ||
|
|
||
|
|
||
| class TemporaryEnv: | ||
| def __init__(self, updates): | ||
| self.original_env = os.environ.copy() | ||
| os.environ.update(updates) | ||
|
|
||
| def __exit__(self, exc_type, exc_value, traceback): | ||
| os.environ.clear() | ||
| os.environ.update(self.original_env) | ||
|
|
||
|
|
||
| def get_nvidia_dll_paths() -> str: | ||
| # Get the site-packages path where nvidia packages are installed | ||
| site_packages_path = site.getsitepackages()[0] | ||
| nvidia_path = os.path.join(site_packages_path, "nvidia") | ||
|
|
||
| # Collect all directories under site-packages/nvidia that contain .dll files (for Windows) | ||
| dll_paths = [] | ||
| for root, files in os.walk(nvidia_path): | ||
tianleiwu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if any(file.endswith(".dll") for file in files): | ||
| dll_paths.append(root) | ||
| return os.pathsep.join(dll_paths) | ||
|
|
||
|
|
||
| def get_nvidia_so_paths() -> str: | ||
| # Get the site-packages path where nvidia packages are installed | ||
| site_packages_path = site.getsitepackages()[0] | ||
| nvidia_path = os.path.join(site_packages_path, "nvidia") | ||
|
|
||
| # Collect all directories under site-packages/nvidia that contain .so files (for Linux) | ||
| so_paths = [] | ||
| for root, files in os.walk(nvidia_path): | ||
tianleiwu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if any(file.endswith(".so") for file in files): | ||
tianleiwu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| so_paths.append(root) | ||
| return os.pathsep.join(so_paths) | ||
|
|
||
|
|
||
| def setup_temp_env_for_ort_cuda(): | ||
|
||
| # Determine platform and set up the environment accordingly | ||
| if platform.system() == "Windows": # Windows | ||
| nvidia_dlls_path = get_nvidia_dll_paths() | ||
| if nvidia_dlls_path: | ||
| return TemporaryEnv({"PATH": nvidia_dlls_path + os.pathsep + os.environ.get("PATH")}) | ||
| else: | ||
| return TemporaryEnv({"PATH": os.environ.get("PATH")}) | ||
tianleiwu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| elif platform.system() == "Linux": | ||
| nvidia_so_paths = get_nvidia_so_paths() | ||
| if nvidia_so_paths: | ||
| return TemporaryEnv({"LD_LIBRARY_PATH": nvidia_so_paths + os.pathsep + os.environ.get("LD_LIBRARY_PATH")}) | ||
| else: | ||
| return TemporaryEnv({"LD_LIBRARY_PATH": os.environ.get("LD_LIBRARY_PATH")}) | ||
tianleiwu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else: | ||
| return None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.