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

15 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-03 02:41 +0000

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

2# SPDX-License-Identifier: Apache-2.0 

3from typing import Any, Callable 

4 

5from ._envvar import envvar_bool 

6from ._nvvm_utils import check_nvvm_compiler_options 

7from ._ptx_utils import get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver 

8from ._version_check import warn_if_cuda_major_version_mismatch 

9 

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

11 

12 

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

14 _handle_getters[t] = getter 

15 

16 

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

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

19 

20 Parameters 

21 ---------- 

22 obj : Any 

23 CUDA Python object 

24 

25 Returns 

26 ------- 

27 int : The object address. 

28 """ 

29 obj_type = type(obj) 1fghijklmnopqrstuvwbcde

30 try: 1fghijklmnopqrstuvwbcde

31 getter = _handle_getters[obj_type] 1fghijklmnopqrstuvwbcde

32 except KeyError: 1bcde

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

34 # Deliberately outside the try: a KeyError raised by the getter itself is a 

35 # bug in that getter, not an unregistered type. 

36 return getter(obj) 1fghijklmnopqrstuvw