Upload runtime/Lib/site-packages/onnxruntime/datasets/onnxruntime_collect_build_info.py with huggingface_hub
Browse files
runtime/Lib/site-packages/onnxruntime/datasets/onnxruntime_collect_build_info.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
| 3 |
+
# Licensed under the MIT License.
|
| 4 |
+
# --------------------------------------------------------------------------
|
| 5 |
+
import ctypes
|
| 6 |
+
import sys
|
| 7 |
+
import warnings
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def find_cudart_versions(build_env=False, build_cuda_version=None):
|
| 11 |
+
# ctypes.CDLL and ctypes.util.find_library load the latest installed library.
|
| 12 |
+
# it may not the the library that would be loaded by onnxruntime.
|
| 13 |
+
# for example, in an environment with Cuda 11.1 and subsequently
|
| 14 |
+
# conda cudatoolkit 10.2.89 installed. ctypes will find cudart 10.2. however,
|
| 15 |
+
# onnxruntime built with Cuda 11.1 will find and load cudart for Cuda 11.1.
|
| 16 |
+
# for the above reason, we need find all versions in the environment and
|
| 17 |
+
# only give warnings if the expected cuda version is not found.
|
| 18 |
+
# in onnxruntime build environment, we expected only one Cuda version.
|
| 19 |
+
if not sys.platform.startswith("linux"):
|
| 20 |
+
warnings.warn("find_cudart_versions only works on Linux")
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
cudart_possible_versions = {None, build_cuda_version}
|
| 24 |
+
|
| 25 |
+
def get_cudart_version(find_cudart_version=None):
|
| 26 |
+
cudart_lib_filename = "libcudart.so"
|
| 27 |
+
if find_cudart_version:
|
| 28 |
+
cudart_lib_filename = cudart_lib_filename + "." + find_cudart_version
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
cudart = ctypes.CDLL(cudart_lib_filename)
|
| 32 |
+
cudart.cudaRuntimeGetVersion.restype = int
|
| 33 |
+
cudart.cudaRuntimeGetVersion.argtypes = [ctypes.POINTER(ctypes.c_int)]
|
| 34 |
+
version = ctypes.c_int()
|
| 35 |
+
status = cudart.cudaRuntimeGetVersion(ctypes.byref(version))
|
| 36 |
+
if status != 0:
|
| 37 |
+
return None
|
| 38 |
+
except Exception:
|
| 39 |
+
return None
|
| 40 |
+
|
| 41 |
+
return version.value
|
| 42 |
+
|
| 43 |
+
# use set to avoid duplications
|
| 44 |
+
cudart_found_versions = {get_cudart_version(cudart_version) for cudart_version in cudart_possible_versions}
|
| 45 |
+
|
| 46 |
+
# convert to list and remove None
|
| 47 |
+
return [ver for ver in cudart_found_versions if ver]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def find_cudnn_supported_cuda_versions(build_env=False):
|
| 51 |
+
# comments in get_cudart_version apply here
|
| 52 |
+
if not sys.platform.startswith("linux"):
|
| 53 |
+
warnings.warn("find_cudnn_versions only works on Linux")
|
| 54 |
+
|
| 55 |
+
cudnn_possible_versions = {None}
|
| 56 |
+
if not build_env:
|
| 57 |
+
# if not in a build environment, there may be more than one installed cudnn.
|
| 58 |
+
# https://developer.nvidia.com/rdp/cudnn-archive to include all that may support Cuda 10+.
|
| 59 |
+
cudnn_possible_versions.update(
|
| 60 |
+
{
|
| 61 |
+
"8.2",
|
| 62 |
+
"8.1.1",
|
| 63 |
+
"8.1.0",
|
| 64 |
+
"8.0.5",
|
| 65 |
+
"8.0.4",
|
| 66 |
+
"8.0.3",
|
| 67 |
+
"8.0.2",
|
| 68 |
+
"8.0.1",
|
| 69 |
+
"7.6.5",
|
| 70 |
+
"7.6.4",
|
| 71 |
+
"7.6.3",
|
| 72 |
+
"7.6.2",
|
| 73 |
+
"7.6.1",
|
| 74 |
+
"7.6.0",
|
| 75 |
+
"7.5.1",
|
| 76 |
+
"7.5.0",
|
| 77 |
+
"7.4.2",
|
| 78 |
+
"7.4.1",
|
| 79 |
+
"7.3.1",
|
| 80 |
+
"7.3.0",
|
| 81 |
+
}
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
def get_cudnn_supported_cuda_version(find_cudnn_version=None):
|
| 85 |
+
cudnn_lib_filename = "libcudnn.so"
|
| 86 |
+
if find_cudnn_version:
|
| 87 |
+
cudnn_lib_filename = cudnn_lib_filename + "." + find_cudnn_version
|
| 88 |
+
|
| 89 |
+
# in cudnn.h cudnn version are calculated as:
|
| 90 |
+
# #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
|
| 91 |
+
try:
|
| 92 |
+
cudnn = ctypes.CDLL(cudnn_lib_filename)
|
| 93 |
+
# cudnn_ver = cudnn.cudnnGetVersion()
|
| 94 |
+
cuda_ver = cudnn.cudnnGetCudartVersion()
|
| 95 |
+
return cuda_ver
|
| 96 |
+
except Exception:
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
# use set to avoid duplications
|
| 100 |
+
cuda_found_versions = {get_cudnn_supported_cuda_version(cudnn_version) for cudnn_version in cudnn_possible_versions}
|
| 101 |
+
|
| 102 |
+
# convert to list and remove None
|
| 103 |
+
return [ver for ver in cuda_found_versions if ver]
|