Coverage for cuda/core/_resource_handles.pyx: 97.18%
71 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-13 01:38 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-13 01:38 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
5# This module compiles _cpp/resource_handles.cpp into a shared library.
6# Consumer modules cimport the functions declared in _resource_handles.pxd.
7# Since there is only one copy of the C++ code (in this .so), all static and
8# thread-local state is shared correctly across all consumer modules.
9#
10# The cdef extern from declarations below satisfy the .pxd declarations directly,
11# without needing separate wrapper functions.
13from cpython.pycapsule cimport PyCapsule_GetName, PyCapsule_GetPointer
14from libc.stddef cimport size_t
16from cuda.bindings cimport cydriver
17from cuda.bindings cimport cynvrtc
18from cuda.bindings cimport cynvvm
19from cuda.bindings cimport cynvjitlink
21import cuda.bindings.cydriver as cydriver
22import cuda.bindings.cynvrtc as cynvrtc
23import cuda.bindings.cynvvm as cynvvm
24import cuda.bindings.cynvjitlink as cynvjitlink
26# =============================================================================
27# C++ function declarations (non-inline, implemented in resource_handles.cpp)
28#
29# These declarations satisfy the cdef function declarations in _resource_handles.pxd.
30# Consumer modules cimport these functions and calls go through this .so.
31# =============================================================================
33cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
34 # Thread-local error handling
35 cydriver.CUresult get_last_error "cuda_core::get_last_error" () noexcept nogil
36 cydriver.CUresult peek_last_error "cuda_core::peek_last_error" () noexcept nogil
37 void clear_last_error "cuda_core::clear_last_error" () noexcept nogil
39 # Context handles
40 ContextHandle create_context_handle_ref "cuda_core::create_context_handle_ref" (
41 cydriver.CUcontext ctx) except+ nogil
42 ContextHandle create_context_handle_from_green_ctx "cuda_core::create_context_handle_from_green_ctx" (
43 const GreenCtxHandle& h_green_ctx) except+ nogil
44 GreenCtxHandle get_context_green_ctx "cuda_core::get_context_green_ctx" (
45 const ContextHandle& h) noexcept nogil
46 GreenCtxHandle create_green_ctx_handle "cuda_core::create_green_ctx_handle" (
47 cydriver.CUdevResource* resources, unsigned int nbResources,
48 cydriver.CUdevice dev, unsigned int flags) except+ nogil
49 GreenCtxHandle create_green_ctx_handle_ref "cuda_core::create_green_ctx_handle_ref" (
50 cydriver.CUgreenCtx ctx) except+ nogil
51 ContextHandle get_primary_context "cuda_core::get_primary_context" (
52 int device_id) except+ nogil
53 ContextHandle get_current_context "cuda_core::get_current_context" () except+ nogil
55 # Stream handles
56 StreamHandle create_stream_handle "cuda_core::create_stream_handle" (
57 const ContextHandle& h_ctx, unsigned int flags, int priority) except+ nogil
58 StreamHandle create_stream_handle_ref "cuda_core::create_stream_handle_ref" (
59 cydriver.CUstream stream) except+ nogil
60 StreamHandle create_stream_handle_with_owner "cuda_core::create_stream_handle_with_owner" (
61 cydriver.CUstream stream, object owner) except+ nogil
62 void py_object_user_object_destroy "cuda_core::py_object_user_object_destroy" (
63 void* py_object) noexcept nogil
64 ContextHandle get_stream_context "cuda_core::get_stream_context" (
65 const StreamHandle& h) noexcept nogil
66 StreamHandle get_legacy_stream "cuda_core::get_legacy_stream" () except+ nogil
67 StreamHandle get_per_thread_stream "cuda_core::get_per_thread_stream" () except+ nogil
69 # Event handles (note: _create_event_handle* are internal due to C++ overloading)
70 EventHandle create_event_handle "cuda_core::create_event_handle" (
71 const ContextHandle& h_ctx, unsigned int flags,
72 bint timing_enabled, bint is_blocking_sync,
73 bint ipc_enabled, int device_id) except+ nogil
74 EventHandle create_event_handle_noctx "cuda_core::create_event_handle_noctx" (
75 unsigned int flags) except+ nogil
76 EventHandle create_event_handle_ref "cuda_core::create_event_handle_ref" (
77 cydriver.CUevent event) except+ nogil
78 EventHandle create_event_handle_ipc "cuda_core::create_event_handle_ipc" (
79 const cydriver.CUipcEventHandle& ipc_handle, bint is_blocking_sync) except+ nogil
81 # Event metadata getters
82 bint get_event_timing_enabled "cuda_core::get_event_timing_enabled" (
83 const EventHandle& h) noexcept nogil
84 bint get_event_is_blocking_sync "cuda_core::get_event_is_blocking_sync" (
85 const EventHandle& h) noexcept nogil
86 bint get_event_ipc_enabled "cuda_core::get_event_ipc_enabled" (
87 const EventHandle& h) noexcept nogil
88 int get_event_device_id "cuda_core::get_event_device_id" (
89 const EventHandle& h) noexcept nogil
90 ContextHandle get_event_context "cuda_core::get_event_context" (
91 const EventHandle& h) noexcept nogil
93 # Memory pool handles
94 MemoryPoolHandle create_mempool_handle "cuda_core::create_mempool_handle" (
95 const cydriver.CUmemPoolProps& props) except+ nogil
96 MemoryPoolHandle create_mempool_handle_ref "cuda_core::create_mempool_handle_ref" (
97 cydriver.CUmemoryPool pool) except+ nogil
98 MemoryPoolHandle get_device_mempool "cuda_core::get_device_mempool" (
99 int device_id) except+ nogil
100 MemoryPoolHandle create_mempool_handle_ipc "cuda_core::create_mempool_handle_ipc" (
101 int fd, cydriver.CUmemAllocationHandleType handle_type) except+ nogil
103 # Device pointer handles
104 DevicePtrHandle deviceptr_alloc_from_pool "cuda_core::deviceptr_alloc_from_pool" (
105 size_t size, const MemoryPoolHandle& h_pool, const StreamHandle& h_stream) except+ nogil
106 DevicePtrHandle deviceptr_alloc_async "cuda_core::deviceptr_alloc_async" (
107 size_t size, const StreamHandle& h_stream) except+ nogil
108 DevicePtrHandle deviceptr_alloc "cuda_core::deviceptr_alloc" (size_t size) except+ nogil
109 DevicePtrHandle deviceptr_alloc_host "cuda_core::deviceptr_alloc_host" (size_t size) except+ nogil
110 DevicePtrHandle deviceptr_create_ref "cuda_core::deviceptr_create_ref" (
111 cydriver.CUdeviceptr ptr) except+ nogil
112 DevicePtrHandle deviceptr_create_with_owner "cuda_core::deviceptr_create_with_owner" (
113 cydriver.CUdeviceptr ptr, object owner) except+ nogil
114 DevicePtrHandle deviceptr_create_mapped_graphics "cuda_core::deviceptr_create_mapped_graphics" (
115 cydriver.CUdeviceptr ptr,
116 const GraphicsResourceHandle& h_resource,
117 const StreamHandle& h_stream) except+ nogil
119 # MR deallocation callback
120 void register_mr_dealloc_callback "cuda_core::register_mr_dealloc_callback" (
121 MRDeallocCallback cb) noexcept
122 DevicePtrHandle deviceptr_create_with_mr "cuda_core::deviceptr_create_with_mr" (
123 cydriver.CUdeviceptr ptr, size_t size, object mr) except+ nogil
125 DevicePtrHandle deviceptr_import_ipc "cuda_core::deviceptr_import_ipc" (
126 const MemoryPoolHandle& h_pool, const void* export_data, const StreamHandle& h_stream) except+ nogil
127 StreamHandle deallocation_stream "cuda_core::deallocation_stream" (
128 const DevicePtrHandle& h) noexcept nogil
129 void set_deallocation_stream "cuda_core::set_deallocation_stream" (
130 const DevicePtrHandle& h, const StreamHandle& h_stream) noexcept nogil
132 # Library handles
133 LibraryHandle create_library_handle_from_file "cuda_core::create_library_handle_from_file" (
134 const char* path) except+ nogil
135 LibraryHandle create_library_handle_from_data "cuda_core::create_library_handle_from_data" (
136 const void* data) except+ nogil
137 LibraryHandle create_library_handle_ref "cuda_core::create_library_handle_ref" (
138 cydriver.CUlibrary library) except+ nogil
140 # Kernel handles
141 KernelHandle create_kernel_handle "cuda_core::create_kernel_handle" (
142 const LibraryHandle& h_library, const char* name) except+ nogil
143 KernelHandle create_kernel_handle_ref "cuda_core::create_kernel_handle_ref" (
144 cydriver.CUkernel kernel) except+ nogil
145 LibraryHandle get_kernel_library "cuda_core::get_kernel_library" (
146 const KernelHandle& h) noexcept nogil
148 # Graph handles
149 GraphHandle create_graph_handle "cuda_core::create_graph_handle" (
150 cydriver.CUgraph graph) except+ nogil
151 GraphHandle create_graph_handle_ref "cuda_core::create_graph_handle_ref" (
152 cydriver.CUgraph graph, const GraphHandle& h_parent) except+ nogil
154 # Graph node handles
155 GraphNodeHandle create_graph_node_handle "cuda_core::create_graph_node_handle" (
156 cydriver.CUgraphNode node, const GraphHandle& h_graph) except+ nogil
157 GraphHandle graph_node_get_graph "cuda_core::graph_node_get_graph" (
158 const GraphNodeHandle& h) noexcept nogil
159 void invalidate_graph_node "cuda_core::invalidate_graph_node" (
160 const GraphNodeHandle& h) noexcept nogil
162 # Graphics resource handles
163 GraphicsResourceHandle create_graphics_resource_handle "cuda_core::create_graphics_resource_handle" (
164 cydriver.CUgraphicsResource resource) except+ nogil
166 # NVRTC Program handles
167 NvrtcProgramHandle create_nvrtc_program_handle "cuda_core::create_nvrtc_program_handle" (
168 cynvrtc.nvrtcProgram prog) except+ nogil
169 NvrtcProgramHandle create_nvrtc_program_handle_ref "cuda_core::create_nvrtc_program_handle_ref" (
170 cynvrtc.nvrtcProgram prog) except+ nogil
172 # NVVM Program handles
173 NvvmProgramHandle create_nvvm_program_handle "cuda_core::create_nvvm_program_handle" (
174 cynvvm.nvvmProgram prog) except+ nogil
175 NvvmProgramHandle create_nvvm_program_handle_ref "cuda_core::create_nvvm_program_handle_ref" (
176 cynvvm.nvvmProgram prog) except+ nogil
178 # nvJitLink handles
179 NvJitLinkHandle create_nvjitlink_handle "cuda_core::create_nvjitlink_handle" (
180 cynvjitlink.nvJitLinkHandle handle) except+ nogil
181 NvJitLinkHandle create_nvjitlink_handle_ref "cuda_core::create_nvjitlink_handle_ref" (
182 cynvjitlink.nvJitLinkHandle handle) except+ nogil
184 # cuLink handles
185 CuLinkHandle create_culink_handle "cuda_core::create_culink_handle" (
186 cydriver.CUlinkState state) except+ nogil
187 CuLinkHandle create_culink_handle_ref "cuda_core::create_culink_handle_ref" (
188 cydriver.CUlinkState state) except+ nogil
190 # File descriptor handles
191 FileDescriptorHandle create_fd_handle "cuda_core::create_fd_handle" (
192 int fd) except+ nogil
193 FileDescriptorHandle create_fd_handle_ref "cuda_core::create_fd_handle_ref" (
194 int fd) except+ nogil
196 # SM resource split (13.1+ wrapper — avoids direct cydriver cimport)
197 # groupParams is void* to avoid referencing CU_DEV_SM_RESOURCE_GROUP_PARAMS
198 # (which doesn't exist in cuda-bindings 13.0 .pxd). The C++ side casts it.
199 cydriver.CUresult sm_resource_split "cuda_core::sm_resource_split" (
200 cydriver.CUdevResource* result, unsigned int nbGroups,
201 const cydriver.CUdevResource* input, cydriver.CUdevResource* remainder,
202 unsigned int flags, void* groupParams) nogil
203 bint has_sm_resource_split "cuda_core::has_sm_resource_split" () noexcept nogil
206# =============================================================================
207# CUDA Driver API capsule
208#
209# This provides resolved CUDA driver function pointers to the C++ code.
210# =============================================================================
212cdef const char* _CUDA_DRIVER_API_V1_NAME = b"cuda.core._resource_handles._CUDA_DRIVER_API_V1"
215# =============================================================================
216# CUDA driver function pointer initialization
217#
218# The C++ code declares extern function pointers (p_cuXxx) that need to be
219# populated before any handle creation functions are called. We extract these
220# from cuda.bindings.cydriver.__pyx_capi__ at module import time.
221#
222# The Cython string substitution (e.g., "reinterpret_cast<void*&>(...)")
223# allows us to assign void* values to typed function pointer variables.
224# =============================================================================
226# Declare extern variables with reinterpret_cast to allow void* assignment
227cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
228 # Context
229 void* p_cuDevicePrimaryCtxRetain "reinterpret_cast<void*&>(cuda_core::p_cuDevicePrimaryCtxRetain)"
230 void* p_cuDevicePrimaryCtxRelease "reinterpret_cast<void*&>(cuda_core::p_cuDevicePrimaryCtxRelease)"
231 void* p_cuCtxGetCurrent "reinterpret_cast<void*&>(cuda_core::p_cuCtxGetCurrent)"
232 void* p_cuGreenCtxCreate "reinterpret_cast<void*&>(cuda_core::p_cuGreenCtxCreate)"
233 void* p_cuGreenCtxDestroy "reinterpret_cast<void*&>(cuda_core::p_cuGreenCtxDestroy)"
234 void* p_cuCtxFromGreenCtx "reinterpret_cast<void*&>(cuda_core::p_cuCtxFromGreenCtx)"
235 void* p_cuDevResourceGenerateDesc "reinterpret_cast<void*&>(cuda_core::p_cuDevResourceGenerateDesc)"
236 void* p_cuGreenCtxStreamCreate "reinterpret_cast<void*&>(cuda_core::p_cuGreenCtxStreamCreate)"
238 # Stream
239 void* p_cuStreamCreateWithPriority "reinterpret_cast<void*&>(cuda_core::p_cuStreamCreateWithPriority)"
240 void* p_cuStreamDestroy "reinterpret_cast<void*&>(cuda_core::p_cuStreamDestroy)"
242 # Event
243 void* p_cuEventCreate "reinterpret_cast<void*&>(cuda_core::p_cuEventCreate)"
244 void* p_cuEventDestroy "reinterpret_cast<void*&>(cuda_core::p_cuEventDestroy)"
245 void* p_cuIpcOpenEventHandle "reinterpret_cast<void*&>(cuda_core::p_cuIpcOpenEventHandle)"
247 # Device
248 void* p_cuDeviceGetCount "reinterpret_cast<void*&>(cuda_core::p_cuDeviceGetCount)"
250 # Memory pool
251 void* p_cuMemPoolSetAccess "reinterpret_cast<void*&>(cuda_core::p_cuMemPoolSetAccess)"
252 void* p_cuMemPoolDestroy "reinterpret_cast<void*&>(cuda_core::p_cuMemPoolDestroy)"
253 void* p_cuMemPoolCreate "reinterpret_cast<void*&>(cuda_core::p_cuMemPoolCreate)"
254 void* p_cuDeviceGetMemPool "reinterpret_cast<void*&>(cuda_core::p_cuDeviceGetMemPool)"
255 void* p_cuMemPoolImportFromShareableHandle "reinterpret_cast<void*&>(cuda_core::p_cuMemPoolImportFromShareableHandle)"
257 # Memory allocation
258 void* p_cuMemAllocFromPoolAsync "reinterpret_cast<void*&>(cuda_core::p_cuMemAllocFromPoolAsync)"
259 void* p_cuMemAllocAsync "reinterpret_cast<void*&>(cuda_core::p_cuMemAllocAsync)"
260 void* p_cuMemAlloc "reinterpret_cast<void*&>(cuda_core::p_cuMemAlloc)"
261 void* p_cuMemAllocHost "reinterpret_cast<void*&>(cuda_core::p_cuMemAllocHost)"
263 # Memory deallocation
264 void* p_cuMemFreeAsync "reinterpret_cast<void*&>(cuda_core::p_cuMemFreeAsync)"
265 void* p_cuMemFree "reinterpret_cast<void*&>(cuda_core::p_cuMemFree)"
266 void* p_cuMemFreeHost "reinterpret_cast<void*&>(cuda_core::p_cuMemFreeHost)"
268 # IPC
269 void* p_cuMemPoolImportPointer "reinterpret_cast<void*&>(cuda_core::p_cuMemPoolImportPointer)"
271 # Library
272 void* p_cuLibraryLoadFromFile "reinterpret_cast<void*&>(cuda_core::p_cuLibraryLoadFromFile)"
273 void* p_cuLibraryLoadData "reinterpret_cast<void*&>(cuda_core::p_cuLibraryLoadData)"
274 void* p_cuLibraryUnload "reinterpret_cast<void*&>(cuda_core::p_cuLibraryUnload)"
275 void* p_cuLibraryGetKernel "reinterpret_cast<void*&>(cuda_core::p_cuLibraryGetKernel)"
277 # Graph
278 void* p_cuGraphDestroy "reinterpret_cast<void*&>(cuda_core::p_cuGraphDestroy)"
280 # Linker
281 void* p_cuLinkDestroy "reinterpret_cast<void*&>(cuda_core::p_cuLinkDestroy)"
283 # Graphics interop
284 void* p_cuGraphicsUnmapResources "reinterpret_cast<void*&>(cuda_core::p_cuGraphicsUnmapResources)"
285 void* p_cuGraphicsUnregisterResource "reinterpret_cast<void*&>(cuda_core::p_cuGraphicsUnregisterResource)"
287 # SM resource split (13.1+)
288 void* p_cuDevSmResourceSplit "reinterpret_cast<void*&>(cuda_core::p_cuDevSmResourceSplit)"
290 # NVRTC
291 void* p_nvrtcDestroyProgram "reinterpret_cast<void*&>(cuda_core::p_nvrtcDestroyProgram)"
293 # NVVM
294 void* p_nvvmDestroyProgram "reinterpret_cast<void*&>(cuda_core::p_nvvmDestroyProgram)"
296 # nvJitLink
297 void* p_nvJitLinkDestroy "reinterpret_cast<void*&>(cuda_core::p_nvJitLinkDestroy)"
300# Initialize driver function pointers from cydriver.__pyx_capi__ at module load
301cdef void* _get_driver_fn(str name):
302 capsule = cydriver.__pyx_capi__[name]
303 return PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule))
306cdef void* _get_optional_driver_fn(str name):
307 try:
308 capsule = cydriver.__pyx_capi__[name]
309 except KeyError:
310 return NULL
311 return PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule))
314cdef void _init_driver_fn_pointers() noexcept:
315 global p_cuDevicePrimaryCtxRetain, p_cuDevicePrimaryCtxRelease, p_cuCtxGetCurrent
316 global p_cuGreenCtxCreate, p_cuGreenCtxDestroy, p_cuCtxFromGreenCtx
317 global p_cuDevResourceGenerateDesc, p_cuGreenCtxStreamCreate
318 global p_cuStreamCreateWithPriority, p_cuStreamDestroy
319 global p_cuEventCreate, p_cuEventDestroy, p_cuIpcOpenEventHandle
320 global p_cuDeviceGetCount
321 global p_cuMemPoolSetAccess, p_cuMemPoolDestroy, p_cuMemPoolCreate
322 global p_cuDeviceGetMemPool, p_cuMemPoolImportFromShareableHandle
323 global p_cuMemAllocFromPoolAsync, p_cuMemAllocAsync, p_cuMemAlloc, p_cuMemAllocHost
324 global p_cuMemFreeAsync, p_cuMemFree, p_cuMemFreeHost
325 global p_cuMemPoolImportPointer
326 global p_cuLibraryLoadFromFile, p_cuLibraryLoadData, p_cuLibraryUnload, p_cuLibraryGetKernel
327 global p_cuGraphDestroy
328 global p_cuLinkDestroy
329 global p_cuGraphicsUnmapResources, p_cuGraphicsUnregisterResource
330 global p_cuDevSmResourceSplit
332 # Context
333 p_cuDevicePrimaryCtxRetain = _get_driver_fn("cuDevicePrimaryCtxRetain")
334 p_cuDevicePrimaryCtxRelease = _get_driver_fn("cuDevicePrimaryCtxRelease")
335 p_cuCtxGetCurrent = _get_driver_fn("cuCtxGetCurrent")
336 p_cuGreenCtxCreate = _get_optional_driver_fn("cuGreenCtxCreate")
337 p_cuGreenCtxDestroy = _get_optional_driver_fn("cuGreenCtxDestroy")
338 p_cuCtxFromGreenCtx = _get_optional_driver_fn("cuCtxFromGreenCtx")
339 p_cuDevResourceGenerateDesc = _get_optional_driver_fn("cuDevResourceGenerateDesc")
340 p_cuGreenCtxStreamCreate = _get_optional_driver_fn("cuGreenCtxStreamCreate")
342 # Stream
343 p_cuStreamCreateWithPriority = _get_driver_fn("cuStreamCreateWithPriority")
344 p_cuStreamDestroy = _get_driver_fn("cuStreamDestroy")
346 # Event
347 p_cuEventCreate = _get_driver_fn("cuEventCreate")
348 p_cuEventDestroy = _get_driver_fn("cuEventDestroy")
349 p_cuIpcOpenEventHandle = _get_driver_fn("cuIpcOpenEventHandle")
351 # Device
352 p_cuDeviceGetCount = _get_driver_fn("cuDeviceGetCount")
354 # Memory pool
355 p_cuMemPoolSetAccess = _get_driver_fn("cuMemPoolSetAccess")
356 p_cuMemPoolDestroy = _get_driver_fn("cuMemPoolDestroy")
357 p_cuMemPoolCreate = _get_driver_fn("cuMemPoolCreate")
358 p_cuDeviceGetMemPool = _get_driver_fn("cuDeviceGetMemPool")
359 p_cuMemPoolImportFromShareableHandle = _get_driver_fn("cuMemPoolImportFromShareableHandle")
361 # Memory allocation
362 p_cuMemAllocFromPoolAsync = _get_driver_fn("cuMemAllocFromPoolAsync")
363 p_cuMemAllocAsync = _get_driver_fn("cuMemAllocAsync")
364 p_cuMemAlloc = _get_driver_fn("cuMemAlloc")
365 p_cuMemAllocHost = _get_driver_fn("cuMemAllocHost")
367 # Memory deallocation
368 p_cuMemFreeAsync = _get_driver_fn("cuMemFreeAsync")
369 p_cuMemFree = _get_driver_fn("cuMemFree")
370 p_cuMemFreeHost = _get_driver_fn("cuMemFreeHost")
372 # IPC
373 p_cuMemPoolImportPointer = _get_driver_fn("cuMemPoolImportPointer")
375 # Library
376 p_cuLibraryLoadFromFile = _get_driver_fn("cuLibraryLoadFromFile")
377 p_cuLibraryLoadData = _get_driver_fn("cuLibraryLoadData")
378 p_cuLibraryUnload = _get_driver_fn("cuLibraryUnload")
379 p_cuLibraryGetKernel = _get_driver_fn("cuLibraryGetKernel")
381 # Graph
382 p_cuGraphDestroy = _get_driver_fn("cuGraphDestroy")
384 # Linker
385 p_cuLinkDestroy = _get_driver_fn("cuLinkDestroy")
387 # Graphics interop
388 p_cuGraphicsUnmapResources = _get_driver_fn("cuGraphicsUnmapResources")
389 p_cuGraphicsUnregisterResource = _get_driver_fn("cuGraphicsUnregisterResource")
391 # SM resource split (13.1+ — may not exist in older cuda-bindings)
392 p_cuDevSmResourceSplit = _get_optional_driver_fn("cuDevSmResourceSplit")
394_init_driver_fn_pointers()
396# =============================================================================
397# NVRTC function pointer initialization
398# =============================================================================
400cdef void* _get_nvrtc_fn(str name):
401 capsule = cynvrtc.__pyx_capi__[name]
402 return PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule))
404cdef void _init_nvrtc_fn_pointers() noexcept:
405 global p_nvrtcDestroyProgram
406 p_nvrtcDestroyProgram = _get_nvrtc_fn("nvrtcDestroyProgram")
408_init_nvrtc_fn_pointers()
410# =============================================================================
411# NVVM function pointer initialization
412#
413# NVVM may not be available at runtime, so we handle missing function pointers
414# gracefully. The C++ deleter checks for null before calling.
415# =============================================================================
417cdef void* _get_nvvm_fn(str name):
418 capsule = cynvvm.__pyx_capi__[name]
419 return PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule))
421cdef void _init_nvvm_fn_pointers() noexcept:
422 global p_nvvmDestroyProgram
423 p_nvvmDestroyProgram = _get_nvvm_fn("nvvmDestroyProgram")
425_init_nvvm_fn_pointers()
427# =============================================================================
428# nvJitLink function pointer initialization
429#
430# nvJitLink may not be available at runtime, so we handle missing function
431# pointers gracefully. The C++ deleter checks for null before calling.
432# =============================================================================
434cdef void* _get_nvjitlink_fn(str name):
435 capsule = cynvjitlink.__pyx_capi__[name]
436 return PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule))
438cdef void _init_nvjitlink_fn_pointers() noexcept:
439 global p_nvJitLinkDestroy
440 p_nvJitLinkDestroy = _get_nvjitlink_fn("nvJitLinkDestroy")
442_init_nvjitlink_fn_pointers()