Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- lib/python3.11/site-packages/cuda/bindings/__init__.pxd +0 -0
- lib/python3.11/site-packages/cuda/bindings/__init__.py +5 -0
- lib/python3.11/site-packages/cuda/bindings/_version.py +34 -0
- lib/python3.11/site-packages/cuda/bindings/cufile.pxd +85 -0
- lib/python3.11/site-packages/cuda/bindings/cycufile.cpython-311-x86_64-linux-gnu.so +0 -0
- lib/python3.11/site-packages/cuda/bindings/cycufile.pxd +431 -0
- lib/python3.11/site-packages/cuda/pathfinder/README.md +3 -0
- lib/python3.11/site-packages/cuda/pathfinder/__init__.py +91 -0
- lib/python3.11/site-packages/cuda/pathfinder/__pycache__/__init__.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/__pycache__/_optional_cuda_import.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/__pycache__/_version.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_binaries/__pycache__/find_nvidia_binary_utility.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_binaries/__pycache__/supported_nvidia_binaries.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_binaries/find_nvidia_binary_utility.py +107 -0
- lib/python3.11/site-packages/cuda/pathfinder/_binaries/supported_nvidia_binaries.py +34 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/descriptor_catalog.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/dynamic_lib_subprocess.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/lib_descriptor.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_dl_common.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_dl_linux.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_dl_windows.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_nvidia_dynamic_lib.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/platform_loader.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/search_platform.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/search_steps.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/subprocess_protocol.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/supported_nvidia_libs.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/descriptor_catalog.py +407 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/dynamic_lib_subprocess.py +127 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/lib_descriptor.py +24 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_dl_common.py +36 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_dl_linux.py +221 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_dl_windows.py +167 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py +303 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/platform_loader.py +41 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/search_platform.py +219 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/search_steps.py +228 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/subprocess_protocol.py +71 -0
- lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py +80 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/find_nvidia_headers.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/header_descriptor.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/header_descriptor_catalog.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/supported_nvidia_headers.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/find_nvidia_headers.py +226 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/header_descriptor.py +54 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/header_descriptor_catalog.py +212 -0
- lib/python3.11/site-packages/cuda/pathfinder/_headers/supported_nvidia_headers.py +81 -0
- lib/python3.11/site-packages/cuda/pathfinder/_optional_cuda_import.py +43 -0
- lib/python3.11/site-packages/cuda/pathfinder/_static_libs/__pycache__/find_bitcode_lib.cpython-311.pyc +0 -0
- lib/python3.11/site-packages/cuda/pathfinder/_static_libs/__pycache__/find_static_lib.cpython-311.pyc +0 -0
lib/python3.11/site-packages/cuda/bindings/__init__.pxd
ADDED
|
File without changes
|
lib/python3.11/site-packages/cuda/bindings/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
|
| 3 |
+
|
| 4 |
+
from cuda.bindings import utils
|
| 5 |
+
from cuda.bindings._version import __version__
|
lib/python3.11/site-packages/cuda/bindings/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by setuptools-scm
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
|
| 4 |
+
__all__ = [
|
| 5 |
+
"__version__",
|
| 6 |
+
"__version_tuple__",
|
| 7 |
+
"version",
|
| 8 |
+
"version_tuple",
|
| 9 |
+
"__commit_id__",
|
| 10 |
+
"commit_id",
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
TYPE_CHECKING = False
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from typing import Tuple
|
| 16 |
+
from typing import Union
|
| 17 |
+
|
| 18 |
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
| 19 |
+
COMMIT_ID = Union[str, None]
|
| 20 |
+
else:
|
| 21 |
+
VERSION_TUPLE = object
|
| 22 |
+
COMMIT_ID = object
|
| 23 |
+
|
| 24 |
+
version: str
|
| 25 |
+
__version__: str
|
| 26 |
+
__version_tuple__: VERSION_TUPLE
|
| 27 |
+
version_tuple: VERSION_TUPLE
|
| 28 |
+
commit_id: COMMIT_ID
|
| 29 |
+
__commit_id__: COMMIT_ID
|
| 30 |
+
|
| 31 |
+
__version__ = version = '13.2.0'
|
| 32 |
+
__version_tuple__ = version_tuple = (13, 2, 0)
|
| 33 |
+
|
| 34 |
+
__commit_id__ = commit_id = 'g06e60656c'
|
lib/python3.11/site-packages/cuda/bindings/cufile.pxd
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
|
| 4 |
+
#
|
| 5 |
+
# This code was automatically generated across versions from 12.9.1 to 13.2.0, generator version 0.3.1.dev1364+ged01d643e. Do not modify it directly.
|
| 6 |
+
|
| 7 |
+
from libc.stdint cimport intptr_t
|
| 8 |
+
|
| 9 |
+
from .cycufile cimport *
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
###############################################################################
|
| 13 |
+
# Types
|
| 14 |
+
###############################################################################
|
| 15 |
+
|
| 16 |
+
ctypedef CUfileHandle_t Handle
|
| 17 |
+
ctypedef CUfileBatchHandle_t BatchHandle
|
| 18 |
+
ctypedef CUfileError_t Error
|
| 19 |
+
ctypedef cufileRDMAInfo_t RDMAInfo
|
| 20 |
+
ctypedef CUfileFSOps_t FSOps
|
| 21 |
+
ctypedef CUfileDrvProps_t DrvProps
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
###############################################################################
|
| 25 |
+
# Enum
|
| 26 |
+
###############################################################################
|
| 27 |
+
|
| 28 |
+
ctypedef CUfileOpError _OpError
|
| 29 |
+
ctypedef CUfileDriverStatusFlags_t _DriverStatusFlags
|
| 30 |
+
ctypedef CUfileDriverControlFlags_t _DriverControlFlags
|
| 31 |
+
ctypedef CUfileFeatureFlags_t _FeatureFlags
|
| 32 |
+
ctypedef CUfileFileHandleType _FileHandleType
|
| 33 |
+
ctypedef CUfileOpcode_t _Opcode
|
| 34 |
+
ctypedef CUfileStatus_t _Status
|
| 35 |
+
ctypedef CUfileBatchMode_t _BatchMode
|
| 36 |
+
ctypedef CUFileSizeTConfigParameter_t _SizeTConfigParameter
|
| 37 |
+
ctypedef CUFileBoolConfigParameter_t _BoolConfigParameter
|
| 38 |
+
ctypedef CUFileStringConfigParameter_t _StringConfigParameter
|
| 39 |
+
ctypedef CUFileArrayConfigParameter_t _ArrayConfigParameter
|
| 40 |
+
ctypedef CUfileP2PFlags_t _P2PFlags
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
###############################################################################
|
| 44 |
+
# Functions
|
| 45 |
+
###############################################################################
|
| 46 |
+
|
| 47 |
+
cpdef intptr_t handle_register(intptr_t descr) except? 0
|
| 48 |
+
cpdef void handle_deregister(intptr_t fh) except*
|
| 49 |
+
cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags)
|
| 50 |
+
cpdef buf_deregister(intptr_t buf_ptr_base)
|
| 51 |
+
cpdef driver_open()
|
| 52 |
+
cpdef use_count()
|
| 53 |
+
cpdef driver_get_properties(intptr_t props)
|
| 54 |
+
cpdef driver_set_poll_mode(bint poll, size_t poll_threshold_size)
|
| 55 |
+
cpdef driver_set_max_direct_io_size(size_t max_direct_io_size)
|
| 56 |
+
cpdef driver_set_max_cache_size(size_t max_cache_size)
|
| 57 |
+
cpdef driver_set_max_pinned_mem_size(size_t max_pinned_size)
|
| 58 |
+
cpdef intptr_t batch_io_set_up(unsigned nr) except? 0
|
| 59 |
+
cpdef batch_io_submit(intptr_t batch_idp, unsigned nr, intptr_t iocbp, unsigned int flags)
|
| 60 |
+
cpdef batch_io_get_status(intptr_t batch_idp, unsigned min_nr, intptr_t nr, intptr_t iocbp, intptr_t timeout)
|
| 61 |
+
cpdef batch_io_cancel(intptr_t batch_idp)
|
| 62 |
+
cpdef void batch_io_destroy(intptr_t batch_idp) except*
|
| 63 |
+
cpdef read_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_read_p, intptr_t stream)
|
| 64 |
+
cpdef write_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_written_p, intptr_t stream)
|
| 65 |
+
cpdef stream_register(intptr_t stream, unsigned flags)
|
| 66 |
+
cpdef stream_deregister(intptr_t stream)
|
| 67 |
+
cpdef int get_version() except? 0
|
| 68 |
+
cpdef size_t get_parameter_size_t(int param) except? 0
|
| 69 |
+
cpdef bint get_parameter_bool(int param) except? 0
|
| 70 |
+
cpdef str get_parameter_string(int param, int len)
|
| 71 |
+
cpdef set_parameter_size_t(int param, size_t value)
|
| 72 |
+
cpdef set_parameter_bool(int param, bint value)
|
| 73 |
+
cpdef set_parameter_string(int param, intptr_t desc_str)
|
| 74 |
+
cpdef tuple get_parameter_min_max_value(int param)
|
| 75 |
+
cpdef set_stats_level(int level)
|
| 76 |
+
cpdef int get_stats_level() except? 0
|
| 77 |
+
cpdef stats_start()
|
| 78 |
+
cpdef stats_stop()
|
| 79 |
+
cpdef stats_reset()
|
| 80 |
+
cpdef get_stats_l1(intptr_t stats)
|
| 81 |
+
cpdef get_stats_l2(intptr_t stats)
|
| 82 |
+
cpdef get_stats_l3(intptr_t stats)
|
| 83 |
+
cpdef size_t get_bar_size_in_kb(int gpu_ind_ex) except? 0
|
| 84 |
+
cpdef set_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len)
|
| 85 |
+
cpdef get_parameter_posix_pool_slab_array(intptr_t size_values, intptr_t count_values, int len)
|
lib/python3.11/site-packages/cuda/bindings/cycufile.cpython-311-x86_64-linux-gnu.so
ADDED
|
Binary file (32.3 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/bindings/cycufile.pxd
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
|
| 4 |
+
#
|
| 5 |
+
# This code was automatically generated across versions from 12.9.1 to 13.2.0, generator version 0.3.1.dev1364+ged01d643e. Do not modify it directly.
|
| 6 |
+
|
| 7 |
+
from libc.stdint cimport uint32_t, uint64_t
|
| 8 |
+
from libc.time cimport time_t
|
| 9 |
+
from libcpp cimport bool as cpp_bool
|
| 10 |
+
from posix.types cimport off_t
|
| 11 |
+
|
| 12 |
+
cimport cuda.bindings.cydriver
|
| 13 |
+
from cuda.bindings.cydriver cimport CUresult
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
###############################################################################
|
| 17 |
+
# Types (structs, enums, ...)
|
| 18 |
+
###############################################################################
|
| 19 |
+
|
| 20 |
+
# TODO: switch to "from libc.time cimport timespec" once we can use recent
|
| 21 |
+
# Cython to build
|
| 22 |
+
cdef extern from "<time.h>":
|
| 23 |
+
cdef struct timespec:
|
| 24 |
+
time_t tv_sec
|
| 25 |
+
long tv_nsec
|
| 26 |
+
cdef extern from "<sys/socket.h>":
|
| 27 |
+
cdef struct sockaddr:
|
| 28 |
+
unsigned short sa_family
|
| 29 |
+
char sa_data[14]
|
| 30 |
+
ctypedef sockaddr sockaddr_t
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# enums
|
| 36 |
+
cdef extern from '<cufile.h>':
|
| 37 |
+
ctypedef enum CUfileOpError:
|
| 38 |
+
CU_FILE_SUCCESS
|
| 39 |
+
CU_FILE_DRIVER_NOT_INITIALIZED
|
| 40 |
+
CU_FILE_DRIVER_INVALID_PROPS
|
| 41 |
+
CU_FILE_DRIVER_UNSUPPORTED_LIMIT
|
| 42 |
+
CU_FILE_DRIVER_VERSION_MISMATCH
|
| 43 |
+
CU_FILE_DRIVER_VERSION_READ_ERROR
|
| 44 |
+
CU_FILE_DRIVER_CLOSING
|
| 45 |
+
CU_FILE_PLATFORM_NOT_SUPPORTED
|
| 46 |
+
CU_FILE_IO_NOT_SUPPORTED
|
| 47 |
+
CU_FILE_DEVICE_NOT_SUPPORTED
|
| 48 |
+
CU_FILE_NVFS_DRIVER_ERROR
|
| 49 |
+
CU_FILE_CUDA_DRIVER_ERROR
|
| 50 |
+
CU_FILE_CUDA_POINTER_INVALID
|
| 51 |
+
CU_FILE_CUDA_MEMORY_TYPE_INVALID
|
| 52 |
+
CU_FILE_CUDA_POINTER_RANGE_ERROR
|
| 53 |
+
CU_FILE_CUDA_CONTEXT_MISMATCH
|
| 54 |
+
CU_FILE_INVALID_MAPPING_SIZE
|
| 55 |
+
CU_FILE_INVALID_MAPPING_RANGE
|
| 56 |
+
CU_FILE_INVALID_FILE_TYPE
|
| 57 |
+
CU_FILE_INVALID_FILE_OPEN_FLAG
|
| 58 |
+
CU_FILE_DIO_NOT_SET
|
| 59 |
+
CU_FILE_INVALID_VALUE
|
| 60 |
+
CU_FILE_MEMORY_ALREADY_REGISTERED
|
| 61 |
+
CU_FILE_MEMORY_NOT_REGISTERED
|
| 62 |
+
CU_FILE_PERMISSION_DENIED
|
| 63 |
+
CU_FILE_DRIVER_ALREADY_OPEN
|
| 64 |
+
CU_FILE_HANDLE_NOT_REGISTERED
|
| 65 |
+
CU_FILE_HANDLE_ALREADY_REGISTERED
|
| 66 |
+
CU_FILE_DEVICE_NOT_FOUND
|
| 67 |
+
CU_FILE_INTERNAL_ERROR
|
| 68 |
+
CU_FILE_GETNEWFD_FAILED
|
| 69 |
+
CU_FILE_NVFS_SETUP_ERROR
|
| 70 |
+
CU_FILE_IO_DISABLED
|
| 71 |
+
CU_FILE_BATCH_SUBMIT_FAILED
|
| 72 |
+
CU_FILE_GPU_MEMORY_PINNING_FAILED
|
| 73 |
+
CU_FILE_BATCH_FULL
|
| 74 |
+
CU_FILE_ASYNC_NOT_SUPPORTED
|
| 75 |
+
CU_FILE_INTERNAL_BATCH_SETUP_ERROR
|
| 76 |
+
CU_FILE_INTERNAL_BATCH_SUBMIT_ERROR
|
| 77 |
+
CU_FILE_INTERNAL_BATCH_GETSTATUS_ERROR
|
| 78 |
+
CU_FILE_INTERNAL_BATCH_CANCEL_ERROR
|
| 79 |
+
CU_FILE_NOMEM_ERROR
|
| 80 |
+
CU_FILE_IO_ERROR
|
| 81 |
+
CU_FILE_INTERNAL_BUF_REGISTER_ERROR
|
| 82 |
+
CU_FILE_HASH_OPR_ERROR
|
| 83 |
+
CU_FILE_INVALID_CONTEXT_ERROR
|
| 84 |
+
CU_FILE_NVFS_INTERNAL_DRIVER_ERROR
|
| 85 |
+
CU_FILE_BATCH_NOCOMPAT_ERROR
|
| 86 |
+
CU_FILE_IO_MAX_ERROR
|
| 87 |
+
|
| 88 |
+
cdef extern from '<cufile.h>':
|
| 89 |
+
ctypedef enum CUfileDriverStatusFlags_t:
|
| 90 |
+
CU_FILE_LUSTRE_SUPPORTED
|
| 91 |
+
CU_FILE_WEKAFS_SUPPORTED
|
| 92 |
+
CU_FILE_NFS_SUPPORTED
|
| 93 |
+
CU_FILE_GPFS_SUPPORTED
|
| 94 |
+
CU_FILE_NVME_SUPPORTED
|
| 95 |
+
CU_FILE_NVMEOF_SUPPORTED
|
| 96 |
+
CU_FILE_SCSI_SUPPORTED
|
| 97 |
+
CU_FILE_SCALEFLUX_CSD_SUPPORTED
|
| 98 |
+
CU_FILE_NVMESH_SUPPORTED
|
| 99 |
+
CU_FILE_BEEGFS_SUPPORTED
|
| 100 |
+
CU_FILE_NVME_P2P_SUPPORTED
|
| 101 |
+
CU_FILE_SCATEFS_SUPPORTED
|
| 102 |
+
CU_FILE_VIRTIOFS_SUPPORTED
|
| 103 |
+
CU_FILE_MAX_TARGET_TYPES
|
| 104 |
+
|
| 105 |
+
cdef extern from '<cufile.h>':
|
| 106 |
+
ctypedef enum CUfileDriverControlFlags_t:
|
| 107 |
+
CU_FILE_USE_POLL_MODE
|
| 108 |
+
CU_FILE_ALLOW_COMPAT_MODE
|
| 109 |
+
CU_FILE_POSIX_IO_MODE
|
| 110 |
+
CU_FILE_FALLBACK_IO_MODE
|
| 111 |
+
|
| 112 |
+
cdef extern from '<cufile.h>':
|
| 113 |
+
ctypedef enum CUfileFeatureFlags_t:
|
| 114 |
+
CU_FILE_DYN_ROUTING_SUPPORTED
|
| 115 |
+
CU_FILE_BATCH_IO_SUPPORTED
|
| 116 |
+
CU_FILE_STREAMS_SUPPORTED
|
| 117 |
+
CU_FILE_PARALLEL_IO_SUPPORTED
|
| 118 |
+
CU_FILE_P2P_SUPPORTED
|
| 119 |
+
|
| 120 |
+
cdef extern from '<cufile.h>':
|
| 121 |
+
ctypedef enum CUfileFileHandleType:
|
| 122 |
+
CU_FILE_HANDLE_TYPE_OPAQUE_FD
|
| 123 |
+
CU_FILE_HANDLE_TYPE_OPAQUE_WIN32
|
| 124 |
+
CU_FILE_HANDLE_TYPE_USERSPACE_FS
|
| 125 |
+
|
| 126 |
+
cdef extern from '<cufile.h>':
|
| 127 |
+
ctypedef enum CUfileOpcode_t:
|
| 128 |
+
CUFILE_READ
|
| 129 |
+
CUFILE_WRITE
|
| 130 |
+
|
| 131 |
+
cdef extern from '<cufile.h>':
|
| 132 |
+
ctypedef enum CUfileStatus_t:
|
| 133 |
+
CUFILE_WAITING
|
| 134 |
+
CUFILE_PENDING
|
| 135 |
+
CUFILE_INVALID
|
| 136 |
+
CUFILE_CANCELED
|
| 137 |
+
CUFILE_COMPLETE
|
| 138 |
+
CUFILE_TIMEOUT
|
| 139 |
+
CUFILE_FAILED
|
| 140 |
+
|
| 141 |
+
cdef extern from '<cufile.h>':
|
| 142 |
+
ctypedef enum CUfileBatchMode_t:
|
| 143 |
+
CUFILE_BATCH
|
| 144 |
+
|
| 145 |
+
cdef extern from '<cufile.h>':
|
| 146 |
+
ctypedef enum CUFileSizeTConfigParameter_t:
|
| 147 |
+
CUFILE_PARAM_PROFILE_STATS
|
| 148 |
+
CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH
|
| 149 |
+
CUFILE_PARAM_EXECUTION_MAX_IO_THREADS
|
| 150 |
+
CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB
|
| 151 |
+
CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM
|
| 152 |
+
CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB
|
| 153 |
+
CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB
|
| 154 |
+
CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB
|
| 155 |
+
CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB
|
| 156 |
+
CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE
|
| 157 |
+
CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB
|
| 158 |
+
CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS
|
| 159 |
+
|
| 160 |
+
cdef extern from '<cufile.h>':
|
| 161 |
+
ctypedef enum CUFileBoolConfigParameter_t:
|
| 162 |
+
CUFILE_PARAM_PROPERTIES_USE_POLL_MODE
|
| 163 |
+
CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE
|
| 164 |
+
CUFILE_PARAM_FORCE_COMPAT_MODE
|
| 165 |
+
CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE
|
| 166 |
+
CUFILE_PARAM_EXECUTION_PARALLEL_IO
|
| 167 |
+
CUFILE_PARAM_PROFILE_NVTX
|
| 168 |
+
CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY
|
| 169 |
+
CUFILE_PARAM_USE_PCIP2PDMA
|
| 170 |
+
CUFILE_PARAM_PREFER_IO_URING
|
| 171 |
+
CUFILE_PARAM_FORCE_ODIRECT_MODE
|
| 172 |
+
CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION
|
| 173 |
+
CUFILE_PARAM_STREAM_MEMOPS_BYPASS
|
| 174 |
+
|
| 175 |
+
cdef extern from '<cufile.h>':
|
| 176 |
+
ctypedef enum CUFileStringConfigParameter_t:
|
| 177 |
+
CUFILE_PARAM_LOGGING_LEVEL
|
| 178 |
+
CUFILE_PARAM_ENV_LOGFILE_PATH
|
| 179 |
+
CUFILE_PARAM_LOG_DIR
|
| 180 |
+
|
| 181 |
+
cdef extern from '<cufile.h>':
|
| 182 |
+
ctypedef enum CUFileArrayConfigParameter_t:
|
| 183 |
+
CUFILE_PARAM_POSIX_POOL_SLAB_SIZE_KB
|
| 184 |
+
CUFILE_PARAM_POSIX_POOL_SLAB_COUNT
|
| 185 |
+
CUFILE_PARAM_GPU_BOUNCE_BUFFER_SLAB_SIZE_KB
|
| 186 |
+
CUFILE_PARAM_GPU_BOUNCE_BUFFER_SLAB_COUNT
|
| 187 |
+
|
| 188 |
+
cdef extern from '<cufile.h>':
|
| 189 |
+
ctypedef enum CUfileP2PFlags_t:
|
| 190 |
+
CUFILE_P2PDMA
|
| 191 |
+
CUFILE_NVFS
|
| 192 |
+
CUFILE_DMABUF
|
| 193 |
+
CUFILE_C2C
|
| 194 |
+
CUFILE_NVIDIA_PEERMEM
|
| 195 |
+
|
| 196 |
+
# types
|
| 197 |
+
cdef extern from '<cufile.h>':
|
| 198 |
+
ctypedef void* CUfileHandle_t 'CUfileHandle_t'
|
| 199 |
+
|
| 200 |
+
cdef extern from '<cufile.h>':
|
| 201 |
+
ctypedef void* CUfileBatchHandle_t 'CUfileBatchHandle_t'
|
| 202 |
+
|
| 203 |
+
cdef extern from '<cufile.h>':
|
| 204 |
+
ctypedef struct CUfileError_t 'CUfileError_t':
|
| 205 |
+
CUfileOpError err
|
| 206 |
+
CUresult cu_err
|
| 207 |
+
|
| 208 |
+
cdef struct _anon_pod0 '_anon_pod0':
|
| 209 |
+
unsigned int major_version
|
| 210 |
+
unsigned int minor_version
|
| 211 |
+
size_t poll_thresh_size
|
| 212 |
+
size_t max_direct_io_size
|
| 213 |
+
unsigned int dstatusflags
|
| 214 |
+
unsigned int dcontrolflags
|
| 215 |
+
|
| 216 |
+
cdef extern from '<cufile.h>':
|
| 217 |
+
ctypedef struct cufileRDMAInfo_t 'cufileRDMAInfo_t':
|
| 218 |
+
int version
|
| 219 |
+
int desc_len
|
| 220 |
+
char* desc_str
|
| 221 |
+
|
| 222 |
+
cdef extern from '<cufile.h>':
|
| 223 |
+
ctypedef struct CUfileFSOps_t 'CUfileFSOps_t':
|
| 224 |
+
char* (*fs_type)(const void*)
|
| 225 |
+
int (*getRDMADeviceList)(const void*, sockaddr_t**)
|
| 226 |
+
int (*getRDMADevicePriority)(const void*, char*, size_t, loff_t, const sockaddr_t*)
|
| 227 |
+
ssize_t (*read)(const void*, char*, size_t, loff_t, const cufileRDMAInfo_t*)
|
| 228 |
+
ssize_t (*write)(const void*, const char*, size_t, loff_t, const cufileRDMAInfo_t*)
|
| 229 |
+
|
| 230 |
+
cdef union _anon_pod1 '_anon_pod1':
|
| 231 |
+
int fd
|
| 232 |
+
void* handle
|
| 233 |
+
|
| 234 |
+
cdef struct _anon_pod3 '_anon_pod3':
|
| 235 |
+
void* devPtr_base
|
| 236 |
+
off_t file_offset
|
| 237 |
+
off_t devPtr_offset
|
| 238 |
+
size_t size
|
| 239 |
+
|
| 240 |
+
cdef extern from '<cufile.h>':
|
| 241 |
+
ctypedef struct CUfileIOEvents_t 'CUfileIOEvents_t':
|
| 242 |
+
void* cookie
|
| 243 |
+
CUfileStatus_t status
|
| 244 |
+
size_t ret
|
| 245 |
+
|
| 246 |
+
cdef extern from '<cufile.h>':
|
| 247 |
+
ctypedef struct CUfileOpCounter_t 'CUfileOpCounter_t':
|
| 248 |
+
uint64_t ok
|
| 249 |
+
uint64_t err
|
| 250 |
+
|
| 251 |
+
cdef extern from '<cufile.h>':
|
| 252 |
+
ctypedef struct CUfilePerGpuStats_t 'CUfilePerGpuStats_t':
|
| 253 |
+
char uuid[16]
|
| 254 |
+
uint64_t read_bytes
|
| 255 |
+
uint64_t read_bw_bytes_per_sec
|
| 256 |
+
uint64_t read_utilization
|
| 257 |
+
uint64_t read_duration_us
|
| 258 |
+
uint64_t n_total_reads
|
| 259 |
+
uint64_t n_p2p_reads
|
| 260 |
+
uint64_t n_nvfs_reads
|
| 261 |
+
uint64_t n_posix_reads
|
| 262 |
+
uint64_t n_unaligned_reads
|
| 263 |
+
uint64_t n_dr_reads
|
| 264 |
+
uint64_t n_sparse_regions
|
| 265 |
+
uint64_t n_inline_regions
|
| 266 |
+
uint64_t n_reads_err
|
| 267 |
+
uint64_t writes_bytes
|
| 268 |
+
uint64_t write_bw_bytes_per_sec
|
| 269 |
+
uint64_t write_utilization
|
| 270 |
+
uint64_t write_duration_us
|
| 271 |
+
uint64_t n_total_writes
|
| 272 |
+
uint64_t n_p2p_writes
|
| 273 |
+
uint64_t n_nvfs_writes
|
| 274 |
+
uint64_t n_posix_writes
|
| 275 |
+
uint64_t n_unaligned_writes
|
| 276 |
+
uint64_t n_dr_writes
|
| 277 |
+
uint64_t n_writes_err
|
| 278 |
+
uint64_t n_mmap
|
| 279 |
+
uint64_t n_mmap_ok
|
| 280 |
+
uint64_t n_mmap_err
|
| 281 |
+
uint64_t n_mmap_free
|
| 282 |
+
uint64_t reg_bytes
|
| 283 |
+
|
| 284 |
+
cdef extern from '<cufile.h>':
|
| 285 |
+
ctypedef struct CUfileDrvProps_t 'CUfileDrvProps_t':
|
| 286 |
+
_anon_pod0 nvfs
|
| 287 |
+
unsigned int fflags
|
| 288 |
+
unsigned int max_device_cache_size
|
| 289 |
+
unsigned int per_buffer_cache_size
|
| 290 |
+
unsigned int max_device_pinned_mem_size
|
| 291 |
+
unsigned int max_batch_io_size
|
| 292 |
+
unsigned int max_batch_io_timeout_msecs
|
| 293 |
+
|
| 294 |
+
cdef extern from '<cufile.h>':
|
| 295 |
+
ctypedef struct CUfileDescr_t 'CUfileDescr_t':
|
| 296 |
+
CUfileFileHandleType type
|
| 297 |
+
_anon_pod1 handle
|
| 298 |
+
CUfileFSOps_t* fs_ops
|
| 299 |
+
|
| 300 |
+
cdef union _anon_pod2 '_anon_pod2':
|
| 301 |
+
_anon_pod3 batch
|
| 302 |
+
|
| 303 |
+
cdef extern from '<cufile.h>':
|
| 304 |
+
ctypedef struct CUfileStatsLevel1_t 'CUfileStatsLevel1_t':
|
| 305 |
+
CUfileOpCounter_t read_ops
|
| 306 |
+
CUfileOpCounter_t write_ops
|
| 307 |
+
CUfileOpCounter_t hdl_register_ops
|
| 308 |
+
CUfileOpCounter_t hdl_deregister_ops
|
| 309 |
+
CUfileOpCounter_t buf_register_ops
|
| 310 |
+
CUfileOpCounter_t buf_deregister_ops
|
| 311 |
+
uint64_t read_bytes
|
| 312 |
+
uint64_t write_bytes
|
| 313 |
+
uint64_t read_bw_bytes_per_sec
|
| 314 |
+
uint64_t write_bw_bytes_per_sec
|
| 315 |
+
uint64_t read_lat_avg_us
|
| 316 |
+
uint64_t write_lat_avg_us
|
| 317 |
+
uint64_t read_ops_per_sec
|
| 318 |
+
uint64_t write_ops_per_sec
|
| 319 |
+
uint64_t read_lat_sum_us
|
| 320 |
+
uint64_t write_lat_sum_us
|
| 321 |
+
CUfileOpCounter_t batch_submit_ops
|
| 322 |
+
CUfileOpCounter_t batch_complete_ops
|
| 323 |
+
CUfileOpCounter_t batch_setup_ops
|
| 324 |
+
CUfileOpCounter_t batch_cancel_ops
|
| 325 |
+
CUfileOpCounter_t batch_destroy_ops
|
| 326 |
+
CUfileOpCounter_t batch_enqueued_ops
|
| 327 |
+
CUfileOpCounter_t batch_posix_enqueued_ops
|
| 328 |
+
CUfileOpCounter_t batch_processed_ops
|
| 329 |
+
CUfileOpCounter_t batch_posix_processed_ops
|
| 330 |
+
CUfileOpCounter_t batch_nvfs_submit_ops
|
| 331 |
+
CUfileOpCounter_t batch_p2p_submit_ops
|
| 332 |
+
CUfileOpCounter_t batch_aio_submit_ops
|
| 333 |
+
CUfileOpCounter_t batch_iouring_submit_ops
|
| 334 |
+
CUfileOpCounter_t batch_mixed_io_submit_ops
|
| 335 |
+
CUfileOpCounter_t batch_total_submit_ops
|
| 336 |
+
uint64_t batch_read_bytes
|
| 337 |
+
uint64_t batch_write_bytes
|
| 338 |
+
uint64_t batch_read_bw_bytes
|
| 339 |
+
uint64_t batch_write_bw_bytes
|
| 340 |
+
uint64_t batch_submit_lat_avg_us
|
| 341 |
+
uint64_t batch_completion_lat_avg_us
|
| 342 |
+
uint64_t batch_submit_ops_per_sec
|
| 343 |
+
uint64_t batch_complete_ops_per_sec
|
| 344 |
+
uint64_t batch_submit_lat_sum_us
|
| 345 |
+
uint64_t batch_completion_lat_sum_us
|
| 346 |
+
uint64_t last_batch_read_bytes
|
| 347 |
+
uint64_t last_batch_write_bytes
|
| 348 |
+
|
| 349 |
+
cdef extern from '<cufile.h>':
|
| 350 |
+
ctypedef struct CUfileIOParams_t 'CUfileIOParams_t':
|
| 351 |
+
CUfileBatchMode_t mode
|
| 352 |
+
_anon_pod2 u
|
| 353 |
+
CUfileHandle_t fh
|
| 354 |
+
CUfileOpcode_t opcode
|
| 355 |
+
void* cookie
|
| 356 |
+
|
| 357 |
+
cdef extern from '<cufile.h>':
|
| 358 |
+
ctypedef struct CUfileStatsLevel2_t 'CUfileStatsLevel2_t':
|
| 359 |
+
CUfileStatsLevel1_t basic
|
| 360 |
+
uint64_t read_size_kb_hist[32]
|
| 361 |
+
uint64_t write_size_kb_hist[32]
|
| 362 |
+
|
| 363 |
+
cdef extern from '<cufile.h>':
|
| 364 |
+
ctypedef struct CUfileStatsLevel3_t 'CUfileStatsLevel3_t':
|
| 365 |
+
CUfileStatsLevel2_t detailed
|
| 366 |
+
uint32_t num_gpus
|
| 367 |
+
CUfilePerGpuStats_t per_gpu_stats[16]
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
cdef extern from *:
|
| 372 |
+
"""
|
| 373 |
+
// This is the missing piece we need to supply to help Cython & C++ compilers.
|
| 374 |
+
inline bool operator==(const CUfileError_t& lhs, const CUfileError_t& rhs) {
|
| 375 |
+
return (lhs.err == rhs.err) && (lhs.cu_err == rhs.cu_err);
|
| 376 |
+
}
|
| 377 |
+
static CUfileError_t CUFILE_LOADING_ERROR{(CUfileOpError)-1, (CUresult)-1};
|
| 378 |
+
"""
|
| 379 |
+
const CUfileError_t CUFILE_LOADING_ERROR
|
| 380 |
+
ctypedef void* CUstream "CUstream"
|
| 381 |
+
|
| 382 |
+
const char* cufileop_status_error(CUfileOpError)
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
###############################################################################
|
| 386 |
+
# Functions
|
| 387 |
+
###############################################################################
|
| 388 |
+
|
| 389 |
+
cdef CUfileError_t cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 390 |
+
cdef void cuFileHandleDeregister(CUfileHandle_t fh) except* nogil
|
| 391 |
+
cdef CUfileError_t cuFileBufRegister(const void* bufPtr_base, size_t length, int flags) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 392 |
+
cdef CUfileError_t cuFileBufDeregister(const void* bufPtr_base) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 393 |
+
cdef ssize_t cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil
|
| 394 |
+
cdef ssize_t cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil
|
| 395 |
+
cdef CUfileError_t cuFileDriverOpen() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 396 |
+
cdef CUfileError_t cuFileDriverClose() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 397 |
+
cdef CUfileError_t cuFileDriverClose_v2() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 398 |
+
cdef long cuFileUseCount() except* nogil
|
| 399 |
+
cdef CUfileError_t cuFileDriverGetProperties(CUfileDrvProps_t* props) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 400 |
+
cdef CUfileError_t cuFileDriverSetPollMode(cpp_bool poll, size_t poll_threshold_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 401 |
+
cdef CUfileError_t cuFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 402 |
+
cdef CUfileError_t cuFileDriverSetMaxCacheSize(size_t max_cache_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 403 |
+
cdef CUfileError_t cuFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 404 |
+
cdef CUfileError_t cuFileBatchIOSetUp(CUfileBatchHandle_t* batch_idp, unsigned nr) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 405 |
+
cdef CUfileError_t cuFileBatchIOSubmit(CUfileBatchHandle_t batch_idp, unsigned nr, CUfileIOParams_t* iocbp, unsigned int flags) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 406 |
+
cdef CUfileError_t cuFileBatchIOGetStatus(CUfileBatchHandle_t batch_idp, unsigned min_nr, unsigned* nr, CUfileIOEvents_t* iocbp, timespec* timeout) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 407 |
+
cdef CUfileError_t cuFileBatchIOCancel(CUfileBatchHandle_t batch_idp) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 408 |
+
cdef void cuFileBatchIODestroy(CUfileBatchHandle_t batch_idp) except* nogil
|
| 409 |
+
cdef CUfileError_t cuFileReadAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_read_p, CUstream stream) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 410 |
+
cdef CUfileError_t cuFileWriteAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_written_p, CUstream stream) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 411 |
+
cdef CUfileError_t cuFileStreamRegister(CUstream stream, unsigned flags) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 412 |
+
cdef CUfileError_t cuFileStreamDeregister(CUstream stream) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 413 |
+
cdef CUfileError_t cuFileGetVersion(int* version) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 414 |
+
cdef CUfileError_t cuFileGetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t* value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 415 |
+
cdef CUfileError_t cuFileGetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool* value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 416 |
+
cdef CUfileError_t cuFileGetParameterString(CUFileStringConfigParameter_t param, char* desc_str, int len) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 417 |
+
cdef CUfileError_t cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 418 |
+
cdef CUfileError_t cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 419 |
+
cdef CUfileError_t cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 420 |
+
cdef CUfileError_t cuFileGetParameterMinMaxValue(CUFileSizeTConfigParameter_t param, size_t* min_value, size_t* max_value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 421 |
+
cdef CUfileError_t cuFileSetStatsLevel(int level) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 422 |
+
cdef CUfileError_t cuFileGetStatsLevel(int* level) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 423 |
+
cdef CUfileError_t cuFileStatsStart() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 424 |
+
cdef CUfileError_t cuFileStatsStop() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 425 |
+
cdef CUfileError_t cuFileStatsReset() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 426 |
+
cdef CUfileError_t cuFileGetStatsL1(CUfileStatsLevel1_t* stats) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 427 |
+
cdef CUfileError_t cuFileGetStatsL2(CUfileStatsLevel2_t* stats) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 428 |
+
cdef CUfileError_t cuFileGetStatsL3(CUfileStatsLevel3_t* stats) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 429 |
+
cdef CUfileError_t cuFileGetBARSizeInKB(int gpuIndex, size_t* barSize) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 430 |
+
cdef CUfileError_t cuFileSetParameterPosixPoolSlabArray(const size_t* size_values, const size_t* count_values, int len) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
| 431 |
+
cdef CUfileError_t cuFileGetParameterPosixPoolSlabArray(size_t* size_values, size_t* count_values, int len) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
|
lib/python3.11/site-packages/cuda/pathfinder/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### The `cuda.pathfinder` documentation was moved
|
| 2 |
+
|
| 3 |
+
Please see https://nvidia.github.io/cuda-python/cuda-pathfinder/latest/
|
lib/python3.11/site-packages/cuda/pathfinder/__init__.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""cuda.pathfinder public APIs"""
|
| 5 |
+
|
| 6 |
+
# NOTE: When adding or removing public APIs from this file, remember to update
|
| 7 |
+
# cuda_pathfinder/docs/source/api.rst
|
| 8 |
+
# to keep the documentation in sync.
|
| 9 |
+
|
| 10 |
+
from cuda.pathfinder._binaries.find_nvidia_binary_utility import (
|
| 11 |
+
find_nvidia_binary_utility as find_nvidia_binary_utility,
|
| 12 |
+
)
|
| 13 |
+
from cuda.pathfinder._binaries.supported_nvidia_binaries import SUPPORTED_BINARIES as _SUPPORTED_BINARIES
|
| 14 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import (
|
| 15 |
+
DynamicLibNotAvailableError as DynamicLibNotAvailableError,
|
| 16 |
+
)
|
| 17 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError as DynamicLibNotFoundError
|
| 18 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import (
|
| 19 |
+
DynamicLibUnknownError as DynamicLibUnknownError,
|
| 20 |
+
)
|
| 21 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL as LoadedDL
|
| 22 |
+
from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib
|
| 23 |
+
from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import (
|
| 24 |
+
SUPPORTED_LIBNAMES as SUPPORTED_NVIDIA_LIBNAMES,
|
| 25 |
+
)
|
| 26 |
+
from cuda.pathfinder._headers.find_nvidia_headers import LocatedHeaderDir as LocatedHeaderDir
|
| 27 |
+
from cuda.pathfinder._headers.find_nvidia_headers import find_nvidia_header_directory as find_nvidia_header_directory
|
| 28 |
+
from cuda.pathfinder._headers.find_nvidia_headers import (
|
| 29 |
+
locate_nvidia_header_directory as locate_nvidia_header_directory,
|
| 30 |
+
)
|
| 31 |
+
from cuda.pathfinder._headers.supported_nvidia_headers import SUPPORTED_HEADERS_CTK as _SUPPORTED_HEADERS_CTK
|
| 32 |
+
from cuda.pathfinder._static_libs.find_bitcode_lib import (
|
| 33 |
+
SUPPORTED_BITCODE_LIBS as _SUPPORTED_BITCODE_LIBS,
|
| 34 |
+
)
|
| 35 |
+
from cuda.pathfinder._static_libs.find_bitcode_lib import (
|
| 36 |
+
BitcodeLibNotFoundError as BitcodeLibNotFoundError,
|
| 37 |
+
)
|
| 38 |
+
from cuda.pathfinder._static_libs.find_bitcode_lib import (
|
| 39 |
+
LocatedBitcodeLib as LocatedBitcodeLib,
|
| 40 |
+
)
|
| 41 |
+
from cuda.pathfinder._static_libs.find_bitcode_lib import (
|
| 42 |
+
find_bitcode_lib as find_bitcode_lib,
|
| 43 |
+
)
|
| 44 |
+
from cuda.pathfinder._static_libs.find_bitcode_lib import (
|
| 45 |
+
locate_bitcode_lib as locate_bitcode_lib,
|
| 46 |
+
)
|
| 47 |
+
from cuda.pathfinder._static_libs.find_static_lib import (
|
| 48 |
+
SUPPORTED_STATIC_LIBS as _SUPPORTED_STATIC_LIBS,
|
| 49 |
+
)
|
| 50 |
+
from cuda.pathfinder._static_libs.find_static_lib import (
|
| 51 |
+
LocatedStaticLib as LocatedStaticLib,
|
| 52 |
+
)
|
| 53 |
+
from cuda.pathfinder._static_libs.find_static_lib import (
|
| 54 |
+
StaticLibNotFoundError as StaticLibNotFoundError,
|
| 55 |
+
)
|
| 56 |
+
from cuda.pathfinder._static_libs.find_static_lib import (
|
| 57 |
+
find_static_lib as find_static_lib,
|
| 58 |
+
)
|
| 59 |
+
from cuda.pathfinder._static_libs.find_static_lib import (
|
| 60 |
+
locate_static_lib as locate_static_lib,
|
| 61 |
+
)
|
| 62 |
+
from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home as get_cuda_path_or_home
|
| 63 |
+
|
| 64 |
+
from cuda.pathfinder._version import __version__ # isort: skip
|
| 65 |
+
|
| 66 |
+
# Indirections to help Sphinx find the docstrings.
|
| 67 |
+
#: Mapping from short CUDA Toolkit (CTK) library names to their canonical
|
| 68 |
+
#: header basenames (used to validate a discovered include directory).
|
| 69 |
+
#: Example: ``"cublas" → "cublas.h"``. The key set is platform-aware
|
| 70 |
+
#: (e.g., ``"cufile"`` may be Linux-only).
|
| 71 |
+
SUPPORTED_HEADERS_CTK = _SUPPORTED_HEADERS_CTK
|
| 72 |
+
|
| 73 |
+
#: Tuple of supported CUDA binary utility names that can be located
|
| 74 |
+
#: via ``find_nvidia_binary_utility()``. Platform-aware (e.g., some
|
| 75 |
+
#: utilities may be available only on Linux or Windows).
|
| 76 |
+
#: Example utilities: ``"nvdisasm"``, ``"cuobjdump"``, ``"nvcc"``.
|
| 77 |
+
SUPPORTED_BINARY_UTILITIES = _SUPPORTED_BINARIES
|
| 78 |
+
|
| 79 |
+
#: Tuple of supported bitcode library names that can be resolved
|
| 80 |
+
#: via ``locate_bitcode_lib()`` and ``find_bitcode_lib()``.
|
| 81 |
+
#: Example value: ``"device"``.
|
| 82 |
+
SUPPORTED_BITCODE_LIBS = _SUPPORTED_BITCODE_LIBS
|
| 83 |
+
|
| 84 |
+
#: Tuple of supported static library names that can be resolved
|
| 85 |
+
#: via ``locate_static_lib()`` and ``find_static_lib()``.
|
| 86 |
+
#: Example value: ``"cudadevrt"``.
|
| 87 |
+
SUPPORTED_STATIC_LIBS = _SUPPORTED_STATIC_LIBS
|
| 88 |
+
|
| 89 |
+
# Backward compatibility: _find_nvidia_header_directory was added in release 1.2.2.
|
| 90 |
+
# It will be removed in release 1.2.4.
|
| 91 |
+
_find_nvidia_header_directory = find_nvidia_header_directory
|
lib/python3.11/site-packages/cuda/pathfinder/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (2.61 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/__pycache__/_optional_cuda_import.cpython-311.pyc
ADDED
|
Binary file (1.84 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/__pycache__/_version.cpython-311.pyc
ADDED
|
Binary file (722 Bytes). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_binaries/__pycache__/find_nvidia_binary_utility.cpython-311.pyc
ADDED
|
Binary file (6.15 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_binaries/__pycache__/supported_nvidia_binaries.cpython-311.pyc
ADDED
|
Binary file (1.25 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_binaries/find_nvidia_binary_utility.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
import functools
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
|
| 8 |
+
from cuda.pathfinder._binaries import supported_nvidia_binaries
|
| 9 |
+
from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home
|
| 10 |
+
from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages
|
| 11 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class UnsupportedBinaryError(Exception):
|
| 15 |
+
def __init__(self, utility: str) -> None:
|
| 16 |
+
super().__init__(utility)
|
| 17 |
+
self.utility = utility
|
| 18 |
+
|
| 19 |
+
def __str__(self) -> str:
|
| 20 |
+
supported_utilities = ", ".join(supported_nvidia_binaries.SUPPORTED_BINARIES)
|
| 21 |
+
return f"Binary '{self.utility}' is not supported. Supported utilities are: {supported_utilities}"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _normalize_utility_name(utility_name: str) -> str:
|
| 25 |
+
"""Normalize utility name by adding .exe on Windows if needed."""
|
| 26 |
+
if IS_WINDOWS and not utility_name.lower().endswith((".exe", ".bat", ".cmd")):
|
| 27 |
+
return f"{utility_name}.exe"
|
| 28 |
+
return utility_name
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@functools.cache
|
| 32 |
+
def find_nvidia_binary_utility(utility_name: str) -> str | None:
|
| 33 |
+
"""Locate a CUDA binary utility executable.
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
utility_name (str): The name of the binary utility to find
|
| 37 |
+
(e.g., ``"nvdisasm"``, ``"cuobjdump"``). On Windows, the ``.exe``
|
| 38 |
+
extension will be automatically appended if not present. The function
|
| 39 |
+
also recognizes ``.bat`` and ``.cmd`` files on Windows.
|
| 40 |
+
|
| 41 |
+
Returns:
|
| 42 |
+
str or None: Absolute path to the discovered executable, or ``None``
|
| 43 |
+
if the utility cannot be found. The returned path is normalized
|
| 44 |
+
(absolute and with resolved separators).
|
| 45 |
+
|
| 46 |
+
Raises:
|
| 47 |
+
UnsupportedBinaryError: If ``utility_name`` is not in the supported set
|
| 48 |
+
(see ``SUPPORTED_BINARY_UTILITIES``).
|
| 49 |
+
|
| 50 |
+
Search order:
|
| 51 |
+
1. **NVIDIA Python wheels**
|
| 52 |
+
|
| 53 |
+
- Scan installed distributions (``site-packages``) for binary layouts
|
| 54 |
+
shipped in NVIDIA wheels (e.g., ``cuda-nvcc``).
|
| 55 |
+
|
| 56 |
+
2. **Conda environments**
|
| 57 |
+
|
| 58 |
+
- Check Conda-style installation prefixes via ``CONDA_PREFIX``
|
| 59 |
+
environment variable, which use platform-specific bin directory
|
| 60 |
+
layouts (``Library/bin`` on Windows, ``bin`` on Linux).
|
| 61 |
+
|
| 62 |
+
3. **CUDA Toolkit environment variables**
|
| 63 |
+
|
| 64 |
+
- Use ``CUDA_HOME`` or ``CUDA_PATH`` (in that order), searching
|
| 65 |
+
``bin/x64``, ``bin/x86_64``, and ``bin`` subdirectories on Windows,
|
| 66 |
+
or just ``bin`` on Linux.
|
| 67 |
+
|
| 68 |
+
Note:
|
| 69 |
+
Results are cached using ``@functools.cache`` for performance. The cache
|
| 70 |
+
persists for the lifetime of the process.
|
| 71 |
+
|
| 72 |
+
On Windows, executables are identified by their file extensions
|
| 73 |
+
(``.exe``, ``.bat``, ``.cmd``). On Unix-like systems, executables
|
| 74 |
+
are identified by the ``X_OK`` (execute) permission bit.
|
| 75 |
+
|
| 76 |
+
Example:
|
| 77 |
+
>>> from cuda.pathfinder import find_nvidia_binary_utility
|
| 78 |
+
>>> nvdisasm = find_nvidia_binary_utility("nvdisasm")
|
| 79 |
+
>>> if nvdisasm:
|
| 80 |
+
... print(f"Found nvdisasm at: {nvdisasm}")
|
| 81 |
+
"""
|
| 82 |
+
if utility_name not in supported_nvidia_binaries.SUPPORTED_BINARIES:
|
| 83 |
+
raise UnsupportedBinaryError(utility_name)
|
| 84 |
+
|
| 85 |
+
# 1. Search in site-packages (NVIDIA wheels)
|
| 86 |
+
candidate_dirs = supported_nvidia_binaries.SITE_PACKAGES_BINDIRS.get(utility_name, ())
|
| 87 |
+
dirs = []
|
| 88 |
+
|
| 89 |
+
for sub_dir in candidate_dirs:
|
| 90 |
+
dirs.extend(find_sub_dirs_all_sitepackages(sub_dir.split(os.sep)))
|
| 91 |
+
|
| 92 |
+
# 2. Search in Conda environment
|
| 93 |
+
if (conda_prefix := os.environ.get("CONDA_PREFIX")) is not None:
|
| 94 |
+
if IS_WINDOWS:
|
| 95 |
+
dirs.append(os.path.join(conda_prefix, "Library", "bin"))
|
| 96 |
+
else:
|
| 97 |
+
dirs.append(os.path.join(conda_prefix, "bin"))
|
| 98 |
+
|
| 99 |
+
# 3. Search in CUDA Toolkit (CUDA_HOME/CUDA_PATH)
|
| 100 |
+
if (cuda_home := get_cuda_path_or_home()) is not None:
|
| 101 |
+
if IS_WINDOWS:
|
| 102 |
+
dirs.append(os.path.join(cuda_home, "bin", "x64"))
|
| 103 |
+
dirs.append(os.path.join(cuda_home, "bin", "x86_64"))
|
| 104 |
+
dirs.append(os.path.join(cuda_home, "bin"))
|
| 105 |
+
|
| 106 |
+
normalized_name = _normalize_utility_name(utility_name)
|
| 107 |
+
return shutil.which(normalized_name, path=os.pathsep.join(dirs))
|
lib/python3.11/site-packages/cuda/pathfinder/_binaries/supported_nvidia_binaries.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Site-packages bin directories where binaries might be found
|
| 6 |
+
# Based on NVIDIA wheel layouts (same for Linux and Windows)
|
| 7 |
+
_CUDA_NVCC_BIN = os.path.join("nvidia", "cuda_nvcc", "bin")
|
| 8 |
+
_CUDA13_BIN = os.path.join("nvidia", "cu13", "bin")
|
| 9 |
+
_NSIGHT_SYSTEMS_BIN = os.path.join("nvidia", "nsight_systems", "bin")
|
| 10 |
+
_NSIGHT_COMPUTE_BIN = os.path.join("nvidia", "nsight_compute", "bin")
|
| 11 |
+
|
| 12 |
+
# Common CUDA binary utilities available on both Linux and Windows
|
| 13 |
+
SITE_PACKAGES_BINDIRS = {
|
| 14 |
+
# Core compilation tools
|
| 15 |
+
"nvcc": (_CUDA13_BIN, _CUDA_NVCC_BIN),
|
| 16 |
+
"nvdisasm": (_CUDA13_BIN, _CUDA_NVCC_BIN),
|
| 17 |
+
"cuobjdump": (_CUDA_NVCC_BIN,),
|
| 18 |
+
"nvprune": (_CUDA_NVCC_BIN,),
|
| 19 |
+
"fatbinary": (_CUDA13_BIN, _CUDA_NVCC_BIN),
|
| 20 |
+
"bin2c": (_CUDA13_BIN, _CUDA_NVCC_BIN),
|
| 21 |
+
"nvlink": (_CUDA13_BIN, _CUDA_NVCC_BIN),
|
| 22 |
+
# Runtime/debugging tools
|
| 23 |
+
"cuda-gdb": (_CUDA_NVCC_BIN,),
|
| 24 |
+
"cuda-gdbserver": (_CUDA_NVCC_BIN,),
|
| 25 |
+
"compute-sanitizer": (_CUDA13_BIN, _CUDA_NVCC_BIN),
|
| 26 |
+
# Profiling tools
|
| 27 |
+
"nvprof": (_CUDA_NVCC_BIN,),
|
| 28 |
+
"nsys": (_NSIGHT_SYSTEMS_BIN,),
|
| 29 |
+
"nsight-sys": (_NSIGHT_SYSTEMS_BIN,),
|
| 30 |
+
"ncu": (_NSIGHT_COMPUTE_BIN,),
|
| 31 |
+
"nsight-compute": (_NSIGHT_COMPUTE_BIN,),
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
SUPPORTED_BINARIES_ALL = SUPPORTED_BINARIES = tuple(SITE_PACKAGES_BINDIRS.keys())
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/descriptor_catalog.cpython-311.pyc
ADDED
|
Binary file (9.88 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/dynamic_lib_subprocess.cpython-311.pyc
ADDED
|
Binary file (6.44 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/lib_descriptor.cpython-311.pyc
ADDED
|
Binary file (1.06 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_dl_common.cpython-311.pyc
ADDED
|
Binary file (1.99 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_dl_linux.cpython-311.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_dl_windows.cpython-311.pyc
ADDED
|
Binary file (7.3 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/load_nvidia_dynamic_lib.cpython-311.pyc
ADDED
|
Binary file (13.5 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/platform_loader.cpython-311.pyc
ADDED
|
Binary file (2.26 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/search_platform.cpython-311.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/search_steps.cpython-311.pyc
ADDED
|
Binary file (10.8 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/subprocess_protocol.cpython-311.pyc
ADDED
|
Binary file (4.3 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/__pycache__/supported_nvidia_libs.cpython-311.pyc
ADDED
|
Binary file (7.44 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/descriptor_catalog.py
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Canonical authored descriptor catalog for dynamic libraries."""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from typing import Literal
|
| 10 |
+
|
| 11 |
+
PackagedWith = Literal["ctk", "other", "driver"]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True, slots=True)
|
| 15 |
+
class DescriptorSpec:
|
| 16 |
+
name: str
|
| 17 |
+
packaged_with: PackagedWith
|
| 18 |
+
linux_sonames: tuple[str, ...] = ()
|
| 19 |
+
windows_dlls: tuple[str, ...] = ()
|
| 20 |
+
site_packages_linux: tuple[str, ...] = ()
|
| 21 |
+
site_packages_windows: tuple[str, ...] = ()
|
| 22 |
+
dependencies: tuple[str, ...] = ()
|
| 23 |
+
anchor_rel_dirs_linux: tuple[str, ...] = ("lib64", "lib")
|
| 24 |
+
anchor_rel_dirs_windows: tuple[str, ...] = ("bin/x64", "bin")
|
| 25 |
+
ctk_root_canary_anchor_libnames: tuple[str, ...] = ()
|
| 26 |
+
requires_add_dll_directory: bool = False
|
| 27 |
+
requires_rtld_deepbind: bool = False
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
DESCRIPTOR_CATALOG: tuple[DescriptorSpec, ...] = (
|
| 31 |
+
# -----------------------------------------------------------------------
|
| 32 |
+
# CTK (CUDA Toolkit) libraries
|
| 33 |
+
# -----------------------------------------------------------------------
|
| 34 |
+
DescriptorSpec(
|
| 35 |
+
name="cudart",
|
| 36 |
+
packaged_with="ctk",
|
| 37 |
+
linux_sonames=("libcudart.so.12", "libcudart.so.13"),
|
| 38 |
+
windows_dlls=("cudart64_12.dll", "cudart64_13.dll"),
|
| 39 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cuda_runtime/lib"),
|
| 40 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cuda_runtime/bin"),
|
| 41 |
+
),
|
| 42 |
+
DescriptorSpec(
|
| 43 |
+
name="nvfatbin",
|
| 44 |
+
packaged_with="ctk",
|
| 45 |
+
linux_sonames=("libnvfatbin.so.12", "libnvfatbin.so.13"),
|
| 46 |
+
windows_dlls=("nvfatbin_120_0.dll", "nvfatbin_130_0.dll"),
|
| 47 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/nvfatbin/lib"),
|
| 48 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/nvfatbin/bin"),
|
| 49 |
+
),
|
| 50 |
+
DescriptorSpec(
|
| 51 |
+
name="nvJitLink",
|
| 52 |
+
packaged_with="ctk",
|
| 53 |
+
linux_sonames=("libnvJitLink.so.12", "libnvJitLink.so.13"),
|
| 54 |
+
windows_dlls=("nvJitLink_120_0.dll", "nvJitLink_130_0.dll"),
|
| 55 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/nvjitlink/lib"),
|
| 56 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/nvjitlink/bin"),
|
| 57 |
+
),
|
| 58 |
+
DescriptorSpec(
|
| 59 |
+
name="nvrtc",
|
| 60 |
+
packaged_with="ctk",
|
| 61 |
+
linux_sonames=("libnvrtc.so.12", "libnvrtc.so.13"),
|
| 62 |
+
windows_dlls=("nvrtc64_120_0.dll", "nvrtc64_130_0.dll"),
|
| 63 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cuda_nvrtc/lib"),
|
| 64 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cuda_nvrtc/bin"),
|
| 65 |
+
requires_add_dll_directory=True,
|
| 66 |
+
),
|
| 67 |
+
DescriptorSpec(
|
| 68 |
+
name="nvvm",
|
| 69 |
+
packaged_with="ctk",
|
| 70 |
+
linux_sonames=("libnvvm.so.4",),
|
| 71 |
+
windows_dlls=("nvvm64.dll", "nvvm64_40_0.dll", "nvvm70.dll"),
|
| 72 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cuda_nvcc/nvvm/lib64"),
|
| 73 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cuda_nvcc/nvvm/bin"),
|
| 74 |
+
anchor_rel_dirs_linux=("nvvm/lib64",),
|
| 75 |
+
anchor_rel_dirs_windows=("nvvm/bin/*", "nvvm/bin"),
|
| 76 |
+
ctk_root_canary_anchor_libnames=("cudart",),
|
| 77 |
+
),
|
| 78 |
+
DescriptorSpec(
|
| 79 |
+
name="cublas",
|
| 80 |
+
packaged_with="ctk",
|
| 81 |
+
linux_sonames=("libcublas.so.12", "libcublas.so.13"),
|
| 82 |
+
windows_dlls=("cublas64_12.dll", "cublas64_13.dll"),
|
| 83 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cublas/lib"),
|
| 84 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cublas/bin"),
|
| 85 |
+
dependencies=("cublasLt",),
|
| 86 |
+
),
|
| 87 |
+
DescriptorSpec(
|
| 88 |
+
name="cublasLt",
|
| 89 |
+
packaged_with="ctk",
|
| 90 |
+
linux_sonames=("libcublasLt.so.12", "libcublasLt.so.13"),
|
| 91 |
+
windows_dlls=("cublasLt64_12.dll", "cublasLt64_13.dll"),
|
| 92 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cublas/lib"),
|
| 93 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cublas/bin"),
|
| 94 |
+
),
|
| 95 |
+
DescriptorSpec(
|
| 96 |
+
name="cufft",
|
| 97 |
+
packaged_with="ctk",
|
| 98 |
+
linux_sonames=("libcufft.so.11", "libcufft.so.12"),
|
| 99 |
+
windows_dlls=("cufft64_11.dll", "cufft64_12.dll"),
|
| 100 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cufft/lib"),
|
| 101 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cufft/bin"),
|
| 102 |
+
requires_add_dll_directory=True,
|
| 103 |
+
),
|
| 104 |
+
DescriptorSpec(
|
| 105 |
+
name="cufftw",
|
| 106 |
+
packaged_with="ctk",
|
| 107 |
+
linux_sonames=("libcufftw.so.11", "libcufftw.so.12"),
|
| 108 |
+
windows_dlls=("cufftw64_11.dll", "cufftw64_12.dll"),
|
| 109 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cufft/lib"),
|
| 110 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cufft/bin"),
|
| 111 |
+
dependencies=("cufft",),
|
| 112 |
+
),
|
| 113 |
+
DescriptorSpec(
|
| 114 |
+
name="curand",
|
| 115 |
+
packaged_with="ctk",
|
| 116 |
+
linux_sonames=("libcurand.so.10",),
|
| 117 |
+
windows_dlls=("curand64_10.dll",),
|
| 118 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/curand/lib"),
|
| 119 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/curand/bin"),
|
| 120 |
+
),
|
| 121 |
+
DescriptorSpec(
|
| 122 |
+
name="cusolver",
|
| 123 |
+
packaged_with="ctk",
|
| 124 |
+
linux_sonames=("libcusolver.so.11", "libcusolver.so.12"),
|
| 125 |
+
windows_dlls=("cusolver64_11.dll", "cusolver64_12.dll"),
|
| 126 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cusolver/lib"),
|
| 127 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cusolver/bin"),
|
| 128 |
+
dependencies=("nvJitLink", "cusparse", "cublasLt", "cublas"),
|
| 129 |
+
),
|
| 130 |
+
DescriptorSpec(
|
| 131 |
+
name="cusolverMg",
|
| 132 |
+
packaged_with="ctk",
|
| 133 |
+
linux_sonames=("libcusolverMg.so.11", "libcusolverMg.so.12"),
|
| 134 |
+
windows_dlls=("cusolverMg64_11.dll", "cusolverMg64_12.dll"),
|
| 135 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cusolver/lib"),
|
| 136 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cusolver/bin"),
|
| 137 |
+
dependencies=("nvJitLink", "cublasLt", "cublas"),
|
| 138 |
+
),
|
| 139 |
+
DescriptorSpec(
|
| 140 |
+
name="cusparse",
|
| 141 |
+
packaged_with="ctk",
|
| 142 |
+
linux_sonames=("libcusparse.so.12",),
|
| 143 |
+
windows_dlls=("cusparse64_12.dll",),
|
| 144 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cusparse/lib"),
|
| 145 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cusparse/bin"),
|
| 146 |
+
dependencies=("nvJitLink",),
|
| 147 |
+
),
|
| 148 |
+
DescriptorSpec(
|
| 149 |
+
name="nppc",
|
| 150 |
+
packaged_with="ctk",
|
| 151 |
+
linux_sonames=("libnppc.so.12", "libnppc.so.13"),
|
| 152 |
+
windows_dlls=("nppc64_12.dll", "nppc64_13.dll"),
|
| 153 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 154 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 155 |
+
),
|
| 156 |
+
DescriptorSpec(
|
| 157 |
+
name="nppial",
|
| 158 |
+
packaged_with="ctk",
|
| 159 |
+
linux_sonames=("libnppial.so.12", "libnppial.so.13"),
|
| 160 |
+
windows_dlls=("nppial64_12.dll", "nppial64_13.dll"),
|
| 161 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 162 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 163 |
+
dependencies=("nppc",),
|
| 164 |
+
),
|
| 165 |
+
DescriptorSpec(
|
| 166 |
+
name="nppicc",
|
| 167 |
+
packaged_with="ctk",
|
| 168 |
+
linux_sonames=("libnppicc.so.12", "libnppicc.so.13"),
|
| 169 |
+
windows_dlls=("nppicc64_12.dll", "nppicc64_13.dll"),
|
| 170 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 171 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 172 |
+
dependencies=("nppc",),
|
| 173 |
+
),
|
| 174 |
+
DescriptorSpec(
|
| 175 |
+
name="nppidei",
|
| 176 |
+
packaged_with="ctk",
|
| 177 |
+
linux_sonames=("libnppidei.so.12", "libnppidei.so.13"),
|
| 178 |
+
windows_dlls=("nppidei64_12.dll", "nppidei64_13.dll"),
|
| 179 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 180 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 181 |
+
dependencies=("nppc",),
|
| 182 |
+
),
|
| 183 |
+
DescriptorSpec(
|
| 184 |
+
name="nppif",
|
| 185 |
+
packaged_with="ctk",
|
| 186 |
+
linux_sonames=("libnppif.so.12", "libnppif.so.13"),
|
| 187 |
+
windows_dlls=("nppif64_12.dll", "nppif64_13.dll"),
|
| 188 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 189 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 190 |
+
dependencies=("nppc",),
|
| 191 |
+
),
|
| 192 |
+
DescriptorSpec(
|
| 193 |
+
name="nppig",
|
| 194 |
+
packaged_with="ctk",
|
| 195 |
+
linux_sonames=("libnppig.so.12", "libnppig.so.13"),
|
| 196 |
+
windows_dlls=("nppig64_12.dll", "nppig64_13.dll"),
|
| 197 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 198 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 199 |
+
dependencies=("nppc",),
|
| 200 |
+
),
|
| 201 |
+
DescriptorSpec(
|
| 202 |
+
name="nppim",
|
| 203 |
+
packaged_with="ctk",
|
| 204 |
+
linux_sonames=("libnppim.so.12", "libnppim.so.13"),
|
| 205 |
+
windows_dlls=("nppim64_12.dll", "nppim64_13.dll"),
|
| 206 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 207 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 208 |
+
dependencies=("nppc",),
|
| 209 |
+
),
|
| 210 |
+
DescriptorSpec(
|
| 211 |
+
name="nppist",
|
| 212 |
+
packaged_with="ctk",
|
| 213 |
+
linux_sonames=("libnppist.so.12", "libnppist.so.13"),
|
| 214 |
+
windows_dlls=("nppist64_12.dll", "nppist64_13.dll"),
|
| 215 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 216 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 217 |
+
dependencies=("nppc",),
|
| 218 |
+
),
|
| 219 |
+
DescriptorSpec(
|
| 220 |
+
name="nppisu",
|
| 221 |
+
packaged_with="ctk",
|
| 222 |
+
linux_sonames=("libnppisu.so.12", "libnppisu.so.13"),
|
| 223 |
+
windows_dlls=("nppisu64_12.dll", "nppisu64_13.dll"),
|
| 224 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 225 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 226 |
+
dependencies=("nppc",),
|
| 227 |
+
),
|
| 228 |
+
DescriptorSpec(
|
| 229 |
+
name="nppitc",
|
| 230 |
+
packaged_with="ctk",
|
| 231 |
+
linux_sonames=("libnppitc.so.12", "libnppitc.so.13"),
|
| 232 |
+
windows_dlls=("nppitc64_12.dll", "nppitc64_13.dll"),
|
| 233 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 234 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 235 |
+
dependencies=("nppc",),
|
| 236 |
+
),
|
| 237 |
+
DescriptorSpec(
|
| 238 |
+
name="npps",
|
| 239 |
+
packaged_with="ctk",
|
| 240 |
+
linux_sonames=("libnpps.so.12", "libnpps.so.13"),
|
| 241 |
+
windows_dlls=("npps64_12.dll", "npps64_13.dll"),
|
| 242 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/npp/lib"),
|
| 243 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/npp/bin"),
|
| 244 |
+
dependencies=("nppc",),
|
| 245 |
+
),
|
| 246 |
+
DescriptorSpec(
|
| 247 |
+
name="nvblas",
|
| 248 |
+
packaged_with="ctk",
|
| 249 |
+
linux_sonames=("libnvblas.so.12", "libnvblas.so.13"),
|
| 250 |
+
windows_dlls=("nvblas64_12.dll", "nvblas64_13.dll"),
|
| 251 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cublas/lib"),
|
| 252 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cublas/bin"),
|
| 253 |
+
dependencies=("cublas", "cublasLt"),
|
| 254 |
+
),
|
| 255 |
+
DescriptorSpec(
|
| 256 |
+
name="nvjpeg",
|
| 257 |
+
packaged_with="ctk",
|
| 258 |
+
linux_sonames=("libnvjpeg.so.12", "libnvjpeg.so.13"),
|
| 259 |
+
windows_dlls=("nvjpeg64_12.dll", "nvjpeg64_13.dll"),
|
| 260 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/nvjpeg/lib"),
|
| 261 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/nvjpeg/bin"),
|
| 262 |
+
),
|
| 263 |
+
DescriptorSpec(
|
| 264 |
+
name="cufile",
|
| 265 |
+
packaged_with="ctk",
|
| 266 |
+
linux_sonames=("libcufile.so.0",),
|
| 267 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cufile/lib"),
|
| 268 |
+
),
|
| 269 |
+
DescriptorSpec(
|
| 270 |
+
name="cupti",
|
| 271 |
+
packaged_with="ctk",
|
| 272 |
+
linux_sonames=("libcupti.so.12", "libcupti.so.13"),
|
| 273 |
+
windows_dlls=(
|
| 274 |
+
"cupti64_2026.1.1.dll",
|
| 275 |
+
"cupti64_2026.1.0.dll",
|
| 276 |
+
"cupti64_2025.4.1.dll",
|
| 277 |
+
"cupti64_2025.3.1.dll",
|
| 278 |
+
"cupti64_2025.2.1.dll",
|
| 279 |
+
"cupti64_2025.1.1.dll",
|
| 280 |
+
"cupti64_2024.3.2.dll",
|
| 281 |
+
"cupti64_2024.2.1.dll",
|
| 282 |
+
"cupti64_2024.1.1.dll",
|
| 283 |
+
"cupti64_2023.3.1.dll",
|
| 284 |
+
"cupti64_2023.2.2.dll",
|
| 285 |
+
"cupti64_2023.1.1.dll",
|
| 286 |
+
"cupti64_2022.4.1.dll",
|
| 287 |
+
),
|
| 288 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cuda_cupti/lib"),
|
| 289 |
+
site_packages_windows=("nvidia/cu13/bin/x86_64", "nvidia/cuda_cupti/bin"),
|
| 290 |
+
anchor_rel_dirs_linux=("extras/CUPTI/lib64", "lib"),
|
| 291 |
+
anchor_rel_dirs_windows=("extras/CUPTI/lib64", "bin"),
|
| 292 |
+
ctk_root_canary_anchor_libnames=("cudart",),
|
| 293 |
+
),
|
| 294 |
+
DescriptorSpec(
|
| 295 |
+
name="cudla",
|
| 296 |
+
packaged_with="ctk",
|
| 297 |
+
linux_sonames=("libcudla.so.1",),
|
| 298 |
+
site_packages_linux=("nvidia/cu13/lib",),
|
| 299 |
+
),
|
| 300 |
+
# -----------------------------------------------------------------------
|
| 301 |
+
# Third-party / separately packaged libraries
|
| 302 |
+
# -----------------------------------------------------------------------
|
| 303 |
+
DescriptorSpec(
|
| 304 |
+
name="cublasmp",
|
| 305 |
+
packaged_with="other",
|
| 306 |
+
linux_sonames=("libcublasmp.so.0",),
|
| 307 |
+
site_packages_linux=("nvidia/cublasmp/cu13/lib", "nvidia/cublasmp/cu12/lib"),
|
| 308 |
+
dependencies=("cublas", "cublasLt", "nvshmem_host"),
|
| 309 |
+
),
|
| 310 |
+
DescriptorSpec(
|
| 311 |
+
name="cufftMp",
|
| 312 |
+
packaged_with="other",
|
| 313 |
+
linux_sonames=("libcufftMp.so.12", "libcufftMp.so.11"),
|
| 314 |
+
site_packages_linux=("nvidia/cufftmp/cu13/lib", "nvidia/cufftmp/cu12/lib"),
|
| 315 |
+
dependencies=("nvshmem_host",),
|
| 316 |
+
requires_rtld_deepbind=True,
|
| 317 |
+
),
|
| 318 |
+
DescriptorSpec(
|
| 319 |
+
name="cusolverMp",
|
| 320 |
+
packaged_with="other",
|
| 321 |
+
linux_sonames=("libcusolverMp.so.0",),
|
| 322 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cu12/lib"),
|
| 323 |
+
dependencies=("cublas", "cudart", "cusolver", "nccl"),
|
| 324 |
+
),
|
| 325 |
+
DescriptorSpec(
|
| 326 |
+
name="mathdx",
|
| 327 |
+
packaged_with="other",
|
| 328 |
+
linux_sonames=("libmathdx.so.0",),
|
| 329 |
+
windows_dlls=("mathdx64_0.dll",),
|
| 330 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cu12/lib"),
|
| 331 |
+
site_packages_windows=("nvidia/cu13/bin", "nvidia/cu12/bin"),
|
| 332 |
+
dependencies=("nvrtc",),
|
| 333 |
+
),
|
| 334 |
+
DescriptorSpec(
|
| 335 |
+
name="cudss",
|
| 336 |
+
packaged_with="other",
|
| 337 |
+
linux_sonames=("libcudss.so.0",),
|
| 338 |
+
windows_dlls=("cudss64_0.dll",),
|
| 339 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cu12/lib"),
|
| 340 |
+
site_packages_windows=("nvidia/cu13/bin", "nvidia/cu12/bin"),
|
| 341 |
+
dependencies=("cublas", "cublasLt"),
|
| 342 |
+
),
|
| 343 |
+
DescriptorSpec(
|
| 344 |
+
name="cusparseLt",
|
| 345 |
+
packaged_with="other",
|
| 346 |
+
linux_sonames=("libcusparseLt.so.0",),
|
| 347 |
+
windows_dlls=("cusparseLt.dll",),
|
| 348 |
+
site_packages_linux=("nvidia/cu13/lib", "nvidia/cusparselt/lib"),
|
| 349 |
+
site_packages_windows=("nvidia/cu13/bin/x64", "nvidia/cusparselt/bin"),
|
| 350 |
+
),
|
| 351 |
+
DescriptorSpec(
|
| 352 |
+
name="cutensor",
|
| 353 |
+
packaged_with="other",
|
| 354 |
+
linux_sonames=("libcutensor.so.2",),
|
| 355 |
+
windows_dlls=("cutensor.dll",),
|
| 356 |
+
site_packages_linux=("cutensor/lib",),
|
| 357 |
+
site_packages_windows=("cutensor/bin",),
|
| 358 |
+
dependencies=("cublasLt",),
|
| 359 |
+
),
|
| 360 |
+
DescriptorSpec(
|
| 361 |
+
name="cutensorMg",
|
| 362 |
+
packaged_with="other",
|
| 363 |
+
linux_sonames=("libcutensorMg.so.2",),
|
| 364 |
+
windows_dlls=("cutensorMg.dll",),
|
| 365 |
+
site_packages_linux=("cutensor/lib",),
|
| 366 |
+
site_packages_windows=("cutensor/bin",),
|
| 367 |
+
dependencies=("cutensor", "cublasLt"),
|
| 368 |
+
),
|
| 369 |
+
DescriptorSpec(
|
| 370 |
+
name="nccl",
|
| 371 |
+
packaged_with="other",
|
| 372 |
+
linux_sonames=("libnccl.so.2",),
|
| 373 |
+
site_packages_linux=("nvidia/nccl/lib",),
|
| 374 |
+
),
|
| 375 |
+
DescriptorSpec(
|
| 376 |
+
name="nvpl_fftw",
|
| 377 |
+
packaged_with="other",
|
| 378 |
+
linux_sonames=("libnvpl_fftw.so.0",),
|
| 379 |
+
site_packages_linux=("nvpl/lib",),
|
| 380 |
+
),
|
| 381 |
+
DescriptorSpec(
|
| 382 |
+
name="nvshmem_host",
|
| 383 |
+
packaged_with="other",
|
| 384 |
+
linux_sonames=("libnvshmem_host.so.3",),
|
| 385 |
+
site_packages_linux=("nvidia/nvshmem/lib",),
|
| 386 |
+
),
|
| 387 |
+
# -----------------------------------------------------------------------
|
| 388 |
+
# Driver libraries (system-search only, no CTK cascade)
|
| 389 |
+
# -----------------------------------------------------------------------
|
| 390 |
+
DescriptorSpec(
|
| 391 |
+
name="cuda",
|
| 392 |
+
packaged_with="driver",
|
| 393 |
+
linux_sonames=("libcuda.so.1",),
|
| 394 |
+
windows_dlls=("nvcuda.dll",),
|
| 395 |
+
),
|
| 396 |
+
DescriptorSpec(
|
| 397 |
+
name="nvcudla",
|
| 398 |
+
packaged_with="driver",
|
| 399 |
+
linux_sonames=("libnvcudla.so",),
|
| 400 |
+
),
|
| 401 |
+
DescriptorSpec(
|
| 402 |
+
name="nvml",
|
| 403 |
+
packaged_with="driver",
|
| 404 |
+
linux_sonames=("libnvidia-ml.so.1",),
|
| 405 |
+
windows_dlls=("nvml.dll",),
|
| 406 |
+
),
|
| 407 |
+
)
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/dynamic_lib_subprocess.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 3 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
from collections.abc import Sequence
|
| 10 |
+
|
| 11 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS
|
| 12 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL
|
| 13 |
+
from cuda.pathfinder._dynamic_libs.platform_loader import LOADER
|
| 14 |
+
from cuda.pathfinder._dynamic_libs.subprocess_protocol import (
|
| 15 |
+
MODE_CANARY,
|
| 16 |
+
MODE_LOAD,
|
| 17 |
+
STATUS_NOT_FOUND,
|
| 18 |
+
STATUS_OK,
|
| 19 |
+
VALID_MODES,
|
| 20 |
+
format_dynamic_lib_subprocess_payload,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# NOTE: The main entrypoint (below) serves both production (canary probe)
|
| 24 |
+
# and tests (full loader). Keeping them together ensures a single subprocess
|
| 25 |
+
# protocol and CLI surface, so the test subprocess stays aligned with the
|
| 26 |
+
# production flow while avoiding a separate test-only module.
|
| 27 |
+
# Any production-code impact is negligible since the extra logic only runs
|
| 28 |
+
# in the subprocess entrypoint and only in test mode.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _probe_canary_abs_path(libname: str) -> str | None:
|
| 32 |
+
desc = LIB_DESCRIPTORS.get(libname)
|
| 33 |
+
if desc is None:
|
| 34 |
+
raise ValueError(f"Unsupported canary library name: {libname!r}")
|
| 35 |
+
try:
|
| 36 |
+
loaded: LoadedDL | None = LOADER.load_with_system_search(desc)
|
| 37 |
+
except DynamicLibNotFoundError:
|
| 38 |
+
return None
|
| 39 |
+
if loaded is None:
|
| 40 |
+
return None
|
| 41 |
+
abs_path: str | None = loaded.abs_path
|
| 42 |
+
return abs_path
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def _validate_abs_path(abs_path: str) -> None:
|
| 46 |
+
assert abs_path, f"empty path: {abs_path=!r}"
|
| 47 |
+
assert os.path.isabs(abs_path), f"not absolute: {abs_path=!r}"
|
| 48 |
+
assert os.path.isfile(abs_path), f"not a file: {abs_path=!r}"
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _load_nvidia_dynamic_lib_for_test(libname: str) -> str:
|
| 52 |
+
"""Test-only loader used by the subprocess entrypoint."""
|
| 53 |
+
# Keep imports inside the subprocess body so startup stays focused on the
|
| 54 |
+
# code under test rather than the parent test module.
|
| 55 |
+
from cuda.pathfinder import load_nvidia_dynamic_lib
|
| 56 |
+
from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import _load_lib_no_cache
|
| 57 |
+
from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import (
|
| 58 |
+
SUPPORTED_LINUX_SONAMES,
|
| 59 |
+
SUPPORTED_WINDOWS_DLLS,
|
| 60 |
+
)
|
| 61 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 62 |
+
|
| 63 |
+
loaded_dl_fresh = load_nvidia_dynamic_lib(libname)
|
| 64 |
+
if loaded_dl_fresh.was_already_loaded_from_elsewhere:
|
| 65 |
+
raise RuntimeError("loaded_dl_fresh.was_already_loaded_from_elsewhere")
|
| 66 |
+
|
| 67 |
+
abs_path = loaded_dl_fresh.abs_path
|
| 68 |
+
if not isinstance(abs_path, str):
|
| 69 |
+
raise RuntimeError(f"loaded_dl_fresh.abs_path is not a string: {abs_path!r}")
|
| 70 |
+
_validate_abs_path(abs_path)
|
| 71 |
+
assert loaded_dl_fresh.found_via is not None
|
| 72 |
+
|
| 73 |
+
loaded_dl_from_cache = load_nvidia_dynamic_lib(libname)
|
| 74 |
+
if loaded_dl_from_cache is not loaded_dl_fresh:
|
| 75 |
+
raise RuntimeError("loaded_dl_from_cache is not loaded_dl_fresh")
|
| 76 |
+
|
| 77 |
+
loaded_dl_no_cache = _load_lib_no_cache(libname)
|
| 78 |
+
supported_libs = SUPPORTED_WINDOWS_DLLS if IS_WINDOWS else SUPPORTED_LINUX_SONAMES
|
| 79 |
+
if not loaded_dl_no_cache.was_already_loaded_from_elsewhere and libname in supported_libs:
|
| 80 |
+
raise RuntimeError("not loaded_dl_no_cache.was_already_loaded_from_elsewhere")
|
| 81 |
+
abs_path_no_cache = loaded_dl_no_cache.abs_path
|
| 82 |
+
if not isinstance(abs_path_no_cache, str):
|
| 83 |
+
raise RuntimeError(f"loaded_dl_no_cache.abs_path is not a string: {abs_path_no_cache!r}")
|
| 84 |
+
if not os.path.samefile(abs_path_no_cache, abs_path):
|
| 85 |
+
raise RuntimeError(f"not os.path.samefile({abs_path_no_cache=!r}, {abs_path=!r})")
|
| 86 |
+
_validate_abs_path(abs_path_no_cache)
|
| 87 |
+
return abs_path
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def probe_dynamic_lib_and_print_json(libname: str, mode: str) -> None:
|
| 91 |
+
if mode == MODE_CANARY:
|
| 92 |
+
abs_path = _probe_canary_abs_path(libname)
|
| 93 |
+
status = STATUS_OK if abs_path is not None else STATUS_NOT_FOUND
|
| 94 |
+
print(format_dynamic_lib_subprocess_payload(status, abs_path))
|
| 95 |
+
return
|
| 96 |
+
|
| 97 |
+
if mode == MODE_LOAD:
|
| 98 |
+
# Test-only path: exercises full loader behavior in isolation.
|
| 99 |
+
try:
|
| 100 |
+
abs_path = _load_nvidia_dynamic_lib_for_test(libname)
|
| 101 |
+
except DynamicLibNotFoundError as exc:
|
| 102 |
+
error = {
|
| 103 |
+
"type": exc.__class__.__name__,
|
| 104 |
+
"message": str(exc),
|
| 105 |
+
}
|
| 106 |
+
print(format_dynamic_lib_subprocess_payload(STATUS_NOT_FOUND, None, error=error))
|
| 107 |
+
return
|
| 108 |
+
print(format_dynamic_lib_subprocess_payload(STATUS_OK, abs_path))
|
| 109 |
+
return
|
| 110 |
+
|
| 111 |
+
raise ValueError(f"Unsupported subprocess probe mode: {mode!r}")
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def main(argv: Sequence[str] | None = None) -> int:
|
| 115 |
+
args = list(sys.argv[1:] if argv is None else argv)
|
| 116 |
+
if len(args) != 2 or args[0] not in VALID_MODES:
|
| 117 |
+
modes = ", ".join(VALID_MODES)
|
| 118 |
+
raise SystemExit(
|
| 119 |
+
f"Usage: python -m cuda.pathfinder._dynamic_libs.dynamic_lib_subprocess <mode> <libname>\nModes: {modes}"
|
| 120 |
+
)
|
| 121 |
+
mode, libname = args
|
| 122 |
+
probe_dynamic_lib_and_print_json(libname, mode)
|
| 123 |
+
return 0
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
raise SystemExit(main())
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/lib_descriptor.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Per-library descriptor and registry.
|
| 5 |
+
|
| 6 |
+
The canonical authored data lives in :mod:`descriptor_catalog`. This module
|
| 7 |
+
provides a name-keyed registry consumed by the runtime search/load path.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
from typing import TypeAlias
|
| 13 |
+
|
| 14 |
+
from cuda.pathfinder._dynamic_libs.descriptor_catalog import (
|
| 15 |
+
DESCRIPTOR_CATALOG,
|
| 16 |
+
DescriptorSpec,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Keep the historical type name for downstream imports.
|
| 20 |
+
LibDescriptor: TypeAlias = DescriptorSpec
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
#: Canonical registry of all known libraries.
|
| 24 |
+
LIB_DESCRIPTORS: dict[str, LibDescriptor] = {desc.name: desc for desc in DESCRIPTOR_CATALOG}
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_dl_common.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
from collections.abc import Callable
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
+
from typing import TYPE_CHECKING
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class DynamicLibNotFoundError(RuntimeError):
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class DynamicLibNotAvailableError(DynamicLibNotFoundError):
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class DynamicLibUnknownError(DynamicLibNotFoundError):
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@dataclass
|
| 27 |
+
class LoadedDL:
|
| 28 |
+
abs_path: str | None
|
| 29 |
+
was_already_loaded_from_elsewhere: bool
|
| 30 |
+
_handle_uint: int # Platform-agnostic unsigned pointer value
|
| 31 |
+
found_via: str # "CUDA_PATH" covers both CUDA_PATH and CUDA_HOME env vars
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def load_dependencies(desc: LibDescriptor, load_func: Callable[[str], LoadedDL]) -> None:
|
| 35 |
+
for dep in desc.dependencies:
|
| 36 |
+
load_func(dep)
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_dl_linux.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import contextlib
|
| 7 |
+
import ctypes
|
| 8 |
+
import ctypes.util
|
| 9 |
+
import os
|
| 10 |
+
from typing import TYPE_CHECKING, cast
|
| 11 |
+
|
| 12 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL
|
| 13 |
+
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 16 |
+
|
| 17 |
+
CDLL_MODE = os.RTLD_NOW | os.RTLD_GLOBAL
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _load_libdl() -> ctypes.CDLL:
|
| 21 |
+
# In normal glibc-based Linux environments, find_library("dl") should return
|
| 22 |
+
# something like "libdl.so.2". In minimal or stripped-down environments
|
| 23 |
+
# (no ldconfig/gcc, incomplete linker cache), this can return None even
|
| 24 |
+
# though libdl is present. In that case, we fall back to the stable SONAME.
|
| 25 |
+
name = ctypes.util.find_library("dl") or "libdl.so.2"
|
| 26 |
+
try:
|
| 27 |
+
return ctypes.CDLL(name)
|
| 28 |
+
except OSError as e:
|
| 29 |
+
raise RuntimeError(f"Could not load {name!r} (required for dlinfo/dlerror on Linux)") from e
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
LIBDL = _load_libdl()
|
| 33 |
+
|
| 34 |
+
# dlinfo
|
| 35 |
+
LIBDL.dlinfo.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p]
|
| 36 |
+
LIBDL.dlinfo.restype = ctypes.c_int
|
| 37 |
+
|
| 38 |
+
# dlerror (thread-local error string; cleared after read)
|
| 39 |
+
LIBDL.dlerror.argtypes = []
|
| 40 |
+
LIBDL.dlerror.restype = ctypes.c_char_p
|
| 41 |
+
|
| 42 |
+
# First appeared in 2004-era glibc. Universally correct on Linux for all practical purposes.
|
| 43 |
+
RTLD_DI_LINKMAP = 2
|
| 44 |
+
RTLD_DI_ORIGIN = 6
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class _LinkMapLNameView(ctypes.Structure):
|
| 48 |
+
"""
|
| 49 |
+
Prefix-only view of glibc's `struct link_map` used **solely** to read `l_name`.
|
| 50 |
+
|
| 51 |
+
Background:
|
| 52 |
+
- `dlinfo(handle, RTLD_DI_LINKMAP, ...)` returns a `struct link_map*`.
|
| 53 |
+
- The first few members of `struct link_map` (including `l_name`) have been
|
| 54 |
+
stable on glibc for decades and are documented as debugger-visible.
|
| 55 |
+
- We only need the offset/layout of `l_name`, not the full struct.
|
| 56 |
+
|
| 57 |
+
Safety constraints:
|
| 58 |
+
- This is a **partial** definition (prefix). It must only be used via a pointer
|
| 59 |
+
returned by `dlinfo(...)`.
|
| 60 |
+
- Do **not** instantiate it or pass it **by value** to any C function.
|
| 61 |
+
- Do **not** access any members beyond those declared here.
|
| 62 |
+
- Do **not** rely on `ctypes.sizeof(LinkMapPrefix)` for allocation.
|
| 63 |
+
|
| 64 |
+
Rationale:
|
| 65 |
+
- Defining only the leading fields avoids depending on internal/unstable
|
| 66 |
+
tail members while keeping code more readable than raw pointer arithmetic.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
_fields_ = (
|
| 70 |
+
("l_addr", ctypes.c_void_p), # ElfW(Addr)
|
| 71 |
+
("l_name", ctypes.c_char_p), # char*
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# Defensive assertions, mainly to document the invariants we depend on
|
| 76 |
+
assert _LinkMapLNameView.l_addr.offset == 0
|
| 77 |
+
assert _LinkMapLNameView.l_name.offset == ctypes.sizeof(ctypes.c_void_p)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _dl_last_error() -> str | None:
|
| 81 |
+
msg_bytes = cast(bytes | None, LIBDL.dlerror())
|
| 82 |
+
if not msg_bytes:
|
| 83 |
+
return None # no pending error
|
| 84 |
+
# Never raises; undecodable bytes are mapped to U+DC80..U+DCFF
|
| 85 |
+
return msg_bytes.decode("utf-8", "surrogateescape")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def l_name_for_dynamic_library(libname: str, handle: ctypes.CDLL) -> str:
|
| 89 |
+
lm_view = ctypes.POINTER(_LinkMapLNameView)()
|
| 90 |
+
rc = LIBDL.dlinfo(ctypes.c_void_p(handle._handle), RTLD_DI_LINKMAP, ctypes.byref(lm_view))
|
| 91 |
+
if rc != 0:
|
| 92 |
+
err = _dl_last_error()
|
| 93 |
+
raise OSError(f"dlinfo failed for {libname=!r} (rc={rc})" + (f": {err}" if err else ""))
|
| 94 |
+
if not lm_view: # NULL link_map**
|
| 95 |
+
raise OSError(f"dlinfo returned NULL link_map pointer for {libname=!r}")
|
| 96 |
+
|
| 97 |
+
l_name_bytes = lm_view.contents.l_name
|
| 98 |
+
if not l_name_bytes:
|
| 99 |
+
raise OSError(f"dlinfo returned empty link_map->l_name for {libname=!r}")
|
| 100 |
+
|
| 101 |
+
path = os.fsdecode(l_name_bytes)
|
| 102 |
+
if not path:
|
| 103 |
+
raise OSError(f"dlinfo returned empty l_name string for {libname=!r}")
|
| 104 |
+
|
| 105 |
+
return path
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def l_origin_for_dynamic_library(libname: str, handle: ctypes.CDLL) -> str:
|
| 109 |
+
l_origin_buf = ctypes.create_string_buffer(4096)
|
| 110 |
+
rc = LIBDL.dlinfo(ctypes.c_void_p(handle._handle), RTLD_DI_ORIGIN, l_origin_buf)
|
| 111 |
+
if rc != 0:
|
| 112 |
+
err = _dl_last_error()
|
| 113 |
+
raise OSError(f"dlinfo failed for {libname=!r} (rc={rc})" + (f": {err}" if err else ""))
|
| 114 |
+
|
| 115 |
+
path = os.fsdecode(l_origin_buf.value)
|
| 116 |
+
if not path:
|
| 117 |
+
raise OSError(f"dlinfo returned empty l_origin string for {libname=!r}")
|
| 118 |
+
|
| 119 |
+
return path
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def abs_path_for_dynamic_library(libname: str, handle: ctypes.CDLL) -> str:
|
| 123 |
+
l_name = l_name_for_dynamic_library(libname, handle)
|
| 124 |
+
l_origin = l_origin_for_dynamic_library(libname, handle)
|
| 125 |
+
return os.path.join(l_origin, os.path.basename(l_name))
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def _candidate_sonames(desc: LibDescriptor) -> list[str]:
|
| 129 |
+
# Reverse tabulated names to achieve new -> old search order.
|
| 130 |
+
candidates = list(reversed(desc.linux_sonames))
|
| 131 |
+
candidates.append(f"lib{desc.name}.so")
|
| 132 |
+
return candidates
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def check_if_already_loaded_from_elsewhere(desc: LibDescriptor, _have_abs_path: bool) -> LoadedDL | None:
|
| 136 |
+
for soname in _candidate_sonames(desc):
|
| 137 |
+
try:
|
| 138 |
+
handle = ctypes.CDLL(soname, mode=os.RTLD_NOLOAD)
|
| 139 |
+
except OSError:
|
| 140 |
+
continue
|
| 141 |
+
else:
|
| 142 |
+
return LoadedDL(
|
| 143 |
+
abs_path_for_dynamic_library(desc.name, handle),
|
| 144 |
+
True,
|
| 145 |
+
handle._handle,
|
| 146 |
+
"was-already-loaded-from-elsewhere",
|
| 147 |
+
)
|
| 148 |
+
return None
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _load_lib(desc: LibDescriptor, filename: str) -> ctypes.CDLL:
|
| 152 |
+
cdll_mode = CDLL_MODE
|
| 153 |
+
if desc.requires_rtld_deepbind:
|
| 154 |
+
cdll_mode |= os.RTLD_DEEPBIND
|
| 155 |
+
return ctypes.CDLL(filename, cdll_mode)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def load_with_system_search(desc: LibDescriptor) -> LoadedDL | None:
|
| 159 |
+
"""Try to load a library using the native Linux dynamic-loader search path.
|
| 160 |
+
|
| 161 |
+
Args:
|
| 162 |
+
desc: Descriptor for the library to load
|
| 163 |
+
|
| 164 |
+
Returns:
|
| 165 |
+
A LoadedDL object if successful, None if the library cannot be loaded
|
| 166 |
+
|
| 167 |
+
Raises:
|
| 168 |
+
RuntimeError: If the library is loaded but no expected symbol is found
|
| 169 |
+
"""
|
| 170 |
+
for soname in _candidate_sonames(desc):
|
| 171 |
+
try:
|
| 172 |
+
handle = _load_lib(desc, soname)
|
| 173 |
+
except OSError:
|
| 174 |
+
pass
|
| 175 |
+
else:
|
| 176 |
+
abs_path = abs_path_for_dynamic_library(desc.name, handle)
|
| 177 |
+
if abs_path is None:
|
| 178 |
+
raise RuntimeError(f"No expected symbol for libname={desc.name!r}")
|
| 179 |
+
return LoadedDL(abs_path, False, handle._handle, "system-search")
|
| 180 |
+
return None
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def _work_around_known_bugs(libname: str, found_path: str) -> None:
|
| 184 |
+
if libname == "nvrtc":
|
| 185 |
+
# Work around bug/oversight in
|
| 186 |
+
# nvidia_cuda_nvrtc-13.0.48-py3-none-manylinux2010_x86_64.manylinux_2_12_x86_64.whl
|
| 187 |
+
# Issue: libnvrtc.so.13 RUNPATH is not set.
|
| 188 |
+
# This workaround is highly specific
|
| 189 |
+
# - for simplicity.
|
| 190 |
+
# - to not mask bugs in future nvidia-cuda-nvrtc releases.
|
| 191 |
+
# - because a more general workaround is complicated.
|
| 192 |
+
dirname, basename = os.path.split(found_path)
|
| 193 |
+
if basename == "libnvrtc.so.13":
|
| 194 |
+
dep_basename = "libnvrtc-builtins.so.13.0"
|
| 195 |
+
dep_path = os.path.join(dirname, dep_basename)
|
| 196 |
+
if os.path.isfile(dep_path):
|
| 197 |
+
# In case of failure, defer to primary load, which is almost certain to fail, too.
|
| 198 |
+
with contextlib.suppress(OSError):
|
| 199 |
+
ctypes.CDLL(dep_path, CDLL_MODE)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL:
|
| 203 |
+
"""Load a dynamic library from the given path.
|
| 204 |
+
|
| 205 |
+
Args:
|
| 206 |
+
desc: Descriptor for the library to load.
|
| 207 |
+
found_path: The absolute path to the library file.
|
| 208 |
+
found_via: Label indicating how the path was discovered.
|
| 209 |
+
|
| 210 |
+
Returns:
|
| 211 |
+
A LoadedDL object representing the loaded library.
|
| 212 |
+
|
| 213 |
+
Raises:
|
| 214 |
+
RuntimeError: If the library cannot be loaded.
|
| 215 |
+
"""
|
| 216 |
+
_work_around_known_bugs(desc.name, found_path)
|
| 217 |
+
try:
|
| 218 |
+
handle = _load_lib(desc, found_path)
|
| 219 |
+
except OSError as e:
|
| 220 |
+
raise RuntimeError(f"Failed to dlopen {found_path}: {e}") from e
|
| 221 |
+
return LoadedDL(found_path, False, handle._handle, found_via)
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_dl_windows.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import ctypes
|
| 7 |
+
import ctypes.wintypes
|
| 8 |
+
import os
|
| 9 |
+
import struct
|
| 10 |
+
from typing import TYPE_CHECKING
|
| 11 |
+
|
| 12 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL
|
| 13 |
+
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 16 |
+
|
| 17 |
+
# Mirrors WinBase.h (unfortunately not defined already elsewhere)
|
| 18 |
+
WINBASE_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100
|
| 19 |
+
WINBASE_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000
|
| 20 |
+
|
| 21 |
+
POINTER_ADDRESS_SPACE = 2 ** (struct.calcsize("P") * 8)
|
| 22 |
+
|
| 23 |
+
# Set up kernel32 functions with proper types
|
| 24 |
+
kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined]
|
| 25 |
+
|
| 26 |
+
# GetModuleHandleW
|
| 27 |
+
kernel32.GetModuleHandleW.argtypes = [ctypes.wintypes.LPCWSTR]
|
| 28 |
+
kernel32.GetModuleHandleW.restype = ctypes.wintypes.HMODULE
|
| 29 |
+
|
| 30 |
+
# LoadLibraryExW
|
| 31 |
+
kernel32.LoadLibraryExW.argtypes = [
|
| 32 |
+
ctypes.wintypes.LPCWSTR, # lpLibFileName
|
| 33 |
+
ctypes.wintypes.HANDLE, # hFile (reserved, must be NULL)
|
| 34 |
+
ctypes.wintypes.DWORD, # dwFlags
|
| 35 |
+
]
|
| 36 |
+
kernel32.LoadLibraryExW.restype = ctypes.wintypes.HMODULE
|
| 37 |
+
|
| 38 |
+
# GetModuleFileNameW
|
| 39 |
+
kernel32.GetModuleFileNameW.argtypes = [
|
| 40 |
+
ctypes.wintypes.HMODULE, # hModule
|
| 41 |
+
ctypes.wintypes.LPWSTR, # lpFilename
|
| 42 |
+
ctypes.wintypes.DWORD, # nSize
|
| 43 |
+
]
|
| 44 |
+
kernel32.GetModuleFileNameW.restype = ctypes.wintypes.DWORD
|
| 45 |
+
|
| 46 |
+
# AddDllDirectory (Windows 7+)
|
| 47 |
+
kernel32.AddDllDirectory.argtypes = [ctypes.wintypes.LPCWSTR]
|
| 48 |
+
kernel32.AddDllDirectory.restype = ctypes.c_void_p # DLL_DIRECTORY_COOKIE
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def ctypes_handle_to_unsigned_int(handle: ctypes.wintypes.HMODULE) -> int:
|
| 52 |
+
"""Convert ctypes HMODULE to unsigned int."""
|
| 53 |
+
handle_uint = int(handle)
|
| 54 |
+
if handle_uint < 0:
|
| 55 |
+
# Convert from signed to unsigned representation
|
| 56 |
+
handle_uint += POINTER_ADDRESS_SPACE
|
| 57 |
+
return handle_uint
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def add_dll_directory(dll_abs_path: str) -> None:
|
| 61 |
+
"""Add a DLL directory to the search path and update PATH environment variable.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
dll_abs_path: Absolute path to the DLL file
|
| 65 |
+
|
| 66 |
+
Raises:
|
| 67 |
+
AssertionError: If the directory containing the DLL does not exist
|
| 68 |
+
"""
|
| 69 |
+
dirpath = os.path.dirname(dll_abs_path)
|
| 70 |
+
assert os.path.isdir(dirpath), dll_abs_path
|
| 71 |
+
|
| 72 |
+
# Add the DLL directory to the search path
|
| 73 |
+
result = kernel32.AddDllDirectory(dirpath)
|
| 74 |
+
if not result:
|
| 75 |
+
# Fallback: just update PATH if AddDllDirectory fails
|
| 76 |
+
pass
|
| 77 |
+
|
| 78 |
+
# Update PATH as a fallback for dependent DLL resolution
|
| 79 |
+
curr_path = os.environ.get("PATH")
|
| 80 |
+
os.environ["PATH"] = dirpath if curr_path is None else os.pathsep.join((curr_path, dirpath))
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def abs_path_for_dynamic_library(libname: str, handle: ctypes.wintypes.HMODULE) -> str:
|
| 84 |
+
"""Get the absolute path of a loaded dynamic library on Windows."""
|
| 85 |
+
# Create buffer for the path
|
| 86 |
+
buffer = ctypes.create_unicode_buffer(260) # MAX_PATH
|
| 87 |
+
length = kernel32.GetModuleFileNameW(handle, buffer, len(buffer))
|
| 88 |
+
|
| 89 |
+
if length == 0:
|
| 90 |
+
error_code = ctypes.GetLastError() # type: ignore[attr-defined]
|
| 91 |
+
raise RuntimeError(f"GetModuleFileNameW failed for {libname!r} (error code: {error_code})")
|
| 92 |
+
|
| 93 |
+
# If buffer was too small, try with larger buffer
|
| 94 |
+
if length == len(buffer):
|
| 95 |
+
buffer = ctypes.create_unicode_buffer(32768) # Extended path length
|
| 96 |
+
length = kernel32.GetModuleFileNameW(handle, buffer, len(buffer))
|
| 97 |
+
if length == 0:
|
| 98 |
+
error_code = ctypes.GetLastError() # type: ignore[attr-defined]
|
| 99 |
+
raise RuntimeError(f"GetModuleFileNameW failed for {libname!r} (error code: {error_code})")
|
| 100 |
+
|
| 101 |
+
return buffer.value
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def check_if_already_loaded_from_elsewhere(desc: LibDescriptor, have_abs_path: bool) -> LoadedDL | None:
|
| 105 |
+
for dll_name in desc.windows_dlls:
|
| 106 |
+
handle = kernel32.GetModuleHandleW(dll_name)
|
| 107 |
+
if handle:
|
| 108 |
+
abs_path = abs_path_for_dynamic_library(desc.name, handle)
|
| 109 |
+
if have_abs_path and desc.requires_add_dll_directory:
|
| 110 |
+
# This is a side-effect if the pathfinder loads the library via
|
| 111 |
+
# load_with_abs_path(). To make the side-effect more deterministic,
|
| 112 |
+
# activate it even if the library was already loaded from elsewhere.
|
| 113 |
+
add_dll_directory(abs_path)
|
| 114 |
+
return LoadedDL(abs_path, True, ctypes_handle_to_unsigned_int(handle), "was-already-loaded-from-elsewhere")
|
| 115 |
+
return None
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def load_with_system_search(desc: LibDescriptor) -> LoadedDL | None:
|
| 119 |
+
"""Try to load a DLL using the native Windows process DLL search path.
|
| 120 |
+
|
| 121 |
+
This calls ``LoadLibraryExW(dll_name, NULL, 0)`` directly. Under Python
|
| 122 |
+
3.8+, CPython configures the process with
|
| 123 |
+
``SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)``, so this
|
| 124 |
+
search does **not** include the system ``PATH``. Directories added via
|
| 125 |
+
``AddDllDirectory()`` still participate.
|
| 126 |
+
|
| 127 |
+
Args:
|
| 128 |
+
desc: Descriptor for the library to load
|
| 129 |
+
|
| 130 |
+
Returns:
|
| 131 |
+
A LoadedDL object if successful, None if the library cannot be loaded
|
| 132 |
+
"""
|
| 133 |
+
# Reverse tabulated names to achieve new -> old search order.
|
| 134 |
+
for dll_name in reversed(desc.windows_dlls):
|
| 135 |
+
handle = kernel32.LoadLibraryExW(dll_name, None, 0)
|
| 136 |
+
if handle:
|
| 137 |
+
abs_path = abs_path_for_dynamic_library(desc.name, handle)
|
| 138 |
+
return LoadedDL(abs_path, False, ctypes_handle_to_unsigned_int(handle), "system-search")
|
| 139 |
+
|
| 140 |
+
return None
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL:
|
| 144 |
+
"""Load a dynamic library from the given path.
|
| 145 |
+
|
| 146 |
+
Args:
|
| 147 |
+
desc: Descriptor for the library to load.
|
| 148 |
+
found_path: The absolute path to the DLL file.
|
| 149 |
+
found_via: Label indicating how the path was discovered.
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
A LoadedDL object representing the loaded library.
|
| 153 |
+
|
| 154 |
+
Raises:
|
| 155 |
+
RuntimeError: If the DLL cannot be loaded.
|
| 156 |
+
"""
|
| 157 |
+
if desc.requires_add_dll_directory:
|
| 158 |
+
add_dll_directory(found_path)
|
| 159 |
+
|
| 160 |
+
flags = WINBASE_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | WINBASE_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
|
| 161 |
+
handle = kernel32.LoadLibraryExW(found_path, None, flags)
|
| 162 |
+
|
| 163 |
+
if not handle:
|
| 164 |
+
error_code = ctypes.GetLastError() # type: ignore[attr-defined]
|
| 165 |
+
raise RuntimeError(f"Failed to load DLL at {found_path}: Windows error {error_code}")
|
| 166 |
+
|
| 167 |
+
return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle), found_via)
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import functools
|
| 7 |
+
import struct
|
| 8 |
+
import subprocess
|
| 9 |
+
import sys
|
| 10 |
+
from typing import TYPE_CHECKING
|
| 11 |
+
|
| 12 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS
|
| 13 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import (
|
| 14 |
+
DynamicLibNotAvailableError,
|
| 15 |
+
DynamicLibNotFoundError,
|
| 16 |
+
DynamicLibUnknownError,
|
| 17 |
+
LoadedDL,
|
| 18 |
+
load_dependencies,
|
| 19 |
+
)
|
| 20 |
+
from cuda.pathfinder._dynamic_libs.platform_loader import LOADER
|
| 21 |
+
from cuda.pathfinder._dynamic_libs.search_steps import (
|
| 22 |
+
EARLY_FIND_STEPS,
|
| 23 |
+
LATE_FIND_STEPS,
|
| 24 |
+
SearchContext,
|
| 25 |
+
derive_ctk_root,
|
| 26 |
+
find_via_ctk_root,
|
| 27 |
+
run_find_steps,
|
| 28 |
+
)
|
| 29 |
+
from cuda.pathfinder._dynamic_libs.subprocess_protocol import (
|
| 30 |
+
DYNAMIC_LIB_SUBPROCESS_CWD,
|
| 31 |
+
MODE_CANARY,
|
| 32 |
+
STATUS_OK,
|
| 33 |
+
DynamicLibSubprocessPayload,
|
| 34 |
+
build_dynamic_lib_subprocess_command,
|
| 35 |
+
parse_dynamic_lib_subprocess_payload,
|
| 36 |
+
)
|
| 37 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 38 |
+
|
| 39 |
+
if TYPE_CHECKING:
|
| 40 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 41 |
+
|
| 42 |
+
# All libnames recognized by load_nvidia_dynamic_lib, across all categories
|
| 43 |
+
# (CTK, third-party, driver).
|
| 44 |
+
_ALL_KNOWN_LIBNAMES: frozenset[str] = frozenset(LIB_DESCRIPTORS)
|
| 45 |
+
_ALL_SUPPORTED_LIBNAMES: frozenset[str] = frozenset(
|
| 46 |
+
name for name, desc in LIB_DESCRIPTORS.items() if (desc.windows_dlls if IS_WINDOWS else desc.linux_sonames)
|
| 47 |
+
)
|
| 48 |
+
_PLATFORM_NAME = "Windows" if IS_WINDOWS else "Linux"
|
| 49 |
+
_CANARY_PROBE_TIMEOUT_SECONDS = 10.0
|
| 50 |
+
|
| 51 |
+
# Driver libraries: shipped with the NVIDIA display driver, always on the
|
| 52 |
+
# system linker path. These skip all CTK search steps (site-packages,
|
| 53 |
+
# conda, CUDA_PATH, canary) and go straight to system search.
|
| 54 |
+
_DRIVER_ONLY_LIBNAMES = frozenset(name for name, desc in LIB_DESCRIPTORS.items() if desc.packaged_with == "driver")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _load_driver_lib_no_cache(desc: LibDescriptor) -> LoadedDL:
|
| 58 |
+
"""Load an NVIDIA driver library (system-search only).
|
| 59 |
+
|
| 60 |
+
Driver libs (libcuda, libnvidia-ml) are part of the display driver, not
|
| 61 |
+
the CUDA Toolkit. They are expected to be discoverable via the platform's
|
| 62 |
+
native loader mechanisms, so the full CTK search cascade (site-packages,
|
| 63 |
+
conda, CUDA_PATH, canary) is unnecessary.
|
| 64 |
+
"""
|
| 65 |
+
loaded = LOADER.check_if_already_loaded_from_elsewhere(desc, False)
|
| 66 |
+
if loaded is not None:
|
| 67 |
+
return loaded
|
| 68 |
+
loaded = LOADER.load_with_system_search(desc)
|
| 69 |
+
if loaded is not None:
|
| 70 |
+
return loaded
|
| 71 |
+
raise DynamicLibNotFoundError(
|
| 72 |
+
f'"{desc.name}" is an NVIDIA driver library and can only be found via'
|
| 73 |
+
f" system search. Ensure the NVIDIA display driver is installed."
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _coerce_subprocess_output(output: str | bytes | None) -> str:
|
| 78 |
+
if isinstance(output, bytes):
|
| 79 |
+
return output.decode(errors="replace")
|
| 80 |
+
return "" if output is None else output
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _raise_canary_probe_child_process_error(
|
| 84 |
+
*,
|
| 85 |
+
returncode: int | None = None,
|
| 86 |
+
timeout: float | None = None,
|
| 87 |
+
stderr: str | bytes | None = None,
|
| 88 |
+
) -> None:
|
| 89 |
+
if timeout is None:
|
| 90 |
+
error_line = f"Canary probe child process exited with code {returncode}."
|
| 91 |
+
else:
|
| 92 |
+
error_line = f"Canary probe child process timed out after {timeout} seconds."
|
| 93 |
+
raise ChildProcessError(
|
| 94 |
+
f"{error_line}\n"
|
| 95 |
+
"--- stderr-from-child-process ---\n"
|
| 96 |
+
f"{_coerce_subprocess_output(stderr)}"
|
| 97 |
+
"<end-of-stderr-from-child-process>\n"
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@functools.cache
|
| 102 |
+
def _resolve_system_loaded_abs_path_in_subprocess(
|
| 103 |
+
libname: str,
|
| 104 |
+
*,
|
| 105 |
+
timeout: float = _CANARY_PROBE_TIMEOUT_SECONDS,
|
| 106 |
+
) -> str | None:
|
| 107 |
+
"""Resolve a canary library's absolute path in a fresh Python subprocess."""
|
| 108 |
+
try:
|
| 109 |
+
result = subprocess.run( # noqa: S603 - trusted argv: current interpreter + internal probe module
|
| 110 |
+
build_dynamic_lib_subprocess_command(MODE_CANARY, libname),
|
| 111 |
+
capture_output=True,
|
| 112 |
+
text=True,
|
| 113 |
+
timeout=timeout,
|
| 114 |
+
check=False,
|
| 115 |
+
cwd=DYNAMIC_LIB_SUBPROCESS_CWD,
|
| 116 |
+
)
|
| 117 |
+
except subprocess.TimeoutExpired as exc:
|
| 118 |
+
_raise_canary_probe_child_process_error(timeout=exc.timeout, stderr=exc.stderr)
|
| 119 |
+
|
| 120 |
+
if result.returncode != 0:
|
| 121 |
+
_raise_canary_probe_child_process_error(returncode=result.returncode, stderr=result.stderr)
|
| 122 |
+
|
| 123 |
+
payload: DynamicLibSubprocessPayload = parse_dynamic_lib_subprocess_payload(
|
| 124 |
+
result.stdout,
|
| 125 |
+
libname=libname,
|
| 126 |
+
error_label="Canary probe child process",
|
| 127 |
+
)
|
| 128 |
+
abs_path: str | None = payload.abs_path
|
| 129 |
+
if payload.status == STATUS_OK:
|
| 130 |
+
return abs_path
|
| 131 |
+
return None
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _loadable_via_canary_subprocess(libname: str, *, timeout: float = _CANARY_PROBE_TIMEOUT_SECONDS) -> bool:
|
| 135 |
+
"""Return True if the canary subprocess can resolve ``libname`` via system search."""
|
| 136 |
+
return _resolve_system_loaded_abs_path_in_subprocess(libname, timeout=timeout) is not None
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _try_ctk_root_canary(ctx: SearchContext) -> str | None:
|
| 140 |
+
"""Try CTK-root canary fallback for descriptor-configured libraries."""
|
| 141 |
+
for canary_libname in ctx.desc.ctk_root_canary_anchor_libnames:
|
| 142 |
+
canary_abs_path = _resolve_system_loaded_abs_path_in_subprocess(canary_libname)
|
| 143 |
+
if canary_abs_path is None:
|
| 144 |
+
continue
|
| 145 |
+
ctk_root = derive_ctk_root(canary_abs_path)
|
| 146 |
+
if ctk_root is None:
|
| 147 |
+
continue
|
| 148 |
+
find = find_via_ctk_root(ctx, ctk_root)
|
| 149 |
+
if find is not None:
|
| 150 |
+
return str(find.abs_path)
|
| 151 |
+
return None
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def _load_lib_no_cache(libname: str) -> LoadedDL:
|
| 155 |
+
desc = LIB_DESCRIPTORS[libname]
|
| 156 |
+
|
| 157 |
+
if libname in _DRIVER_ONLY_LIBNAMES:
|
| 158 |
+
return _load_driver_lib_no_cache(desc)
|
| 159 |
+
|
| 160 |
+
ctx = SearchContext(desc)
|
| 161 |
+
|
| 162 |
+
# Phase 1: Try to find the library file on disk (pip wheels, conda).
|
| 163 |
+
find = run_find_steps(ctx, EARLY_FIND_STEPS)
|
| 164 |
+
|
| 165 |
+
# Phase 2: Cross-cutting — already-loaded check and dependency loading.
|
| 166 |
+
# The already-loaded check on Windows uses the "have we found a path?"
|
| 167 |
+
# flag to decide whether to apply AddDllDirectory side-effects.
|
| 168 |
+
loaded = LOADER.check_if_already_loaded_from_elsewhere(desc, find is not None)
|
| 169 |
+
load_dependencies(desc, load_nvidia_dynamic_lib)
|
| 170 |
+
if loaded is not None:
|
| 171 |
+
return loaded
|
| 172 |
+
|
| 173 |
+
# Phase 3: Load from found path, or fall back to system search + late find.
|
| 174 |
+
if find is not None:
|
| 175 |
+
return LOADER.load_with_abs_path(desc, find.abs_path, find.found_via)
|
| 176 |
+
|
| 177 |
+
loaded = LOADER.load_with_system_search(desc)
|
| 178 |
+
if loaded is not None:
|
| 179 |
+
return loaded
|
| 180 |
+
|
| 181 |
+
find = run_find_steps(ctx, LATE_FIND_STEPS)
|
| 182 |
+
if find is not None:
|
| 183 |
+
return LOADER.load_with_abs_path(desc, find.abs_path, find.found_via)
|
| 184 |
+
|
| 185 |
+
if desc.ctk_root_canary_anchor_libnames:
|
| 186 |
+
canary_abs_path = _try_ctk_root_canary(ctx)
|
| 187 |
+
if canary_abs_path is not None:
|
| 188 |
+
return LOADER.load_with_abs_path(desc, canary_abs_path, "system-ctk-root")
|
| 189 |
+
|
| 190 |
+
ctx.raise_not_found()
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
@functools.cache
|
| 194 |
+
def load_nvidia_dynamic_lib(libname: str) -> LoadedDL:
|
| 195 |
+
"""Load an NVIDIA dynamic library by name.
|
| 196 |
+
|
| 197 |
+
Args:
|
| 198 |
+
libname (str): The short name of the library to load (e.g., ``"cudart"``,
|
| 199 |
+
``"nvvm"``, etc.).
|
| 200 |
+
|
| 201 |
+
Returns:
|
| 202 |
+
LoadedDL: Object containing the OS library handle and absolute path.
|
| 203 |
+
|
| 204 |
+
**Important:**
|
| 205 |
+
|
| 206 |
+
**Never close the returned handle.** Do **not** call ``dlclose`` (Linux) or
|
| 207 |
+
``FreeLibrary`` (Windows) on the ``LoadedDL._handle_uint``.
|
| 208 |
+
|
| 209 |
+
**Why:** the return value is cached (``functools.cache``) and shared across the
|
| 210 |
+
process. Closing the handle can unload the module while other code still uses
|
| 211 |
+
it, leading to crashes or subtle failures.
|
| 212 |
+
|
| 213 |
+
This applies to Linux and Windows. For context, see issue #1011:
|
| 214 |
+
https://github.com/NVIDIA/cuda-python/issues/1011
|
| 215 |
+
|
| 216 |
+
Raises:
|
| 217 |
+
DynamicLibUnknownError: If ``libname`` is not a recognized library name.
|
| 218 |
+
DynamicLibNotAvailableError: If ``libname`` is recognized but not
|
| 219 |
+
supported on this platform.
|
| 220 |
+
DynamicLibNotFoundError: If the library cannot be found or loaded.
|
| 221 |
+
RuntimeError: If Python is not 64-bit.
|
| 222 |
+
|
| 223 |
+
Search order:
|
| 224 |
+
0. **Already loaded in the current process**
|
| 225 |
+
|
| 226 |
+
- If a matching library is already loaded by some other component,
|
| 227 |
+
return its absolute path and handle and skip the rest of the search.
|
| 228 |
+
|
| 229 |
+
1. **NVIDIA Python wheels**
|
| 230 |
+
|
| 231 |
+
- Scan installed distributions (``site-packages``) to find libraries
|
| 232 |
+
shipped in NVIDIA wheels.
|
| 233 |
+
|
| 234 |
+
2. **Conda environment**
|
| 235 |
+
|
| 236 |
+
- Conda installations are discovered via ``CONDA_PREFIX``, which is
|
| 237 |
+
defined automatically in activated conda environments (see
|
| 238 |
+
https://docs.conda.io/projects/conda-build/en/stable/user-guide/environment-variables.html).
|
| 239 |
+
|
| 240 |
+
3. **OS default mechanisms**
|
| 241 |
+
|
| 242 |
+
- Fall back to the native loader:
|
| 243 |
+
|
| 244 |
+
- Linux: ``dlopen()``
|
| 245 |
+
|
| 246 |
+
- Windows: ``LoadLibraryExW()``
|
| 247 |
+
|
| 248 |
+
On Linux, CUDA Toolkit (CTK) system installs with system config updates are
|
| 249 |
+
usually discovered via ``/etc/ld.so.conf.d/*cuda*.conf``.
|
| 250 |
+
|
| 251 |
+
On Windows, under Python 3.8+, CPython configures the process with
|
| 252 |
+
``SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)``.
|
| 253 |
+
As a result, the native DLL search used here does **not** include
|
| 254 |
+
the system ``PATH``.
|
| 255 |
+
|
| 256 |
+
4. **Environment variables**
|
| 257 |
+
|
| 258 |
+
- If set, use ``CUDA_PATH`` or ``CUDA_HOME`` (in that order).
|
| 259 |
+
On Windows, this is the typical way system-installed CTK DLLs are
|
| 260 |
+
located. Note that the NVIDIA CTK installer automatically
|
| 261 |
+
adds ``CUDA_PATH`` to the system-wide environment.
|
| 262 |
+
|
| 263 |
+
5. **CTK root canary probe (discoverable libs only)**
|
| 264 |
+
|
| 265 |
+
- For selected libraries whose shared object doesn't reside on the
|
| 266 |
+
standard linker path (currently ``nvvm``), attempt to derive CTK
|
| 267 |
+
root by system-loading a well-known CTK canary library in a
|
| 268 |
+
subprocess and then searching relative to that root. On Windows,
|
| 269 |
+
the canary uses the same native ``LoadLibraryExW`` semantics as
|
| 270 |
+
step 3, so there is also no ``PATH``-based discovery.
|
| 271 |
+
|
| 272 |
+
**Driver libraries** (``"cuda"``, ``"nvml"``):
|
| 273 |
+
|
| 274 |
+
These are part of the NVIDIA display driver (not the CUDA Toolkit) and
|
| 275 |
+
are expected to be reachable via the native OS loader path. For these
|
| 276 |
+
libraries the search is simplified to:
|
| 277 |
+
|
| 278 |
+
0. Already loaded in the current process
|
| 279 |
+
1. OS default mechanisms (``dlopen`` / ``LoadLibraryExW``)
|
| 280 |
+
|
| 281 |
+
The CTK-specific steps (site-packages, conda, ``CUDA_PATH``, canary
|
| 282 |
+
probe) are skipped entirely.
|
| 283 |
+
|
| 284 |
+
Notes:
|
| 285 |
+
The search is performed **per library**. There is currently no mechanism to
|
| 286 |
+
guarantee that multiple libraries are all resolved from the same location.
|
| 287 |
+
|
| 288 |
+
"""
|
| 289 |
+
pointer_size_bits = struct.calcsize("P") * 8
|
| 290 |
+
if pointer_size_bits != 64:
|
| 291 |
+
raise RuntimeError(
|
| 292 |
+
f"cuda.pathfinder.load_nvidia_dynamic_lib() requires 64-bit Python."
|
| 293 |
+
f" Currently running: {pointer_size_bits}-bit Python"
|
| 294 |
+
f" {sys.version_info.major}.{sys.version_info.minor}"
|
| 295 |
+
)
|
| 296 |
+
if libname not in _ALL_KNOWN_LIBNAMES:
|
| 297 |
+
raise DynamicLibUnknownError(f"Unknown library name: {libname!r}. Known names: {sorted(_ALL_KNOWN_LIBNAMES)}")
|
| 298 |
+
if libname not in _ALL_SUPPORTED_LIBNAMES:
|
| 299 |
+
raise DynamicLibNotAvailableError(
|
| 300 |
+
f"Library name {libname!r} is known but not available on {_PLATFORM_NAME}. "
|
| 301 |
+
f"Supported names on {_PLATFORM_NAME}: {sorted(_ALL_SUPPORTED_LIBNAMES)}"
|
| 302 |
+
)
|
| 303 |
+
return _load_lib_no_cache(libname)
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/platform_loader.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Platform loader seam for OS-specific dynamic linking.
|
| 5 |
+
|
| 6 |
+
This module provides a small interface that hides the Linux vs Windows
|
| 7 |
+
implementation details of:
|
| 8 |
+
|
| 9 |
+
- already-loaded checks
|
| 10 |
+
- system-search loading
|
| 11 |
+
- absolute-path loading
|
| 12 |
+
|
| 13 |
+
The orchestration logic in :mod:`load_nvidia_dynamic_lib` should not need to
|
| 14 |
+
branch on platform; it calls through the loader instance exported here.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
from typing import Protocol
|
| 20 |
+
|
| 21 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 22 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL
|
| 23 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class PlatformLoader(Protocol):
|
| 27 |
+
def check_if_already_loaded_from_elsewhere(self, desc: LibDescriptor, have_abs_path: bool) -> LoadedDL | None: ...
|
| 28 |
+
|
| 29 |
+
def load_with_system_search(self, desc: LibDescriptor) -> LoadedDL | None: ...
|
| 30 |
+
|
| 31 |
+
def load_with_abs_path(self, desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL: ...
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if IS_WINDOWS:
|
| 35 |
+
from cuda.pathfinder._dynamic_libs import load_dl_windows as _impl
|
| 36 |
+
else:
|
| 37 |
+
from cuda.pathfinder._dynamic_libs import load_dl_linux as _impl
|
| 38 |
+
|
| 39 |
+
# The platform modules already expose functions matching the PlatformLoader
|
| 40 |
+
# protocol. Wrap in a simple namespace so callers use LOADER.method() syntax.
|
| 41 |
+
LOADER: PlatformLoader = _impl
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/search_platform.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Platform abstraction for filesystem search steps.
|
| 5 |
+
|
| 6 |
+
The goal is to keep :mod:`search_steps` platform-agnostic: it should not branch
|
| 7 |
+
on OS flags like ``IS_WINDOWS``. Instead, it calls through the single
|
| 8 |
+
``PLATFORM`` instance exported here.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import glob
|
| 14 |
+
import os
|
| 15 |
+
from collections.abc import Sequence
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from typing import Protocol, cast
|
| 18 |
+
|
| 19 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 20 |
+
from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import is_suppressed_dll_file
|
| 21 |
+
from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages
|
| 22 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _no_such_file_in_sub_dirs(
|
| 26 |
+
sub_dirs: Sequence[str], file_wild: str, error_messages: list[str], attachments: list[str]
|
| 27 |
+
) -> None:
|
| 28 |
+
error_messages.append(f"No such file: {file_wild}")
|
| 29 |
+
for sub_dir in find_sub_dirs_all_sitepackages(sub_dirs):
|
| 30 |
+
attachments.append(f' listdir("{sub_dir}"):')
|
| 31 |
+
for node in sorted(os.listdir(sub_dir)):
|
| 32 |
+
attachments.append(f" {node}")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _find_so_in_rel_dirs(
|
| 36 |
+
rel_dirs: tuple[str, ...],
|
| 37 |
+
so_basename: str,
|
| 38 |
+
error_messages: list[str],
|
| 39 |
+
attachments: list[str],
|
| 40 |
+
) -> str | None:
|
| 41 |
+
sub_dirs_searched: list[tuple[str, ...]] = []
|
| 42 |
+
file_wild = so_basename + "*"
|
| 43 |
+
for rel_dir in rel_dirs:
|
| 44 |
+
sub_dir = tuple(rel_dir.split(os.path.sep))
|
| 45 |
+
for abs_dir in find_sub_dirs_all_sitepackages(sub_dir):
|
| 46 |
+
# Exact unversioned match first; fall back to versioned names because some
|
| 47 |
+
# distros only ship lib<name>.so.<major> (e.g. conda libcupti). Only one match
|
| 48 |
+
# is expected in practice. Sort in reverse so the newest-sorting name wins if
|
| 49 |
+
# multiple coexist, matching the newest-first bias elsewhere in pathfinder
|
| 50 |
+
# (see LinuxSearchPlatform.find_in_lib_dir and load_dl_linux._candidate_sonames).
|
| 51 |
+
# Issue #1732 tracks the deferred question of raising on true ambiguity.
|
| 52 |
+
so_name = os.path.join(abs_dir, so_basename)
|
| 53 |
+
if os.path.isfile(so_name):
|
| 54 |
+
return so_name
|
| 55 |
+
for so_name in sorted(glob.glob(os.path.join(abs_dir, file_wild)), reverse=True):
|
| 56 |
+
if os.path.isfile(so_name):
|
| 57 |
+
return so_name
|
| 58 |
+
sub_dirs_searched.append(sub_dir)
|
| 59 |
+
for sub_dir in sub_dirs_searched:
|
| 60 |
+
_no_such_file_in_sub_dirs(sub_dir, file_wild, error_messages, attachments)
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _find_dll_under_dir(dirpath: str, file_wild: str) -> str | None:
|
| 65 |
+
for path in sorted(glob.glob(os.path.join(dirpath, file_wild))):
|
| 66 |
+
if not os.path.isfile(path):
|
| 67 |
+
continue
|
| 68 |
+
if not is_suppressed_dll_file(os.path.basename(path)):
|
| 69 |
+
return path
|
| 70 |
+
return None
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _find_dll_in_rel_dirs(
|
| 74 |
+
rel_dirs: tuple[str, ...],
|
| 75 |
+
lib_searched_for: str,
|
| 76 |
+
error_messages: list[str],
|
| 77 |
+
attachments: list[str],
|
| 78 |
+
) -> str | None:
|
| 79 |
+
sub_dirs_searched: list[tuple[str, ...]] = []
|
| 80 |
+
for rel_dir in rel_dirs:
|
| 81 |
+
sub_dir = tuple(rel_dir.split(os.path.sep))
|
| 82 |
+
for abs_dir in find_sub_dirs_all_sitepackages(sub_dir):
|
| 83 |
+
dll_name = _find_dll_under_dir(abs_dir, lib_searched_for)
|
| 84 |
+
if dll_name is not None:
|
| 85 |
+
return dll_name
|
| 86 |
+
sub_dirs_searched.append(sub_dir)
|
| 87 |
+
for sub_dir in sub_dirs_searched:
|
| 88 |
+
_no_such_file_in_sub_dirs(sub_dir, lib_searched_for, error_messages, attachments)
|
| 89 |
+
return None
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class SearchPlatform(Protocol):
|
| 93 |
+
def lib_searched_for(self, libname: str) -> str: ...
|
| 94 |
+
|
| 95 |
+
def site_packages_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]: ...
|
| 96 |
+
|
| 97 |
+
def conda_anchor_point(self, conda_prefix: str) -> str: ...
|
| 98 |
+
|
| 99 |
+
def anchor_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]: ...
|
| 100 |
+
|
| 101 |
+
def find_in_site_packages(
|
| 102 |
+
self,
|
| 103 |
+
rel_dirs: tuple[str, ...],
|
| 104 |
+
lib_searched_for: str,
|
| 105 |
+
error_messages: list[str],
|
| 106 |
+
attachments: list[str],
|
| 107 |
+
) -> str | None: ...
|
| 108 |
+
|
| 109 |
+
def find_in_lib_dir(
|
| 110 |
+
self,
|
| 111 |
+
lib_dir: str,
|
| 112 |
+
libname: str,
|
| 113 |
+
lib_searched_for: str,
|
| 114 |
+
error_messages: list[str],
|
| 115 |
+
attachments: list[str],
|
| 116 |
+
) -> str | None: ...
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
@dataclass(frozen=True, slots=True)
|
| 120 |
+
class LinuxSearchPlatform:
|
| 121 |
+
def lib_searched_for(self, libname: str) -> str:
|
| 122 |
+
return f"lib{libname}.so"
|
| 123 |
+
|
| 124 |
+
def site_packages_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]:
|
| 125 |
+
return cast(tuple[str, ...], desc.site_packages_linux)
|
| 126 |
+
|
| 127 |
+
def conda_anchor_point(self, conda_prefix: str) -> str:
|
| 128 |
+
return conda_prefix
|
| 129 |
+
|
| 130 |
+
def anchor_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]:
|
| 131 |
+
return cast(tuple[str, ...], desc.anchor_rel_dirs_linux)
|
| 132 |
+
|
| 133 |
+
def find_in_site_packages(
|
| 134 |
+
self,
|
| 135 |
+
rel_dirs: tuple[str, ...],
|
| 136 |
+
lib_searched_for: str,
|
| 137 |
+
error_messages: list[str],
|
| 138 |
+
attachments: list[str],
|
| 139 |
+
) -> str | None:
|
| 140 |
+
return _find_so_in_rel_dirs(rel_dirs, lib_searched_for, error_messages, attachments)
|
| 141 |
+
|
| 142 |
+
def find_in_lib_dir(
|
| 143 |
+
self,
|
| 144 |
+
lib_dir: str,
|
| 145 |
+
_libname: str,
|
| 146 |
+
lib_searched_for: str,
|
| 147 |
+
error_messages: list[str],
|
| 148 |
+
attachments: list[str],
|
| 149 |
+
) -> str | None:
|
| 150 |
+
# Most libraries have both unversioned and versioned files/symlinks (exact match first)
|
| 151 |
+
so_name = os.path.join(lib_dir, lib_searched_for)
|
| 152 |
+
if os.path.isfile(so_name):
|
| 153 |
+
return so_name
|
| 154 |
+
# Some libraries only exist as versioned files (e.g., libcupti.so.13 in conda),
|
| 155 |
+
# so the glob fallback is needed
|
| 156 |
+
file_wild = lib_searched_for + "*"
|
| 157 |
+
# Only one match is expected, but to ensure deterministic behavior in unexpected
|
| 158 |
+
# situations, and to be internally consistent, we sort in reverse order with the
|
| 159 |
+
# intent to return the newest version first. Issue #1732 tracks the deferred
|
| 160 |
+
# question of raising on true ambiguity.
|
| 161 |
+
for so_name in sorted(glob.glob(os.path.join(lib_dir, file_wild)), reverse=True):
|
| 162 |
+
if os.path.isfile(so_name):
|
| 163 |
+
return so_name
|
| 164 |
+
error_messages.append(f"No such file: {file_wild}")
|
| 165 |
+
attachments.append(f' listdir("{lib_dir}"):')
|
| 166 |
+
if not os.path.isdir(lib_dir):
|
| 167 |
+
attachments.append(" DIRECTORY DOES NOT EXIST")
|
| 168 |
+
else:
|
| 169 |
+
for node in sorted(os.listdir(lib_dir)):
|
| 170 |
+
attachments.append(f" {node}")
|
| 171 |
+
return None
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
@dataclass(frozen=True, slots=True)
|
| 175 |
+
class WindowsSearchPlatform:
|
| 176 |
+
def lib_searched_for(self, libname: str) -> str:
|
| 177 |
+
return f"{libname}*.dll"
|
| 178 |
+
|
| 179 |
+
def site_packages_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]:
|
| 180 |
+
return cast(tuple[str, ...], desc.site_packages_windows)
|
| 181 |
+
|
| 182 |
+
def conda_anchor_point(self, conda_prefix: str) -> str:
|
| 183 |
+
return os.path.join(conda_prefix, "Library")
|
| 184 |
+
|
| 185 |
+
def anchor_rel_dirs(self, desc: LibDescriptor) -> tuple[str, ...]:
|
| 186 |
+
return cast(tuple[str, ...], desc.anchor_rel_dirs_windows)
|
| 187 |
+
|
| 188 |
+
def find_in_site_packages(
|
| 189 |
+
self,
|
| 190 |
+
rel_dirs: tuple[str, ...],
|
| 191 |
+
lib_searched_for: str,
|
| 192 |
+
error_messages: list[str],
|
| 193 |
+
attachments: list[str],
|
| 194 |
+
) -> str | None:
|
| 195 |
+
return _find_dll_in_rel_dirs(rel_dirs, lib_searched_for, error_messages, attachments)
|
| 196 |
+
|
| 197 |
+
def find_in_lib_dir(
|
| 198 |
+
self,
|
| 199 |
+
lib_dir: str,
|
| 200 |
+
libname: str,
|
| 201 |
+
_lib_searched_for: str,
|
| 202 |
+
error_messages: list[str],
|
| 203 |
+
attachments: list[str],
|
| 204 |
+
) -> str | None:
|
| 205 |
+
file_wild = libname + "*.dll"
|
| 206 |
+
dll_name = _find_dll_under_dir(lib_dir, file_wild)
|
| 207 |
+
if dll_name is not None:
|
| 208 |
+
return dll_name
|
| 209 |
+
error_messages.append(f"No such file: {file_wild}")
|
| 210 |
+
attachments.append(f' listdir("{lib_dir}"):')
|
| 211 |
+
if not os.path.isdir(lib_dir):
|
| 212 |
+
attachments.append(" DIRECTORY DOES NOT EXIST")
|
| 213 |
+
else:
|
| 214 |
+
for node in sorted(os.listdir(lib_dir)):
|
| 215 |
+
attachments.append(f" {node}")
|
| 216 |
+
return None
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
PLATFORM: SearchPlatform = WindowsSearchPlatform() if IS_WINDOWS else LinuxSearchPlatform()
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/search_steps.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Composable search steps for locating NVIDIA libraries.
|
| 5 |
+
|
| 6 |
+
Each find step is a callable with signature::
|
| 7 |
+
|
| 8 |
+
(SearchContext) -> FindResult | None
|
| 9 |
+
|
| 10 |
+
Find steps locate a library file on disk without loading it. The
|
| 11 |
+
orchestrator in :mod:`load_nvidia_dynamic_lib` handles loading, the
|
| 12 |
+
already-loaded check, and dependency resolution.
|
| 13 |
+
|
| 14 |
+
Step sequences are defined per search strategy so that adding a new
|
| 15 |
+
step or strategy only requires adding a function and a tuple entry.
|
| 16 |
+
|
| 17 |
+
This module is intentionally platform-agnostic: it does not branch on the
|
| 18 |
+
current operating system. Platform differences are routed through the
|
| 19 |
+
:data:`~cuda.pathfinder._dynamic_libs.search_platform.PLATFORM` instance.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
import glob
|
| 23 |
+
import os
|
| 24 |
+
from collections.abc import Callable
|
| 25 |
+
from dataclasses import dataclass, field
|
| 26 |
+
from typing import NoReturn, cast
|
| 27 |
+
|
| 28 |
+
from cuda.pathfinder._dynamic_libs.lib_descriptor import LibDescriptor
|
| 29 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError
|
| 30 |
+
from cuda.pathfinder._dynamic_libs.search_platform import PLATFORM, SearchPlatform
|
| 31 |
+
from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home
|
| 32 |
+
|
| 33 |
+
# ---------------------------------------------------------------------------
|
| 34 |
+
# Data types
|
| 35 |
+
# ---------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@dataclass
|
| 39 |
+
class FindResult:
|
| 40 |
+
"""A library file located on disk (not yet loaded)."""
|
| 41 |
+
|
| 42 |
+
abs_path: str
|
| 43 |
+
found_via: str
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@dataclass
|
| 47 |
+
class SearchContext:
|
| 48 |
+
"""Mutable state accumulated during the search cascade."""
|
| 49 |
+
|
| 50 |
+
desc: LibDescriptor
|
| 51 |
+
platform: SearchPlatform = PLATFORM
|
| 52 |
+
error_messages: list[str] = field(default_factory=list)
|
| 53 |
+
attachments: list[str] = field(default_factory=list)
|
| 54 |
+
|
| 55 |
+
@property
|
| 56 |
+
def libname(self) -> str:
|
| 57 |
+
return self.desc.name # type: ignore[no-any-return] # mypy can't resolve new sibling module
|
| 58 |
+
|
| 59 |
+
@property
|
| 60 |
+
def lib_searched_for(self) -> str:
|
| 61 |
+
return cast(str, self.platform.lib_searched_for(self.libname))
|
| 62 |
+
|
| 63 |
+
def raise_not_found(self) -> NoReturn:
|
| 64 |
+
err = ", ".join(self.error_messages)
|
| 65 |
+
att = "\n".join(self.attachments)
|
| 66 |
+
raise DynamicLibNotFoundError(f'Failure finding "{self.lib_searched_for}": {err}\n{att}')
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
#: Type alias for a find step callable.
|
| 70 |
+
FindStep = Callable[[SearchContext], FindResult | None]
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _find_lib_dir_using_anchor(desc: LibDescriptor, platform: SearchPlatform, anchor_point: str) -> str | None:
|
| 74 |
+
"""Find the library directory under *anchor_point* using the descriptor's relative paths."""
|
| 75 |
+
rel_dirs = platform.anchor_rel_dirs(desc)
|
| 76 |
+
for rel_path in rel_dirs:
|
| 77 |
+
for dirname in sorted(glob.glob(os.path.join(anchor_point, rel_path))):
|
| 78 |
+
if os.path.isdir(dirname):
|
| 79 |
+
return os.path.normpath(dirname)
|
| 80 |
+
return None
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _find_using_lib_dir(ctx: SearchContext, lib_dir: str | None) -> str | None:
|
| 84 |
+
"""Find a library file in a resolved lib directory."""
|
| 85 |
+
if lib_dir is None:
|
| 86 |
+
return None
|
| 87 |
+
return cast(
|
| 88 |
+
str | None,
|
| 89 |
+
ctx.platform.find_in_lib_dir(
|
| 90 |
+
lib_dir,
|
| 91 |
+
ctx.libname,
|
| 92 |
+
ctx.lib_searched_for,
|
| 93 |
+
ctx.error_messages,
|
| 94 |
+
ctx.attachments,
|
| 95 |
+
),
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _derive_ctk_root_linux(resolved_lib_path: str) -> str | None:
|
| 100 |
+
"""Derive CTK root from Linux canary path.
|
| 101 |
+
|
| 102 |
+
Supports:
|
| 103 |
+
- ``$CTK_ROOT/lib64/libfoo.so.*``
|
| 104 |
+
- ``$CTK_ROOT/lib/libfoo.so.*``
|
| 105 |
+
- ``$CTK_ROOT/targets/<triple>/lib64/libfoo.so.*``
|
| 106 |
+
- ``$CTK_ROOT/targets/<triple>/lib/libfoo.so.*``
|
| 107 |
+
"""
|
| 108 |
+
lib_dir = os.path.dirname(resolved_lib_path)
|
| 109 |
+
basename = os.path.basename(lib_dir)
|
| 110 |
+
if basename in ("lib64", "lib"):
|
| 111 |
+
parent = os.path.dirname(lib_dir)
|
| 112 |
+
grandparent = os.path.dirname(parent)
|
| 113 |
+
if os.path.basename(grandparent) == "targets":
|
| 114 |
+
return os.path.dirname(grandparent)
|
| 115 |
+
return parent
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def _derive_ctk_root_windows(resolved_lib_path: str) -> str | None:
|
| 120 |
+
"""Derive CTK root from Windows canary path.
|
| 121 |
+
|
| 122 |
+
Supports:
|
| 123 |
+
- ``$CTK_ROOT/bin/x64/foo.dll`` (CTK 13 style)
|
| 124 |
+
- ``$CTK_ROOT/bin/foo.dll`` (CTK 12 style)
|
| 125 |
+
"""
|
| 126 |
+
import ntpath
|
| 127 |
+
|
| 128 |
+
lib_dir = ntpath.dirname(resolved_lib_path)
|
| 129 |
+
basename = ntpath.basename(lib_dir).lower()
|
| 130 |
+
if basename == "x64":
|
| 131 |
+
parent = ntpath.dirname(lib_dir)
|
| 132 |
+
if ntpath.basename(parent).lower() == "bin":
|
| 133 |
+
return ntpath.dirname(parent)
|
| 134 |
+
elif basename == "bin":
|
| 135 |
+
return ntpath.dirname(lib_dir)
|
| 136 |
+
return None
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def derive_ctk_root(resolved_lib_path: str) -> str | None:
|
| 140 |
+
"""Derive CTK root from a resolved canary library path."""
|
| 141 |
+
ctk_root = _derive_ctk_root_linux(resolved_lib_path)
|
| 142 |
+
if ctk_root is not None:
|
| 143 |
+
return ctk_root
|
| 144 |
+
return _derive_ctk_root_windows(resolved_lib_path)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def find_via_ctk_root(ctx: SearchContext, ctk_root: str) -> FindResult | None:
|
| 148 |
+
"""Find a library under a previously derived CTK root."""
|
| 149 |
+
lib_dir = _find_lib_dir_using_anchor(ctx.desc, ctx.platform, ctk_root)
|
| 150 |
+
abs_path = _find_using_lib_dir(ctx, lib_dir)
|
| 151 |
+
if abs_path is None:
|
| 152 |
+
return None
|
| 153 |
+
return FindResult(abs_path, "system-ctk-root")
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
# ---------------------------------------------------------------------------
|
| 157 |
+
# Find steps
|
| 158 |
+
# ---------------------------------------------------------------------------
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def find_in_site_packages(ctx: SearchContext) -> FindResult | None:
|
| 162 |
+
"""Search pip wheel install locations."""
|
| 163 |
+
rel_dirs = ctx.platform.site_packages_rel_dirs(ctx.desc)
|
| 164 |
+
if not rel_dirs:
|
| 165 |
+
return None
|
| 166 |
+
abs_path = ctx.platform.find_in_site_packages(rel_dirs, ctx.lib_searched_for, ctx.error_messages, ctx.attachments)
|
| 167 |
+
if abs_path is not None:
|
| 168 |
+
return FindResult(abs_path, "site-packages")
|
| 169 |
+
return None
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def find_in_conda(ctx: SearchContext) -> FindResult | None:
|
| 173 |
+
"""Search ``$CONDA_PREFIX``."""
|
| 174 |
+
conda_prefix = os.environ.get("CONDA_PREFIX")
|
| 175 |
+
if not conda_prefix:
|
| 176 |
+
return None
|
| 177 |
+
anchor = ctx.platform.conda_anchor_point(conda_prefix)
|
| 178 |
+
lib_dir = _find_lib_dir_using_anchor(ctx.desc, ctx.platform, anchor)
|
| 179 |
+
abs_path = _find_using_lib_dir(ctx, lib_dir)
|
| 180 |
+
if abs_path is not None:
|
| 181 |
+
return FindResult(abs_path, "conda")
|
| 182 |
+
return None
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def find_in_cuda_path(ctx: SearchContext) -> FindResult | None:
|
| 186 |
+
"""Search ``$CUDA_PATH`` / ``$CUDA_HOME``.
|
| 187 |
+
|
| 188 |
+
On Windows, this is the normal fallback for system-installed CTK DLLs when
|
| 189 |
+
they are not already discoverable via the native ``LoadLibraryExW(..., 0)``
|
| 190 |
+
path used by :func:`cuda.pathfinder._dynamic_libs.load_dl_windows.load_with_system_search`.
|
| 191 |
+
Python 3.8+ does not include ``PATH`` in that native DLL search.
|
| 192 |
+
|
| 193 |
+
The returned ``found_via`` is always ``"CUDA_PATH"`` regardless of which
|
| 194 |
+
environment variable actually provided the value.
|
| 195 |
+
"""
|
| 196 |
+
cuda_home = get_cuda_path_or_home()
|
| 197 |
+
if cuda_home is None:
|
| 198 |
+
return None
|
| 199 |
+
lib_dir = _find_lib_dir_using_anchor(ctx.desc, ctx.platform, cuda_home)
|
| 200 |
+
abs_path = _find_using_lib_dir(ctx, lib_dir)
|
| 201 |
+
if abs_path is not None:
|
| 202 |
+
return FindResult(abs_path, "CUDA_PATH")
|
| 203 |
+
return None
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# ---------------------------------------------------------------------------
|
| 207 |
+
# Step sequences per strategy
|
| 208 |
+
# ---------------------------------------------------------------------------
|
| 209 |
+
|
| 210 |
+
#: Find steps that run before the already-loaded check and system search.
|
| 211 |
+
EARLY_FIND_STEPS: tuple[FindStep, ...] = (find_in_site_packages, find_in_conda)
|
| 212 |
+
|
| 213 |
+
#: Find steps that run after system search fails.
|
| 214 |
+
LATE_FIND_STEPS: tuple[FindStep, ...] = (find_in_cuda_path,)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# ---------------------------------------------------------------------------
|
| 218 |
+
# Cascade runner
|
| 219 |
+
# ---------------------------------------------------------------------------
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def run_find_steps(ctx: SearchContext, steps: tuple[FindStep, ...]) -> FindResult | None:
|
| 223 |
+
"""Run find steps in order, returning the first hit."""
|
| 224 |
+
for step in steps:
|
| 225 |
+
result = step(ctx)
|
| 226 |
+
if result is not None:
|
| 227 |
+
return result
|
| 228 |
+
return None
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/subprocess_protocol.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import sys
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Literal
|
| 11 |
+
|
| 12 |
+
MODE_CANARY: Literal["canary"] = "canary"
|
| 13 |
+
MODE_LOAD: Literal["load"] = "load"
|
| 14 |
+
VALID_MODES: tuple[Literal["canary"], Literal["load"]] = (MODE_CANARY, MODE_LOAD)
|
| 15 |
+
|
| 16 |
+
STATUS_OK: Literal["ok"] = "ok"
|
| 17 |
+
STATUS_NOT_FOUND: Literal["not-found"] = "not-found"
|
| 18 |
+
|
| 19 |
+
DYNAMIC_LIB_SUBPROCESS_MODULE = "cuda.pathfinder._dynamic_libs.dynamic_lib_subprocess"
|
| 20 |
+
DYNAMIC_LIB_SUBPROCESS_CWD = Path(__file__).resolve().parents[3]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@dataclass(frozen=True)
|
| 24 |
+
class DynamicLibSubprocessPayload:
|
| 25 |
+
status: Literal["ok", "not-found"]
|
| 26 |
+
abs_path: str | None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def format_dynamic_lib_subprocess_payload(
|
| 30 |
+
status: Literal["ok", "not-found"],
|
| 31 |
+
abs_path: str | None,
|
| 32 |
+
*,
|
| 33 |
+
error: dict[str, str] | None = None,
|
| 34 |
+
) -> str:
|
| 35 |
+
payload: dict[str, object] = {"status": status, "abs_path": abs_path}
|
| 36 |
+
if error is not None:
|
| 37 |
+
payload["error"] = error
|
| 38 |
+
return json.dumps(payload)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def build_dynamic_lib_subprocess_command(mode: str, libname: str) -> list[str]:
|
| 42 |
+
return [sys.executable, "-m", DYNAMIC_LIB_SUBPROCESS_MODULE, mode, libname]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def parse_dynamic_lib_subprocess_payload(
|
| 46 |
+
stdout: str,
|
| 47 |
+
*,
|
| 48 |
+
libname: str,
|
| 49 |
+
error_label: str,
|
| 50 |
+
) -> DynamicLibSubprocessPayload:
|
| 51 |
+
# Use the final non-empty line in case earlier output lines are emitted.
|
| 52 |
+
lines = [line for line in stdout.splitlines() if line.strip()]
|
| 53 |
+
if not lines:
|
| 54 |
+
raise RuntimeError(f"{error_label} produced no stdout payload for {libname!r}")
|
| 55 |
+
try:
|
| 56 |
+
payload = json.loads(lines[-1])
|
| 57 |
+
except json.JSONDecodeError:
|
| 58 |
+
raise RuntimeError(f"{error_label} emitted invalid JSON payload for {libname!r}: {lines[-1]!r}") from None
|
| 59 |
+
if not isinstance(payload, dict):
|
| 60 |
+
raise RuntimeError(f"{error_label} emitted unexpected payload for {libname!r}: {payload!r}")
|
| 61 |
+
status = payload.get("status")
|
| 62 |
+
abs_path = payload.get("abs_path")
|
| 63 |
+
if status == STATUS_OK:
|
| 64 |
+
if not isinstance(abs_path, str):
|
| 65 |
+
raise RuntimeError(f"{error_label} emitted unexpected payload for {libname!r}: {payload!r}")
|
| 66 |
+
return DynamicLibSubprocessPayload(status=STATUS_OK, abs_path=abs_path)
|
| 67 |
+
if status == STATUS_NOT_FOUND:
|
| 68 |
+
if abs_path is not None:
|
| 69 |
+
raise RuntimeError(f"{error_label} emitted unexpected payload for {libname!r}: {payload!r}")
|
| 70 |
+
return DynamicLibSubprocessPayload(status=STATUS_NOT_FOUND, abs_path=None)
|
| 71 |
+
raise RuntimeError(f"{error_label} emitted unexpected payload for {libname!r}: {payload!r}")
|
lib/python3.11/site-packages/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Legacy table exports derived from the authored descriptor catalog.
|
| 5 |
+
|
| 6 |
+
The canonical data entry point is :mod:`descriptor_catalog`. This module keeps
|
| 7 |
+
historical constant names for backward compatibility by deriving them from the
|
| 8 |
+
catalog.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from cuda.pathfinder._dynamic_libs.descriptor_catalog import DESCRIPTOR_CATALOG
|
| 14 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 15 |
+
|
| 16 |
+
_CTK_DESCRIPTORS = tuple(desc for desc in DESCRIPTOR_CATALOG if desc.packaged_with == "ctk")
|
| 17 |
+
_OTHER_DESCRIPTORS = tuple(desc for desc in DESCRIPTOR_CATALOG if desc.packaged_with == "other")
|
| 18 |
+
_DRIVER_DESCRIPTORS = tuple(desc for desc in DESCRIPTOR_CATALOG if desc.packaged_with == "driver")
|
| 19 |
+
_NON_CTK_DESCRIPTORS = _OTHER_DESCRIPTORS + _DRIVER_DESCRIPTORS
|
| 20 |
+
|
| 21 |
+
SUPPORTED_LIBNAMES_COMMON = tuple(desc.name for desc in _CTK_DESCRIPTORS if desc.linux_sonames and desc.windows_dlls)
|
| 22 |
+
SUPPORTED_LIBNAMES_LINUX_ONLY = tuple(
|
| 23 |
+
desc.name for desc in _CTK_DESCRIPTORS if desc.linux_sonames and not desc.windows_dlls
|
| 24 |
+
)
|
| 25 |
+
SUPPORTED_LIBNAMES_WINDOWS_ONLY = tuple(
|
| 26 |
+
desc.name for desc in _CTK_DESCRIPTORS if desc.windows_dlls and not desc.linux_sonames
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
SUPPORTED_LIBNAMES_LINUX = SUPPORTED_LIBNAMES_COMMON + SUPPORTED_LIBNAMES_LINUX_ONLY
|
| 30 |
+
SUPPORTED_LIBNAMES_WINDOWS = SUPPORTED_LIBNAMES_COMMON + SUPPORTED_LIBNAMES_WINDOWS_ONLY
|
| 31 |
+
SUPPORTED_LIBNAMES_ALL = SUPPORTED_LIBNAMES_COMMON + SUPPORTED_LIBNAMES_LINUX_ONLY + SUPPORTED_LIBNAMES_WINDOWS_ONLY
|
| 32 |
+
SUPPORTED_LIBNAMES = SUPPORTED_LIBNAMES_WINDOWS if IS_WINDOWS else SUPPORTED_LIBNAMES_LINUX
|
| 33 |
+
|
| 34 |
+
DIRECT_DEPENDENCIES_CTK = {desc.name: desc.dependencies for desc in _CTK_DESCRIPTORS if desc.dependencies}
|
| 35 |
+
DIRECT_DEPENDENCIES = {desc.name: desc.dependencies for desc in DESCRIPTOR_CATALOG if desc.dependencies}
|
| 36 |
+
|
| 37 |
+
SUPPORTED_LINUX_SONAMES_CTK = {desc.name: desc.linux_sonames for desc in _CTK_DESCRIPTORS if desc.linux_sonames}
|
| 38 |
+
SUPPORTED_LINUX_SONAMES_OTHER = {desc.name: desc.linux_sonames for desc in _OTHER_DESCRIPTORS if desc.linux_sonames}
|
| 39 |
+
SUPPORTED_LINUX_SONAMES_DRIVER = {desc.name: desc.linux_sonames for desc in _DRIVER_DESCRIPTORS if desc.linux_sonames}
|
| 40 |
+
SUPPORTED_LINUX_SONAMES = SUPPORTED_LINUX_SONAMES_CTK | SUPPORTED_LINUX_SONAMES_OTHER | SUPPORTED_LINUX_SONAMES_DRIVER
|
| 41 |
+
|
| 42 |
+
SUPPORTED_WINDOWS_DLLS_CTK = {desc.name: desc.windows_dlls for desc in _CTK_DESCRIPTORS if desc.windows_dlls}
|
| 43 |
+
SUPPORTED_WINDOWS_DLLS_OTHER = {desc.name: desc.windows_dlls for desc in _OTHER_DESCRIPTORS if desc.windows_dlls}
|
| 44 |
+
SUPPORTED_WINDOWS_DLLS_DRIVER = {desc.name: desc.windows_dlls for desc in _DRIVER_DESCRIPTORS if desc.windows_dlls}
|
| 45 |
+
SUPPORTED_WINDOWS_DLLS = SUPPORTED_WINDOWS_DLLS_CTK | SUPPORTED_WINDOWS_DLLS_OTHER | SUPPORTED_WINDOWS_DLLS_DRIVER
|
| 46 |
+
|
| 47 |
+
LIBNAMES_REQUIRING_OS_ADD_DLL_DIRECTORY = tuple(
|
| 48 |
+
desc.name for desc in DESCRIPTOR_CATALOG if desc.requires_add_dll_directory and desc.windows_dlls
|
| 49 |
+
)
|
| 50 |
+
LIBNAMES_REQUIRING_RTLD_DEEPBIND = tuple(
|
| 51 |
+
desc.name for desc in DESCRIPTOR_CATALOG if desc.requires_rtld_deepbind and desc.linux_sonames
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Based on output of toolshed/make_site_packages_libdirs_linux.py
|
| 55 |
+
SITE_PACKAGES_LIBDIRS_LINUX_CTK = {
|
| 56 |
+
desc.name: desc.site_packages_linux for desc in _CTK_DESCRIPTORS if desc.site_packages_linux
|
| 57 |
+
}
|
| 58 |
+
SITE_PACKAGES_LIBDIRS_LINUX_OTHER = {
|
| 59 |
+
desc.name: desc.site_packages_linux for desc in _NON_CTK_DESCRIPTORS if desc.site_packages_linux
|
| 60 |
+
}
|
| 61 |
+
SITE_PACKAGES_LIBDIRS_LINUX = SITE_PACKAGES_LIBDIRS_LINUX_CTK | SITE_PACKAGES_LIBDIRS_LINUX_OTHER
|
| 62 |
+
|
| 63 |
+
SITE_PACKAGES_LIBDIRS_WINDOWS_CTK = {
|
| 64 |
+
desc.name: desc.site_packages_windows for desc in _CTK_DESCRIPTORS if desc.site_packages_windows
|
| 65 |
+
}
|
| 66 |
+
SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER = {
|
| 67 |
+
desc.name: desc.site_packages_windows for desc in _NON_CTK_DESCRIPTORS if desc.site_packages_windows
|
| 68 |
+
}
|
| 69 |
+
SITE_PACKAGES_LIBDIRS_WINDOWS = SITE_PACKAGES_LIBDIRS_WINDOWS_CTK | SITE_PACKAGES_LIBDIRS_WINDOWS_OTHER
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def is_suppressed_dll_file(path_basename: str) -> bool:
|
| 73 |
+
if path_basename.startswith("nvrtc"):
|
| 74 |
+
# nvidia_cuda_nvrtc_cu12-12.8.93-py3-none-win_amd64.whl:
|
| 75 |
+
# nvidia\cuda_nvrtc\bin\
|
| 76 |
+
# nvrtc-builtins64_128.dll
|
| 77 |
+
# nvrtc64_120_0.alt.dll
|
| 78 |
+
# nvrtc64_120_0.dll
|
| 79 |
+
return path_basename.endswith(".alt.dll") or "-builtins" in path_basename
|
| 80 |
+
return path_basename.startswith(("cudart32_", "nvvm32"))
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/find_nvidia_headers.cpython-311.pyc
ADDED
|
Binary file (9.69 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/header_descriptor.cpython-311.pyc
ADDED
|
Binary file (3.21 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/header_descriptor_catalog.cpython-311.pyc
ADDED
|
Binary file (4.85 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/__pycache__/supported_nvidia_headers.cpython-311.pyc
ADDED
|
Binary file (5.18 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/find_nvidia_headers.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import functools
|
| 7 |
+
import glob
|
| 8 |
+
import os
|
| 9 |
+
from collections.abc import Callable
|
| 10 |
+
from dataclasses import dataclass
|
| 11 |
+
from typing import TYPE_CHECKING
|
| 12 |
+
|
| 13 |
+
from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import (
|
| 14 |
+
_resolve_system_loaded_abs_path_in_subprocess,
|
| 15 |
+
)
|
| 16 |
+
from cuda.pathfinder._dynamic_libs.search_steps import derive_ctk_root
|
| 17 |
+
from cuda.pathfinder._headers.header_descriptor import (
|
| 18 |
+
HEADER_DESCRIPTORS,
|
| 19 |
+
platform_include_subdirs,
|
| 20 |
+
resolve_conda_anchor,
|
| 21 |
+
)
|
| 22 |
+
from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home
|
| 23 |
+
from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages
|
| 24 |
+
|
| 25 |
+
if TYPE_CHECKING:
|
| 26 |
+
from cuda.pathfinder._headers.header_descriptor import HeaderDescriptor
|
| 27 |
+
|
| 28 |
+
# ---------------------------------------------------------------------------
|
| 29 |
+
# Data types
|
| 30 |
+
# ---------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@dataclass
|
| 34 |
+
class LocatedHeaderDir:
|
| 35 |
+
abs_path: str | None
|
| 36 |
+
found_via: str
|
| 37 |
+
|
| 38 |
+
def __post_init__(self) -> None:
|
| 39 |
+
self.abs_path = _abs_norm(self.abs_path)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
#: Type alias for a header find step callable.
|
| 43 |
+
HeaderFindStep = Callable[["HeaderDescriptor"], LocatedHeaderDir | None]
|
| 44 |
+
|
| 45 |
+
# ---------------------------------------------------------------------------
|
| 46 |
+
# Helpers
|
| 47 |
+
# ---------------------------------------------------------------------------
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _abs_norm(path: str | None) -> str | None:
|
| 51 |
+
if path:
|
| 52 |
+
return os.path.normpath(os.path.abspath(path))
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _joined_isfile(dirpath: str, basename: str) -> bool:
|
| 57 |
+
return os.path.isfile(os.path.join(dirpath, basename))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _locate_in_anchor_layout(desc: HeaderDescriptor, anchor_point: str) -> str | None:
|
| 61 |
+
"""Search for a header under *anchor_point* using the descriptor's layout fields."""
|
| 62 |
+
h_basename = desc.header_basename
|
| 63 |
+
for rel_dir in desc.anchor_include_rel_dirs:
|
| 64 |
+
idir = os.path.join(anchor_point, rel_dir)
|
| 65 |
+
for subdir in platform_include_subdirs(desc):
|
| 66 |
+
cdir = os.path.join(idir, subdir)
|
| 67 |
+
if _joined_isfile(cdir, h_basename):
|
| 68 |
+
return cdir
|
| 69 |
+
if _joined_isfile(idir, h_basename):
|
| 70 |
+
return idir
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# ---------------------------------------------------------------------------
|
| 75 |
+
# Find steps
|
| 76 |
+
# ---------------------------------------------------------------------------
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def find_in_site_packages(desc: HeaderDescriptor) -> LocatedHeaderDir | None:
|
| 80 |
+
"""Search pip wheel install locations."""
|
| 81 |
+
for sub_dir in desc.site_packages_dirs:
|
| 82 |
+
hdr_dir: str # help mypy
|
| 83 |
+
for hdr_dir in find_sub_dirs_all_sitepackages(tuple(sub_dir.split("/"))):
|
| 84 |
+
if _joined_isfile(hdr_dir, desc.header_basename):
|
| 85 |
+
return LocatedHeaderDir(abs_path=hdr_dir, found_via="site-packages")
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def find_in_conda(desc: HeaderDescriptor) -> LocatedHeaderDir | None:
|
| 90 |
+
"""Search ``$CONDA_PREFIX``."""
|
| 91 |
+
conda_prefix = os.environ.get("CONDA_PREFIX")
|
| 92 |
+
if not conda_prefix:
|
| 93 |
+
return None
|
| 94 |
+
anchor_point = resolve_conda_anchor(desc, conda_prefix)
|
| 95 |
+
if anchor_point is None:
|
| 96 |
+
return None
|
| 97 |
+
found_header_path = _locate_in_anchor_layout(desc, anchor_point)
|
| 98 |
+
if found_header_path:
|
| 99 |
+
return LocatedHeaderDir(abs_path=found_header_path, found_via="conda")
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def find_in_cuda_path(desc: HeaderDescriptor) -> LocatedHeaderDir | None:
|
| 104 |
+
"""Search ``$CUDA_PATH`` / ``$CUDA_HOME``."""
|
| 105 |
+
cuda_home = get_cuda_path_or_home()
|
| 106 |
+
if cuda_home is None:
|
| 107 |
+
return None
|
| 108 |
+
result = _locate_in_anchor_layout(desc, cuda_home)
|
| 109 |
+
if result is not None:
|
| 110 |
+
return LocatedHeaderDir(abs_path=result, found_via="CUDA_PATH")
|
| 111 |
+
return None
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def find_via_ctk_root_canary(desc: HeaderDescriptor) -> LocatedHeaderDir | None:
|
| 115 |
+
"""Try CTK header lookup via CTK-root canary probing.
|
| 116 |
+
|
| 117 |
+
Skips immediately if the descriptor does not opt in (``use_ctk_root_canary``).
|
| 118 |
+
Otherwise, system-loads ``cudart`` in a fully isolated Python subprocess, derives
|
| 119 |
+
CTK root from the resolved library path, and searches the expected include
|
| 120 |
+
layout under that root.
|
| 121 |
+
"""
|
| 122 |
+
if not desc.use_ctk_root_canary:
|
| 123 |
+
return None
|
| 124 |
+
canary_abs_path = _resolve_system_loaded_abs_path_in_subprocess("cudart")
|
| 125 |
+
if canary_abs_path is None:
|
| 126 |
+
return None
|
| 127 |
+
ctk_root = derive_ctk_root(canary_abs_path)
|
| 128 |
+
if ctk_root is None:
|
| 129 |
+
return None
|
| 130 |
+
result = _locate_in_anchor_layout(desc, ctk_root)
|
| 131 |
+
if result is not None:
|
| 132 |
+
return LocatedHeaderDir(abs_path=result, found_via="system-ctk-root")
|
| 133 |
+
return None
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def find_in_system_install_dirs(desc: HeaderDescriptor) -> LocatedHeaderDir | None:
|
| 137 |
+
"""Search system install directories (glob patterns)."""
|
| 138 |
+
for pattern in desc.system_install_dirs:
|
| 139 |
+
for hdr_dir in sorted(glob.glob(pattern), reverse=True):
|
| 140 |
+
if _joined_isfile(hdr_dir, desc.header_basename):
|
| 141 |
+
return LocatedHeaderDir(abs_path=hdr_dir, found_via="supported_install_dir")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# ---------------------------------------------------------------------------
|
| 146 |
+
# Step sequence and cascade runner
|
| 147 |
+
# ---------------------------------------------------------------------------
|
| 148 |
+
|
| 149 |
+
#: Unified find steps — each step self-gates based on descriptor fields.
|
| 150 |
+
FIND_STEPS: tuple[HeaderFindStep, ...] = (
|
| 151 |
+
find_in_site_packages,
|
| 152 |
+
find_in_conda,
|
| 153 |
+
find_in_cuda_path,
|
| 154 |
+
find_via_ctk_root_canary,
|
| 155 |
+
find_in_system_install_dirs,
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def run_find_steps(desc: HeaderDescriptor, steps: tuple[HeaderFindStep, ...]) -> LocatedHeaderDir | None:
|
| 160 |
+
"""Run find steps in order, returning the first hit."""
|
| 161 |
+
for step in steps:
|
| 162 |
+
result = step(desc)
|
| 163 |
+
if result is not None:
|
| 164 |
+
return result
|
| 165 |
+
return None
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# ---------------------------------------------------------------------------
|
| 169 |
+
# Public API
|
| 170 |
+
# ---------------------------------------------------------------------------
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
@functools.cache
|
| 174 |
+
def locate_nvidia_header_directory(libname: str) -> LocatedHeaderDir | None:
|
| 175 |
+
"""Locate the header directory for a supported NVIDIA library.
|
| 176 |
+
|
| 177 |
+
Args:
|
| 178 |
+
libname (str): The short name of the library whose headers are needed
|
| 179 |
+
(e.g., ``"nvrtc"``, ``"cusolver"``, ``"nvshmem"``).
|
| 180 |
+
|
| 181 |
+
Returns:
|
| 182 |
+
LocatedHeaderDir or None: A LocatedHeaderDir object containing the absolute path
|
| 183 |
+
to the discovered header directory and information about where it was found,
|
| 184 |
+
or ``None`` if the headers cannot be found.
|
| 185 |
+
|
| 186 |
+
Raises:
|
| 187 |
+
RuntimeError: If ``libname`` is not in the supported set.
|
| 188 |
+
|
| 189 |
+
Search order:
|
| 190 |
+
1. **NVIDIA Python wheels** — site-packages directories from the descriptor.
|
| 191 |
+
2. **Conda environments** — platform-specific conda include layouts.
|
| 192 |
+
3. **CUDA Toolkit environment variables** — ``CUDA_PATH`` / ``CUDA_HOME``.
|
| 193 |
+
4. **CTK root canary probe** — subprocess canary (descriptors with
|
| 194 |
+
``use_ctk_root_canary=True`` only).
|
| 195 |
+
5. **System install directories** — glob patterns from the descriptor.
|
| 196 |
+
"""
|
| 197 |
+
desc = HEADER_DESCRIPTORS.get(libname)
|
| 198 |
+
if desc is None:
|
| 199 |
+
raise RuntimeError(f"UNKNOWN {libname=}")
|
| 200 |
+
return run_find_steps(desc, FIND_STEPS)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def find_nvidia_header_directory(libname: str) -> str | None:
|
| 204 |
+
"""Locate the header directory for a supported NVIDIA library.
|
| 205 |
+
|
| 206 |
+
Args:
|
| 207 |
+
libname (str): The short name of the library whose headers are needed
|
| 208 |
+
(e.g., ``"nvrtc"``, ``"cusolver"``, ``"nvshmem"``).
|
| 209 |
+
|
| 210 |
+
Returns:
|
| 211 |
+
str or None: Absolute path to the discovered header directory, or ``None``
|
| 212 |
+
if the headers cannot be found.
|
| 213 |
+
|
| 214 |
+
Raises:
|
| 215 |
+
RuntimeError: If ``libname`` is not in the supported set.
|
| 216 |
+
|
| 217 |
+
Search order:
|
| 218 |
+
1. **NVIDIA Python wheels** — site-packages directories from the descriptor.
|
| 219 |
+
2. **Conda environments** — platform-specific conda include layouts.
|
| 220 |
+
3. **CUDA Toolkit environment variables** — ``CUDA_PATH`` / ``CUDA_HOME``.
|
| 221 |
+
4. **CTK root canary probe** — subprocess canary (descriptors with
|
| 222 |
+
``use_ctk_root_canary=True`` only).
|
| 223 |
+
5. **System install directories** — glob patterns from the descriptor.
|
| 224 |
+
"""
|
| 225 |
+
found = locate_nvidia_header_directory(libname)
|
| 226 |
+
return found.abs_path if found else None
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/header_descriptor.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Per-header descriptor, registry, and platform-aware accessors.
|
| 5 |
+
|
| 6 |
+
The canonical authored data lives in :mod:`header_descriptor_catalog`. This
|
| 7 |
+
module provides a name-keyed registry and platform-dispatch helpers consumed
|
| 8 |
+
by the runtime search path — keeping the search code itself platform-agnostic.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import glob
|
| 14 |
+
import os
|
| 15 |
+
from typing import TypeAlias, cast
|
| 16 |
+
|
| 17 |
+
from cuda.pathfinder._headers.header_descriptor_catalog import (
|
| 18 |
+
HEADER_DESCRIPTOR_CATALOG,
|
| 19 |
+
HeaderDescriptorSpec,
|
| 20 |
+
)
|
| 21 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 22 |
+
|
| 23 |
+
HeaderDescriptor: TypeAlias = HeaderDescriptorSpec
|
| 24 |
+
|
| 25 |
+
#: Canonical registry of all known header libraries.
|
| 26 |
+
HEADER_DESCRIPTORS: dict[str, HeaderDescriptor] = {desc.name: desc for desc in HEADER_DESCRIPTOR_CATALOG}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def platform_include_subdirs(desc: HeaderDescriptor) -> tuple[str, ...]:
|
| 30 |
+
"""Return the effective include subdirectory search list for the current platform.
|
| 31 |
+
|
| 32 |
+
On Windows, Windows-specific subdirs are checked first, followed by the
|
| 33 |
+
common subdirs. On Linux, only the common subdirs are returned.
|
| 34 |
+
"""
|
| 35 |
+
if IS_WINDOWS:
|
| 36 |
+
return cast(tuple[str, ...], desc.include_subdirs_windows + desc.include_subdirs)
|
| 37 |
+
return cast(tuple[str, ...], desc.include_subdirs)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def resolve_conda_anchor(desc: HeaderDescriptor, conda_prefix: str) -> str | None:
|
| 41 |
+
"""Resolve the conda anchor point for header search on the current platform.
|
| 42 |
+
|
| 43 |
+
Returns the directory that ``_locate_in_anchor_layout`` should use as
|
| 44 |
+
*anchor_point*, or ``None`` if the conda layout is not usable.
|
| 45 |
+
"""
|
| 46 |
+
if IS_WINDOWS:
|
| 47 |
+
anchor = os.path.join(conda_prefix, "Library")
|
| 48 |
+
return anchor if os.path.isdir(anchor) else None
|
| 49 |
+
if desc.conda_targets_layout:
|
| 50 |
+
targets_include_path = glob.glob(os.path.join(conda_prefix, "targets", "*", "include"))
|
| 51 |
+
if not targets_include_path or len(targets_include_path) != 1:
|
| 52 |
+
return None
|
| 53 |
+
return os.path.dirname(targets_include_path[0])
|
| 54 |
+
return conda_prefix
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/header_descriptor_catalog.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Canonical authored descriptor catalog for header directories."""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from typing import Literal
|
| 10 |
+
|
| 11 |
+
HeaderPackagedWith = Literal["ctk", "other"]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True, slots=True)
|
| 15 |
+
class HeaderDescriptorSpec:
|
| 16 |
+
name: str
|
| 17 |
+
packaged_with: HeaderPackagedWith
|
| 18 |
+
header_basename: str
|
| 19 |
+
site_packages_dirs: tuple[str, ...] = ()
|
| 20 |
+
available_on_linux: bool = True
|
| 21 |
+
available_on_windows: bool = True
|
| 22 |
+
# Relative path(s) from anchor point to the include directory.
|
| 23 |
+
anchor_include_rel_dirs: tuple[str, ...] = ("include",)
|
| 24 |
+
# Subdirectories within the include dir to check before the include dir itself.
|
| 25 |
+
include_subdirs: tuple[str, ...] = ()
|
| 26 |
+
# Windows-only additional subdirectories within the include dir.
|
| 27 |
+
include_subdirs_windows: tuple[str, ...] = ()
|
| 28 |
+
# System install directories (glob patterns).
|
| 29 |
+
system_install_dirs: tuple[str, ...] = ()
|
| 30 |
+
# Whether to use targets/<arch>/include layout for conda on Linux.
|
| 31 |
+
conda_targets_layout: bool = True
|
| 32 |
+
# Whether to attempt CTK-root canary probing (spawns a subprocess).
|
| 33 |
+
use_ctk_root_canary: bool = True
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
HEADER_DESCRIPTOR_CATALOG: tuple[HeaderDescriptorSpec, ...] = (
|
| 37 |
+
# -----------------------------------------------------------------------
|
| 38 |
+
# CTK (CUDA Toolkit) headers
|
| 39 |
+
# -----------------------------------------------------------------------
|
| 40 |
+
HeaderDescriptorSpec(
|
| 41 |
+
name="cccl",
|
| 42 |
+
packaged_with="ctk",
|
| 43 |
+
header_basename="cuda/std/version",
|
| 44 |
+
site_packages_dirs=(
|
| 45 |
+
"nvidia/cu13/include/cccl", # cuda-toolkit[cccl]==13.*
|
| 46 |
+
"nvidia/cuda_cccl/include", # cuda-toolkit[cccl]==12.*
|
| 47 |
+
),
|
| 48 |
+
include_subdirs=("cccl",),
|
| 49 |
+
include_subdirs_windows=("targets/x64/cccl", "targets/x64"),
|
| 50 |
+
),
|
| 51 |
+
HeaderDescriptorSpec(
|
| 52 |
+
name="cublas",
|
| 53 |
+
packaged_with="ctk",
|
| 54 |
+
header_basename="cublas.h",
|
| 55 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cublas/include"),
|
| 56 |
+
),
|
| 57 |
+
HeaderDescriptorSpec(
|
| 58 |
+
name="cudart",
|
| 59 |
+
packaged_with="ctk",
|
| 60 |
+
header_basename="cuda_runtime.h",
|
| 61 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cuda_runtime/include"),
|
| 62 |
+
),
|
| 63 |
+
HeaderDescriptorSpec(
|
| 64 |
+
name="cufft",
|
| 65 |
+
packaged_with="ctk",
|
| 66 |
+
header_basename="cufft.h",
|
| 67 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cufft/include"),
|
| 68 |
+
),
|
| 69 |
+
HeaderDescriptorSpec(
|
| 70 |
+
name="cufile",
|
| 71 |
+
packaged_with="ctk",
|
| 72 |
+
header_basename="cufile.h",
|
| 73 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cufile/include"),
|
| 74 |
+
available_on_windows=False,
|
| 75 |
+
),
|
| 76 |
+
HeaderDescriptorSpec(
|
| 77 |
+
name="curand",
|
| 78 |
+
packaged_with="ctk",
|
| 79 |
+
header_basename="curand.h",
|
| 80 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/curand/include"),
|
| 81 |
+
),
|
| 82 |
+
HeaderDescriptorSpec(
|
| 83 |
+
name="cusolver",
|
| 84 |
+
packaged_with="ctk",
|
| 85 |
+
header_basename="cusolverDn.h",
|
| 86 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cusolver/include"),
|
| 87 |
+
),
|
| 88 |
+
HeaderDescriptorSpec(
|
| 89 |
+
name="cusparse",
|
| 90 |
+
packaged_with="ctk",
|
| 91 |
+
header_basename="cusparse.h",
|
| 92 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cusparse/include"),
|
| 93 |
+
),
|
| 94 |
+
HeaderDescriptorSpec(
|
| 95 |
+
name="npp",
|
| 96 |
+
packaged_with="ctk",
|
| 97 |
+
header_basename="npp.h",
|
| 98 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/npp/include"),
|
| 99 |
+
),
|
| 100 |
+
HeaderDescriptorSpec(
|
| 101 |
+
name="profiler",
|
| 102 |
+
packaged_with="ctk",
|
| 103 |
+
header_basename="cuda_profiler_api.h",
|
| 104 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cuda_profiler_api/include"),
|
| 105 |
+
),
|
| 106 |
+
HeaderDescriptorSpec(
|
| 107 |
+
name="nvcc",
|
| 108 |
+
packaged_with="ctk",
|
| 109 |
+
header_basename="fatbinary_section.h",
|
| 110 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cuda_nvcc/include"),
|
| 111 |
+
),
|
| 112 |
+
HeaderDescriptorSpec(
|
| 113 |
+
name="nvfatbin",
|
| 114 |
+
packaged_with="ctk",
|
| 115 |
+
header_basename="nvFatbin.h",
|
| 116 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/nvfatbin/include"),
|
| 117 |
+
),
|
| 118 |
+
HeaderDescriptorSpec(
|
| 119 |
+
name="nvjitlink",
|
| 120 |
+
packaged_with="ctk",
|
| 121 |
+
header_basename="nvJitLink.h",
|
| 122 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/nvjitlink/include"),
|
| 123 |
+
),
|
| 124 |
+
HeaderDescriptorSpec(
|
| 125 |
+
name="nvjpeg",
|
| 126 |
+
packaged_with="ctk",
|
| 127 |
+
header_basename="nvjpeg.h",
|
| 128 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/nvjpeg/include"),
|
| 129 |
+
),
|
| 130 |
+
HeaderDescriptorSpec(
|
| 131 |
+
name="nvrtc",
|
| 132 |
+
packaged_with="ctk",
|
| 133 |
+
header_basename="nvrtc.h",
|
| 134 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cuda_nvrtc/include"),
|
| 135 |
+
),
|
| 136 |
+
HeaderDescriptorSpec(
|
| 137 |
+
name="nvvm",
|
| 138 |
+
packaged_with="ctk",
|
| 139 |
+
header_basename="nvvm.h",
|
| 140 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cuda_nvcc/nvvm/include"),
|
| 141 |
+
anchor_include_rel_dirs=("nvvm/include",),
|
| 142 |
+
),
|
| 143 |
+
HeaderDescriptorSpec(
|
| 144 |
+
name="cudla",
|
| 145 |
+
packaged_with="ctk",
|
| 146 |
+
header_basename="cudla.h",
|
| 147 |
+
site_packages_dirs=("nvidia/cu13/include",),
|
| 148 |
+
available_on_windows=False,
|
| 149 |
+
),
|
| 150 |
+
# -----------------------------------------------------------------------
|
| 151 |
+
# Third-party / separately packaged headers
|
| 152 |
+
# -----------------------------------------------------------------------
|
| 153 |
+
HeaderDescriptorSpec(
|
| 154 |
+
name="cusolverMp",
|
| 155 |
+
packaged_with="other",
|
| 156 |
+
header_basename="cusolverMp.h",
|
| 157 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cu12/include"),
|
| 158 |
+
available_on_windows=False,
|
| 159 |
+
conda_targets_layout=False,
|
| 160 |
+
use_ctk_root_canary=False,
|
| 161 |
+
),
|
| 162 |
+
HeaderDescriptorSpec(
|
| 163 |
+
name="cusparseLt",
|
| 164 |
+
packaged_with="other",
|
| 165 |
+
header_basename="cusparseLt.h",
|
| 166 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cusparselt/include"),
|
| 167 |
+
conda_targets_layout=False,
|
| 168 |
+
use_ctk_root_canary=False,
|
| 169 |
+
),
|
| 170 |
+
HeaderDescriptorSpec(
|
| 171 |
+
name="cute",
|
| 172 |
+
packaged_with="other",
|
| 173 |
+
header_basename="cute/tensor.hpp",
|
| 174 |
+
site_packages_dirs=("cutlass_library/source/include",),
|
| 175 |
+
conda_targets_layout=False,
|
| 176 |
+
use_ctk_root_canary=False,
|
| 177 |
+
),
|
| 178 |
+
HeaderDescriptorSpec(
|
| 179 |
+
name="cutensor",
|
| 180 |
+
packaged_with="other",
|
| 181 |
+
header_basename="cutensor.h",
|
| 182 |
+
site_packages_dirs=("cutensor/include",),
|
| 183 |
+
conda_targets_layout=False,
|
| 184 |
+
use_ctk_root_canary=False,
|
| 185 |
+
),
|
| 186 |
+
HeaderDescriptorSpec(
|
| 187 |
+
name="cutlass",
|
| 188 |
+
packaged_with="other",
|
| 189 |
+
header_basename="cutlass/cutlass.h",
|
| 190 |
+
site_packages_dirs=("cutlass_library/source/include",),
|
| 191 |
+
conda_targets_layout=False,
|
| 192 |
+
use_ctk_root_canary=False,
|
| 193 |
+
),
|
| 194 |
+
HeaderDescriptorSpec(
|
| 195 |
+
name="mathdx",
|
| 196 |
+
packaged_with="other",
|
| 197 |
+
header_basename="libmathdx.h",
|
| 198 |
+
site_packages_dirs=("nvidia/cu13/include", "nvidia/cu12/include"),
|
| 199 |
+
conda_targets_layout=False,
|
| 200 |
+
use_ctk_root_canary=False,
|
| 201 |
+
),
|
| 202 |
+
HeaderDescriptorSpec(
|
| 203 |
+
name="nvshmem",
|
| 204 |
+
packaged_with="other",
|
| 205 |
+
header_basename="nvshmem.h",
|
| 206 |
+
site_packages_dirs=("nvidia/nvshmem/include",),
|
| 207 |
+
available_on_windows=False,
|
| 208 |
+
system_install_dirs=("/usr/include/nvshmem_*",),
|
| 209 |
+
conda_targets_layout=False,
|
| 210 |
+
use_ctk_root_canary=False,
|
| 211 |
+
),
|
| 212 |
+
)
|
lib/python3.11/site-packages/cuda/pathfinder/_headers/supported_nvidia_headers.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
"""Legacy table exports derived from the authored header descriptor catalog.
|
| 5 |
+
|
| 6 |
+
The canonical data entry point is :mod:`header_descriptor_catalog`. This module
|
| 7 |
+
keeps historical constant names for backward compatibility by deriving them
|
| 8 |
+
from the catalog.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from typing import Final
|
| 14 |
+
|
| 15 |
+
from cuda.pathfinder._headers.header_descriptor_catalog import HEADER_DESCRIPTOR_CATALOG
|
| 16 |
+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
|
| 17 |
+
|
| 18 |
+
_CTK_DESCRIPTORS = tuple(desc for desc in HEADER_DESCRIPTOR_CATALOG if desc.packaged_with == "ctk")
|
| 19 |
+
_NON_CTK_DESCRIPTORS = tuple(desc for desc in HEADER_DESCRIPTOR_CATALOG if desc.packaged_with == "other")
|
| 20 |
+
|
| 21 |
+
SUPPORTED_HEADERS_CTK_COMMON: Final[dict[str, str]] = {
|
| 22 |
+
desc.name: desc.header_basename
|
| 23 |
+
for desc in _CTK_DESCRIPTORS
|
| 24 |
+
if desc.available_on_linux and desc.available_on_windows
|
| 25 |
+
}
|
| 26 |
+
SUPPORTED_HEADERS_CTK_LINUX_ONLY: Final[dict[str, str]] = {
|
| 27 |
+
desc.name: desc.header_basename
|
| 28 |
+
for desc in _CTK_DESCRIPTORS
|
| 29 |
+
if desc.available_on_linux and not desc.available_on_windows
|
| 30 |
+
}
|
| 31 |
+
SUPPORTED_HEADERS_CTK_WINDOWS_ONLY: Final[dict[str, str]] = {
|
| 32 |
+
desc.name: desc.header_basename
|
| 33 |
+
for desc in _CTK_DESCRIPTORS
|
| 34 |
+
if desc.available_on_windows and not desc.available_on_linux
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
SUPPORTED_HEADERS_CTK_LINUX = SUPPORTED_HEADERS_CTK_COMMON | SUPPORTED_HEADERS_CTK_LINUX_ONLY
|
| 38 |
+
SUPPORTED_HEADERS_CTK_WINDOWS = SUPPORTED_HEADERS_CTK_COMMON | SUPPORTED_HEADERS_CTK_WINDOWS_ONLY
|
| 39 |
+
SUPPORTED_HEADERS_CTK_ALL = (
|
| 40 |
+
SUPPORTED_HEADERS_CTK_COMMON | SUPPORTED_HEADERS_CTK_LINUX_ONLY | SUPPORTED_HEADERS_CTK_WINDOWS_ONLY
|
| 41 |
+
)
|
| 42 |
+
SUPPORTED_HEADERS_CTK: Final[dict[str, str]] = (
|
| 43 |
+
SUPPORTED_HEADERS_CTK_WINDOWS if IS_WINDOWS else SUPPORTED_HEADERS_CTK_LINUX
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
SUPPORTED_SITE_PACKAGE_HEADER_DIRS_CTK: Final[dict[str, tuple[str, ...]]] = {
|
| 47 |
+
desc.name: desc.site_packages_dirs for desc in _CTK_DESCRIPTORS if desc.site_packages_dirs
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
SUPPORTED_HEADERS_NON_CTK_COMMON: Final[dict[str, str]] = {
|
| 51 |
+
desc.name: desc.header_basename
|
| 52 |
+
for desc in _NON_CTK_DESCRIPTORS
|
| 53 |
+
if desc.available_on_linux and desc.available_on_windows
|
| 54 |
+
}
|
| 55 |
+
SUPPORTED_HEADERS_NON_CTK_LINUX_ONLY: Final[dict[str, str]] = {
|
| 56 |
+
desc.name: desc.header_basename
|
| 57 |
+
for desc in _NON_CTK_DESCRIPTORS
|
| 58 |
+
if desc.available_on_linux and not desc.available_on_windows
|
| 59 |
+
}
|
| 60 |
+
SUPPORTED_HEADERS_NON_CTK_WINDOWS_ONLY: Final[dict[str, str]] = {
|
| 61 |
+
desc.name: desc.header_basename
|
| 62 |
+
for desc in _NON_CTK_DESCRIPTORS
|
| 63 |
+
if desc.available_on_windows and not desc.available_on_linux
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
SUPPORTED_HEADERS_NON_CTK_LINUX = SUPPORTED_HEADERS_NON_CTK_COMMON | SUPPORTED_HEADERS_NON_CTK_LINUX_ONLY
|
| 67 |
+
SUPPORTED_HEADERS_NON_CTK_WINDOWS = SUPPORTED_HEADERS_NON_CTK_COMMON | SUPPORTED_HEADERS_NON_CTK_WINDOWS_ONLY
|
| 68 |
+
SUPPORTED_HEADERS_NON_CTK_ALL = (
|
| 69 |
+
SUPPORTED_HEADERS_NON_CTK_COMMON | SUPPORTED_HEADERS_NON_CTK_LINUX_ONLY | SUPPORTED_HEADERS_NON_CTK_WINDOWS_ONLY
|
| 70 |
+
)
|
| 71 |
+
SUPPORTED_HEADERS_NON_CTK: Final[dict[str, str]] = (
|
| 72 |
+
SUPPORTED_HEADERS_NON_CTK_WINDOWS if IS_WINDOWS else SUPPORTED_HEADERS_NON_CTK_LINUX
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
SUPPORTED_SITE_PACKAGE_HEADER_DIRS_NON_CTK: Final[dict[str, tuple[str, ...]]] = {
|
| 76 |
+
desc.name: desc.site_packages_dirs for desc in _NON_CTK_DESCRIPTORS if desc.site_packages_dirs
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
SUPPORTED_INSTALL_DIRS_NON_CTK: Final[dict[str, tuple[str, ...]]] = {
|
| 80 |
+
desc.name: desc.system_install_dirs for desc in _NON_CTK_DESCRIPTORS if desc.system_install_dirs
|
| 81 |
+
}
|
lib/python3.11/site-packages/cuda/pathfinder/_optional_cuda_import.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import importlib
|
| 7 |
+
from collections.abc import Callable
|
| 8 |
+
from types import ModuleType
|
| 9 |
+
|
| 10 |
+
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _optional_cuda_import(
|
| 14 |
+
fully_qualified_modname: str,
|
| 15 |
+
*,
|
| 16 |
+
probe_function: Callable[[ModuleType], object] | None = None,
|
| 17 |
+
) -> ModuleType | None:
|
| 18 |
+
"""Import an optional CUDA module without masking unrelated import bugs.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
The imported module if available and the optional probe succeeds,
|
| 22 |
+
otherwise ``None`` when the requested module is unavailable.
|
| 23 |
+
|
| 24 |
+
Raises:
|
| 25 |
+
ModuleNotFoundError: If the import fails because a dependency of the
|
| 26 |
+
target module is missing (instead of the target module itself).
|
| 27 |
+
Exception: Any exception raised by ``probe_function`` except
|
| 28 |
+
:class:`DynamicLibNotFoundError`, which is treated as "unavailable".
|
| 29 |
+
"""
|
| 30 |
+
try:
|
| 31 |
+
module = importlib.import_module(fully_qualified_modname)
|
| 32 |
+
except ModuleNotFoundError as err:
|
| 33 |
+
if err.name != fully_qualified_modname:
|
| 34 |
+
raise
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
if probe_function is not None:
|
| 38 |
+
try:
|
| 39 |
+
probe_function(module)
|
| 40 |
+
except DynamicLibNotFoundError:
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
return module
|
lib/python3.11/site-packages/cuda/pathfinder/_static_libs/__pycache__/find_bitcode_lib.cpython-311.pyc
ADDED
|
Binary file (9.31 kB). View file
|
|
|
lib/python3.11/site-packages/cuda/pathfinder/_static_libs/__pycache__/find_static_lib.cpython-311.pyc
ADDED
|
Binary file (9.16 kB). View file
|
|
|