Coverage for cuda / core / _utils / cuda_utils.pxd: 0.00%

4 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-08 01:07 +0000

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

2# 

3# SPDX-License-Identifier: Apache-2.0 

4  

5cimport cpython 

6from cpython.object cimport PyObject 

7from libc.stdint cimport int64_t, int32_t 

8  

9from cuda.bindings cimport cydriver, cynvrtc, cynvvm, cynvjitlink 

10  

11  

12ctypedef fused integer_t: 

13 int64_t 

14 int32_t 

15  

16  

17# mimic CU_DEVICE_INVALID 

18cdef const cydriver.CUcontext CU_CONTEXT_INVALID = <cydriver.CUcontext>(-2) 

19  

20  

21cdef int HANDLE_RETURN(cydriver.CUresult err) except?-1 nogil 

22cdef int HANDLE_RETURN_NVRTC(cynvrtc.nvrtcProgram prog, cynvrtc.nvrtcResult err) except?-1 nogil 

23cdef int HANDLE_RETURN_NVVM(cynvvm.nvvmProgram prog, cynvvm.nvvmResult err) except?-1 nogil 

24cdef int HANDLE_RETURN_NVJITLINK( 

25 cynvjitlink.nvJitLinkHandle handle, cynvjitlink.nvJitLinkResult err) except?-1 nogil 

26  

27  

28# TODO: stop exposing these within the codebase? 

29cpdef int _check_driver_error(cydriver.CUresult error) except?-1 nogil 

30cpdef int _check_runtime_error(error) except?-1 

31cpdef int _check_nvrtc_error(error) except?-1 

32  

33  

34cpdef check_or_create_options(type cls, options, str options_description=*, bint keep_none=*) 

35  

36  

37# Create low-level externs so Cython won't "helpfully" handle reference counting 

38# for us. Prefixing with an underscore to distinguish it from the definition in 

39# cpython.long. 

40cdef extern from "Python.h": 

41 PyObject *_PyLong_FromLongLong "PyLong_FromLongLong" (long long val) except NULL 

42 void _PyTuple_SET_ITEM "PyTuple_SET_ITEM" (object p, Py_ssize_t pos, PyObject *o) 

43  

44  

45cdef inline tuple carray_integer_t_to_tuple(integer_t *ptr, int length): 

46 # Construct shape and strides tuples using the Python/C API for speed 

47 cdef tuple result = cpython.PyTuple_New(length) 

48 for i in range(length): 

49 _PyTuple_SET_ITEM(result, i, _PyLong_FromLongLong(ptr[i])) 

50 return result