Coverage for cuda / bindings / utils / __init__.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-10 01:19 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE 

3from typing import Any, Callable 

4 

5from ._ptx_utils import get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver 

6 

7_handle_getters: dict[type, Callable[[Any], int]] = {} 

8 

9 

10def _add_cuda_native_handle_getter(t: type, getter: Callable[[Any], int]) -> None: 

11 _handle_getters[t] = getter 

12 

13 

14def get_cuda_native_handle(obj: Any) -> int: 

15 """Returns the address of the provided CUDA Python object as a Python int. 

16 

17 Parameters 

18 ---------- 

19 obj : Any 

20 CUDA Python object 

21 

22 Returns 

23 ------- 

24 int : The object address. 

25 """ 

26 obj_type = type(obj) 

27 try: 

28 return _handle_getters[obj_type](obj) 

29 except KeyError: 

30 raise TypeError("Unknown type: " + str(obj_type)) from None