Coverage for cuda / core / experimental / _utils / cuda_utils.pxd: 0%
4 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-10 01:19 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-10 01:19 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
5cimport cpython
6from cpython.object cimport PyObject
7from libc.stdint cimport int64_t
9from cuda.bindings cimport cydriver
12ctypedef fused supported_error_type:
13 cydriver.CUresult
16# mimic CU_DEVICE_INVALID
17cdef const cydriver.CUcontext CU_CONTEXT_INVALID = <cydriver.CUcontext>(-2)
20cdef cydriver.CUdevice get_device_from_ctx(
21 cydriver.CUcontext target_ctx, cydriver.CUcontext curr_ctx) except?cydriver.CU_DEVICE_INVALID nogil
24cdef int HANDLE_RETURN(supported_error_type err) except?-1 nogil
27# TODO: stop exposing these within the codebase?
28cpdef int _check_driver_error(cydriver.CUresult error) except?-1 nogil
29cpdef int _check_runtime_error(error) except?-1
30cpdef int _check_nvrtc_error(error) except?-1
33cpdef check_or_create_options(type cls, options, str options_description=*, bint keep_none=*)
36# Create low-level externs so Cython won't "helpfully" handle reference counting
37# for us. Prefixing with an underscore to distinguish it from the definition in
38# cpython.long.
39cdef extern from "Python.h":
40 PyObject *_PyLong_FromLongLong "PyLong_FromLongLong" (long long val) except NULL
41 void _PyTuple_SET_ITEM "PyTuple_SET_ITEM" (object p, Py_ssize_t pos, PyObject *o)
44cdef inline tuple carray_int64_t_to_tuple(int64_t *ptr, int length):
45 # Construct shape and strides tuples using the Python/C API for speed
46 cdef tuple result = cpython.PyTuple_New(length)
47 for i in range(length):
48 _PyTuple_SET_ITEM(result, i, _PyLong_FromLongLong(ptr[i]))
49 return result