Skip to content

Commit 9ba6196

Browse files
committed
Backport #840
1 parent 00a216b commit 9ba6196

2 files changed

Lines changed: 27 additions & 231 deletions

File tree

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
from ._get_handle import get_cuda_native_handle
4+
from typing import Any, Callable
5+
56
from ._ptx_utils import get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver
7+
8+
_handle_getters: dict[type, Callable[[Any], int]] = {}
9+
10+
11+
def _add_cuda_native_handle_getter(t: type, getter: Callable[[Any], int]) -> None:
12+
_handle_getters[t] = getter
13+
14+
15+
def get_cuda_native_handle(obj: Any) -> int:
16+
"""Returns the address of the provided CUDA Python object as a Python int.
17+
18+
Parameters
19+
----------
20+
obj : Any
21+
CUDA Python object
22+
23+
Returns
24+
-------
25+
int : The object address.
26+
"""
27+
obj_type = type(obj)
28+
try:
29+
return _handle_getters[obj_type](obj)
30+
except KeyError:
31+
raise TypeError("Unknown type: " + str(obj_type)) from None

cuda_bindings/cuda/bindings/utils/_get_handle.pyx.in

Lines changed: 0 additions & 230 deletions
This file was deleted.

0 commit comments

Comments
 (0)