Skip to content

Commit 5e6c7e5

Browse files
committed
Implement TEMPORARY BACKWARD COMPATIBILITY in /cuda/bindings/path_finder.py
1 parent 4096885 commit 5e6c7e5

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

cuda_bindings/cuda/bindings/path_finder.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,46 @@
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

44
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
66

77
__all__ = [
88
"_load_nvidia_dynamic_library",
99
"_SUPPORTED_LIBNAMES",
1010
]
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

Comments
 (0)