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

12 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-08 01:07 +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 

6from ._version_check import warn_if_cuda_major_version_mismatch 

7 

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

9 

10 

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

12 _handle_getters[t] = getter 

13 

14 

15def 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) 1fghijklmnopqrstuvbcde

28 try: 1fghijklmnopqrstuvbcde

29 return _handle_getters[obj_type](obj) 1fghijklmnopqrstuvbcde

30 except KeyError: 1bcde

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