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

Adding optional CUDA DLLs when installing onnxruntime_gpu #22506

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
65b0f6b
Adding optional CUDA DLLs when installing onnxruntime_gpu
jchen351 Oct 18, 2024
a335dc6
Lintrunner -a
jchen351 Oct 18, 2024
87c51fb
Merge branch 'main' into Cjian/cuda_pip
jchen351 Oct 21, 2024
c95dbce
Update python code
jchen351 Oct 21, 2024
990752e
update python lint to 3.12
jchen351 Oct 21, 2024
e15e3e0
update python lint to 3.12
jchen351 Oct 21, 2024
5e70dd0
Revert lint python to 3.10
jchen351 Oct 21, 2024
3bf6817
Merge branch 'main' into Cjian/cuda_pip
jchen351 Nov 6, 2024
faa6e3a
Use the regex to match .so , .so.nn where nn is a digital number
jchen351 Nov 6, 2024
2efad16
Import missing re
jchen351 Nov 6, 2024
f4f9d35
Adding nvidia-curand and nvidia-cuda-runtime
jchen351 Nov 6, 2024
c025719
Fix typo
jchen351 Nov 6, 2024
c7d0951
lintrunner -a
jchen351 Nov 6, 2024
5fea4d4
Adding 2 second output to os.walk()
jchen351 Nov 7, 2024
ca752b6
Merge branch 'main' into Cjian/cuda_pip
jchen351 Nov 11, 2024
f27a566
Try to install onnxruntime-gpu from local wheel with [cuda_dlls]
jchen351 Nov 11, 2024
120ddf9
Try to install onnxruntime-gpu from local wheel with [cuda_dlls]
jchen351 Nov 11, 2024
644b52e
Update onnxruntime/python/onnxruntime_cuda_temp_env.py
jchen351 Nov 11, 2024
f557c1e
Using os.add_dll_directory and ctypes.CDLL to load dynamic library
jchen351 Nov 11, 2024
f170664
Merge remote-tracking branch 'origin/Cjian/cuda_pip' into Cjian/cuda_pip
jchen351 Nov 11, 2024
5a0e3fb
linrunner -a
jchen351 Nov 11, 2024
cddc500
Move nvidia dll loading to __init__.py
jchen351 Nov 11, 2024
81ef596
rolling back accidentally added yml files
jchen351 Nov 11, 2024
05e8441
Merge branch 'main' into Cjian/cuda_pip
jchen351 Nov 11, 2024
513522f
rolling back accidentally added yml files
jchen351 Nov 11, 2024
77ac10a
add __package__ == "onnxruntime-gpu" condition
jchen351 Nov 11, 2024
fa785d7
preload both windows and linux dlibs
jchen351 Nov 11, 2024
cf7ba65
Move load nvidia dll to an other __init__.py
jchen351 Nov 11, 2024
d24c96c
Move load nvidia dll to an other __init__.py
jchen351 Nov 12, 2024
e9b913f
Move load nvidia dll to an other __init__.py
jchen351 Nov 12, 2024
144f066
Move load nvidia dll to an other __init__.py
jchen351 Nov 12, 2024
0560de9
remove print statements
jchen351 Nov 12, 2024
053d0a3
Merge remote-tracking branch 'origin/main' into Cjian/cuda_pip
jchen351 Nov 14, 2024
457f4a2
Refactor CUDA library regex patterns for Windows environments to sear…
jchen351 Nov 15, 2024
014833f
Refactor CUDA library regex patterns to search nvidia libraries.
jchen351 Nov 15, 2024
d2cbf27
Refactor CUDA library regex patterns to search nvidia libraries.
jchen351 Nov 15, 2024
02c73c6
Use site.getsitepackages()[-1] for both Windows and Linux.
jchen351 Dec 11, 2024
cd02bdb
Logging exception error and add "libcublasLt.so" to the list of libar…
jchen351 Dec 12, 2024
b342c18
Change the regex to exact match of lib files, ignore the case
jchen351 Dec 12, 2024
11b2604
Lintrunner -a
jchen351 Dec 12, 2024
74b8a91
change log level to debug
jchen351 Dec 13, 2024
5ddfc0f
change log level to debug
jchen351 Dec 13, 2024
287bd46
Change logging error to debugs and update messages
jchen351 Dec 16, 2024
dff876c
Update "libnvrtc.so.11", toi "libnvrtc.so.11.2"
jchen351 Dec 16, 2024
5923d1b
#This is not a mistake, it links to more specific version like libnvr…
jchen351 Dec 16, 2024
cf612fc
lintrunner -a
jchen351 Dec 17, 2024
d0ffbaf
change cuda_version() to cuda version
jchen351 Dec 19, 2024
ad0cf6b
Update save_build_and_package_info to allow to be used in non trainin…
jchen351 Dec 19, 2024
fad62cb
check linux before calling find_cudart_versions. Also remove if has_o…
jchen351 Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions onnxruntime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@
onnxruntime_validation.check_distro_info()


def check_and_load_cuda_libs(root_directory, cuda_libs):
def check_and_load_cuda_libs(root_directory, cuda_libs_):
# Convert the target library names to lowercase for case-insensitive comparison
tianleiwu marked this conversation as resolved.
Show resolved Hide resolved
# Convert the target library names to lowercase for case-insensitive comparison
if cuda_libs_ is None or len(cuda_libs_) == 0:
logging.debug("No CUDA libraries provided for loading.")
return
cuda_libs_ = {lib.lower() for lib in cuda_libs_}
found_libs = {}
for dirpath, _, filenames in os.walk(root_directory):
# Convert filenames in the current directory to lowercase for comparison
files_in_dir = {file.lower(): file for file in filenames} # Map lowercase to original
# Find common libraries in the current directory
matched_libs = cuda_libs.intersection(files_in_dir.keys())
matched_libs = cuda_libs_.intersection(files_in_dir.keys())
for lib in matched_libs:
# Store the full path of the found DLL
full_path = os.path.join(dirpath, files_in_dir[lib])
Expand All @@ -98,11 +103,11 @@ def check_and_load_cuda_libs(root_directory, cuda_libs):
logging.error(f"Failed to load {full_path}: {e}")

# If all required libraries are found, stop the search
if set(found_libs.keys()) == cuda_libs:
if set(found_libs.keys()) == cuda_libs_:
print("All required CUDA libraries found and loaded.")
return True
logging.error(f"Failed to load all required CUDA libraries. missing libraries: {cuda_libs - found_libs.keys()}")
return False
return
logging.error(f"Failed to load all required CUDA libraries. missing libraries: {cuda_libs_ - found_libs.keys()}")
jchen351 marked this conversation as resolved.
Show resolved Hide resolved
return


# Load nvidia libraries from site-packages/nvidia if the package is onnxruntime-gpu
jchen351 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -117,7 +122,6 @@ def check_and_load_cuda_libs(root_directory, cuda_libs):
import logging
import os
import platform
import re
import site

# Get the site-packages path where nvidia packages are installed
Expand All @@ -129,15 +133,15 @@ def check_and_load_cuda_libs(root_directory, cuda_libs):
# Define the list of DLL patterns, nvrtc, curand and nvJitLink are not included for Windows
if (11, 0) <= cuda_version() < (12, 0):
tianleiwu marked this conversation as resolved.
Show resolved Hide resolved
cuda_libs = (
"cublasLT64_11.dll",
"cublaslt64_11.dll",
"cublas64_11.dll",
"cufft64_10.dll",
"cudart64_11.dll",
"cudnn64_8.dll",
)
elif (12, 0) <= cuda_version() < (13, 0):
cuda_libs = (
"cublasLT64_12.dll",
"cublaslt64_12.dll",
"cublas64_12.dll",
"cufft64_11.dll",
"cudart64_12.dll",
Expand Down Expand Up @@ -166,10 +170,5 @@ def check_and_load_cuda_libs(root_directory, cuda_libs):
"libnvrtc.so.12",
)
else:
logging.error(f"Unsupported platform: {platform.system()}")

if cuda_libs:
# Convert the target library names to lowercase for case-insensitive comparison
cuda_libs = {lib.lower() for lib in cuda_libs}
# Load the required CUDA libraries
check_and_load_cuda_libs(nvidia_path, cuda_libs)
logging.debug(f"Unsupported platform: {platform.system()}")
check_and_load_cuda_libs(nvidia_path, cuda_libs)
Loading