|
2 | 2 | # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
|
3 | 3 |
|
4 | 4 | from cuda.pathfinder import SUPPORTED_NVIDIA_LIBNAMES as _SUPPORTED_LIBNAMES
|
5 |
| -from cuda.pathfinder import load_nvidia_dynamic_lib as _load_nvidia_dynamic_library |
| 5 | +from cuda.pathfinder import load_nvidia_dynamic_lib |
6 | 6 |
|
7 | 7 | __all__ = [
|
8 | 8 | "_load_nvidia_dynamic_library",
|
9 | 9 | "_SUPPORTED_LIBNAMES",
|
10 | 10 | ]
|
| 11 | + |
| 12 | +# All code below this line is for TEMPORARY BACKWARD COMPATIBILITY only. |
| 13 | + |
| 14 | +from dataclasses import dataclass |
| 15 | +from typing import Optional |
| 16 | + |
| 17 | +from cuda.pathfinder._dynamic_libs import supported_nvidia_libs |
| 18 | + |
| 19 | +if supported_nvidia_libs.IS_WINDOWS: |
| 20 | + import pywintypes |
| 21 | + |
| 22 | + from cuda.pathfinder._load_dl_windows import POINTER_ADDRESS_SPACE |
| 23 | + |
| 24 | + def _unsigned_int_to_pywintypes_handle(handle_uint: int) -> pywintypes.HANDLE: |
| 25 | + handle_int = handle_uint - POINTER_ADDRESS_SPACE if handle_uint >= POINTER_ADDRESS_SPACE // 2 else handle_uint |
| 26 | + return pywintypes.HANDLE(handle_int) |
| 27 | + |
| 28 | + HandleType = pywintypes.HANDLE |
| 29 | +else: |
| 30 | + HandleType = int |
| 31 | + |
| 32 | + |
| 33 | +# Original implementation, before making handle private as _handle_uint. |
| 34 | +@dataclass |
| 35 | +class LoadedDL: |
| 36 | + handle: HandleType # type: ignore[valid-type] |
| 37 | + abs_path: Optional[str] |
| 38 | + was_already_loaded_from_elsewhere: bool |
| 39 | + |
| 40 | + |
| 41 | +def _load_nvidia_dynamic_library(libname: str) -> LoadedDL: |
| 42 | + loaded_dl_uint = load_nvidia_dynamic_lib(libname) |
| 43 | + if supported_nvidia_libs.IS_WINDOWS: |
| 44 | + handle = _unsigned_int_to_pywintypes_handle(loaded_dl_uint._handle_uint) |
| 45 | + else: |
| 46 | + handle = loaded_dl_uint._handle_uint |
| 47 | + return LoadedDL(handle, loaded_dl_uint.abs_path, loaded_dl_uint.was_already_loaded_from_elsewhere) |
0 commit comments