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

13 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-29 01:27 +0000

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

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

3from typing import Any, Callable 

4 

5from ._nvvm_utils import check_nvvm_compiler_options 

6from ._ptx_utils import get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver 

7from ._version_check import warn_if_cuda_major_version_mismatch 

8 

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

10 

11 

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

13 _handle_getters[t] = getter 

14 

15 

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

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

18 

19 Parameters 

20 ---------- 

21 obj : Any 

22 CUDA Python object 

23 

24 Returns 

25 ------- 

26 int : The object address. 

27 """ 

28 obj_type = type(obj) 1fghijklmnopqrstuvbcde

29 try: 1fghijklmnopqrstuvbcde

30 return _handle_getters[obj_type](obj) 1fghijklmnopqrstuvbcde

31 except KeyError: 1bcde

32 raise TypeError("Unknown type: " + str(obj_type)) from None 1bcde