Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions cuda_bindings/cuda/bindings/driver.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -53948,3 +53948,125 @@ def sizeof(objType):
if objType == VdpOutputSurface:
return sizeof(cydriver.VdpOutputSurface){{endif}}
raise TypeError("Unknown type: " + str(objType))

cdef int _add_native_handle_getters() except?-1:
from cuda.bindings.utils import _add_cuda_native_handle_getter
{{if 'CUcontext' in found_types}}
def CUcontext_getter(CUcontext x): return <uintptr_t><void*><cydriver.CUcontext>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUcontext, CUcontext_getter)
{{endif}}
{{if 'CUmodule' in found_types}}
def CUmodule_getter(CUmodule x): return <uintptr_t><void*><cydriver.CUmodule>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUmodule, CUmodule_getter)
{{endif}}
{{if 'CUfunction' in found_types}}
def CUfunction_getter(CUfunction x): return <uintptr_t><void*><cydriver.CUfunction>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUfunction, CUfunction_getter)
{{endif}}
{{if 'CUlibrary' in found_types}}
def CUlibrary_getter(CUlibrary x): return <uintptr_t><void*><cydriver.CUlibrary>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUlibrary, CUlibrary_getter)
{{endif}}
{{if 'CUkernel' in found_types}}
def CUkernel_getter(CUkernel x): return <uintptr_t><void*><cydriver.CUkernel>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUkernel, CUkernel_getter)
{{endif}}
{{if 'CUarray' in found_types}}
def CUarray_getter(CUarray x): return <uintptr_t><void*><cydriver.CUarray>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUarray, CUarray_getter)
{{endif}}
{{if 'CUmipmappedArray' in found_types}}
def CUmipmappedArray_getter(CUmipmappedArray x): return <uintptr_t><void*><cydriver.CUmipmappedArray>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUmipmappedArray, CUmipmappedArray_getter)
{{endif}}
{{if 'CUtexref' in found_types}}
def CUtexref_getter(CUtexref x): return <uintptr_t><void*><cydriver.CUtexref>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUtexref, CUtexref_getter)
{{endif}}
{{if 'CUsurfref' in found_types}}
def CUsurfref_getter(CUsurfref x): return <uintptr_t><void*><cydriver.CUsurfref>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUsurfref, CUsurfref_getter)
{{endif}}
{{if 'CUevent' in found_types}}
def CUevent_getter(CUevent x): return <uintptr_t><void*><cydriver.CUevent>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUevent, CUevent_getter)
{{endif}}
{{if 'CUstream' in found_types}}
def CUstream_getter(CUstream x): return <uintptr_t><void*><cydriver.CUstream>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUstream, CUstream_getter)
{{endif}}
{{if 'CUgraphicsResource' in found_types}}
def CUgraphicsResource_getter(CUgraphicsResource x): return <uintptr_t><void*><cydriver.CUgraphicsResource>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUgraphicsResource, CUgraphicsResource_getter)
{{endif}}
{{if 'CUexternalMemory' in found_types}}
def CUexternalMemory_getter(CUexternalMemory x): return <uintptr_t><void*><cydriver.CUexternalMemory>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUexternalMemory, CUexternalMemory_getter)
{{endif}}
{{if 'CUexternalSemaphore' in found_types}}
def CUexternalSemaphore_getter(CUexternalSemaphore x): return <uintptr_t><void*><cydriver.CUexternalSemaphore>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUexternalSemaphore, CUexternalSemaphore_getter)
{{endif}}
{{if 'CUgraph' in found_types}}
def CUgraph_getter(CUgraph x): return <uintptr_t><void*><cydriver.CUgraph>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUgraph, CUgraph_getter)
{{endif}}
{{if 'CUgraphNode' in found_types}}
def CUgraphNode_getter(CUgraphNode x): return <uintptr_t><void*><cydriver.CUgraphNode>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUgraphNode, CUgraphNode_getter)
{{endif}}
{{if 'CUgraphExec' in found_types}}
def CUgraphExec_getter(CUgraphExec x): return <uintptr_t><void*><cydriver.CUgraphExec>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUgraphExec, CUgraphExec_getter)
{{endif}}
{{if 'CUmemoryPool' in found_types}}
def CUmemoryPool_getter(CUmemoryPool x): return <uintptr_t><void*><cydriver.CUmemoryPool>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUmemoryPool, CUmemoryPool_getter)
{{endif}}
{{if 'CUuserObject' in found_types}}
def CUuserObject_getter(CUuserObject x): return <uintptr_t><void*><cydriver.CUuserObject>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUuserObject, CUuserObject_getter)
{{endif}}
{{if 'CUgraphDeviceNode' in found_types}}
def CUgraphDeviceNode_getter(CUgraphDeviceNode x): return <uintptr_t><void*><cydriver.CUgraphDeviceNode>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUgraphDeviceNode, CUgraphDeviceNode_getter)
{{endif}}
{{if 'CUasyncCallbackHandle' in found_types}}
def CUasyncCallbackHandle_getter(CUasyncCallbackHandle x): return <uintptr_t><void*><cydriver.CUasyncCallbackHandle>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUasyncCallbackHandle, CUasyncCallbackHandle_getter)
{{endif}}
{{if 'CUgreenCtx' in found_types}}
def CUgreenCtx_getter(CUgreenCtx x): return <uintptr_t><void*><cydriver.CUgreenCtx>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUgreenCtx, CUgreenCtx_getter)
{{endif}}
{{if 'CUlinkState' in found_types}}
def CUlinkState_getter(CUlinkState x): return <uintptr_t><void*><cydriver.CUlinkState>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUlinkState, CUlinkState_getter)
{{endif}}
{{if 'CUdevResourceDesc' in found_types}}
def CUdevResourceDesc_getter(CUdevResourceDesc x): return <uintptr_t><void*><cydriver.CUdevResourceDesc>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUdevResourceDesc, CUdevResourceDesc_getter)
{{endif}}
{{if 'CUlogsCallbackHandle' in found_types}}
def CUlogsCallbackHandle_getter(CUlogsCallbackHandle x): return <uintptr_t><void*><cydriver.CUlogsCallbackHandle>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUlogsCallbackHandle, CUlogsCallbackHandle_getter)
{{endif}}
{{if True}}
def CUeglStreamConnection_getter(CUeglStreamConnection x): return <uintptr_t><void*><cydriver.CUeglStreamConnection>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(CUeglStreamConnection, CUeglStreamConnection_getter)
{{endif}}
{{if True}}
def EGLImageKHR_getter(EGLImageKHR x): return <uintptr_t><void*><cydriver.EGLImageKHR>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(EGLImageKHR, EGLImageKHR_getter)
{{endif}}
{{if True}}
def EGLStreamKHR_getter(EGLStreamKHR x): return <uintptr_t><void*><cydriver.EGLStreamKHR>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(EGLStreamKHR, EGLStreamKHR_getter)
{{endif}}
{{if True}}
def EGLSyncKHR_getter(EGLSyncKHR x): return <uintptr_t><void*><cydriver.EGLSyncKHR>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(EGLSyncKHR, EGLSyncKHR_getter)
{{endif}}
return 0
_add_native_handle_getters()

102 changes: 102 additions & 0 deletions cuda_bindings/cuda/bindings/runtime.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -37912,3 +37912,105 @@ def sizeof(objType):
if objType == cudaEglStreamConnection:
return sizeof(cyruntime.cudaEglStreamConnection){{endif}}
raise TypeError("Unknown type: " + str(objType))

cdef int _add_native_handle_getters() except?-1:
from cuda.bindings.utils import _add_cuda_native_handle_getter
{{if 'cudaArray_t' in found_types}}
def cudaArray_t_getter(cudaArray_t x): return <uintptr_t><void*><cyruntime.cudaArray_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaArray_t, cudaArray_t_getter)
{{endif}}
{{if 'cudaArray_const_t' in found_types}}
def cudaArray_const_t_getter(cudaArray_const_t x): return <uintptr_t><void*><cyruntime.cudaArray_const_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaArray_const_t, cudaArray_const_t_getter)
{{endif}}
{{if 'cudaMipmappedArray_t' in found_types}}
def cudaMipmappedArray_t_getter(cudaMipmappedArray_t x): return <uintptr_t><void*><cyruntime.cudaMipmappedArray_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaMipmappedArray_t, cudaMipmappedArray_t_getter)
{{endif}}
{{if 'cudaMipmappedArray_const_t' in found_types}}
def cudaMipmappedArray_const_t_getter(cudaMipmappedArray_const_t x): return <uintptr_t><void*><cyruntime.cudaMipmappedArray_const_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaMipmappedArray_const_t, cudaMipmappedArray_const_t_getter)
{{endif}}
{{if 'cudaStream_t' in found_types}}
def cudaStream_t_getter(cudaStream_t x): return <uintptr_t><void*><cyruntime.cudaStream_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaStream_t, cudaStream_t_getter)
{{endif}}
{{if 'cudaEvent_t' in found_types}}
def cudaEvent_t_getter(cudaEvent_t x): return <uintptr_t><void*><cyruntime.cudaEvent_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaEvent_t, cudaEvent_t_getter)
{{endif}}
{{if 'cudaGraphicsResource_t' in found_types}}
def cudaGraphicsResource_t_getter(cudaGraphicsResource_t x): return <uintptr_t><void*><cyruntime.cudaGraphicsResource_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaGraphicsResource_t, cudaGraphicsResource_t_getter)
{{endif}}
{{if 'cudaExternalMemory_t' in found_types}}
def cudaExternalMemory_t_getter(cudaExternalMemory_t x): return <uintptr_t><void*><cyruntime.cudaExternalMemory_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaExternalMemory_t, cudaExternalMemory_t_getter)
{{endif}}
{{if 'cudaExternalSemaphore_t' in found_types}}
def cudaExternalSemaphore_t_getter(cudaExternalSemaphore_t x): return <uintptr_t><void*><cyruntime.cudaExternalSemaphore_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaExternalSemaphore_t, cudaExternalSemaphore_t_getter)
{{endif}}
{{if 'cudaGraph_t' in found_types}}
def cudaGraph_t_getter(cudaGraph_t x): return <uintptr_t><void*><cyruntime.cudaGraph_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaGraph_t, cudaGraph_t_getter)
{{endif}}
{{if 'cudaGraphNode_t' in found_types}}
def cudaGraphNode_t_getter(cudaGraphNode_t x): return <uintptr_t><void*><cyruntime.cudaGraphNode_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaGraphNode_t, cudaGraphNode_t_getter)
{{endif}}
{{if 'cudaUserObject_t' in found_types}}
def cudaUserObject_t_getter(cudaUserObject_t x): return <uintptr_t><void*><cyruntime.cudaUserObject_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaUserObject_t, cudaUserObject_t_getter)
{{endif}}
{{if 'cudaFunction_t' in found_types}}
def cudaFunction_t_getter(cudaFunction_t x): return <uintptr_t><void*><cyruntime.cudaFunction_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaFunction_t, cudaFunction_t_getter)
{{endif}}
{{if 'cudaKernel_t' in found_types}}
def cudaKernel_t_getter(cudaKernel_t x): return <uintptr_t><void*><cyruntime.cudaKernel_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaKernel_t, cudaKernel_t_getter)
{{endif}}
{{if 'cudaLibrary_t' in found_types}}
def cudaLibrary_t_getter(cudaLibrary_t x): return <uintptr_t><void*><cyruntime.cudaLibrary_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaLibrary_t, cudaLibrary_t_getter)
{{endif}}
{{if 'cudaMemPool_t' in found_types}}
def cudaMemPool_t_getter(cudaMemPool_t x): return <uintptr_t><void*><cyruntime.cudaMemPool_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaMemPool_t, cudaMemPool_t_getter)
{{endif}}
{{if 'cudaGraphExec_t' in found_types}}
def cudaGraphExec_t_getter(cudaGraphExec_t x): return <uintptr_t><void*><cyruntime.cudaGraphExec_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaGraphExec_t, cudaGraphExec_t_getter)
{{endif}}
{{if 'cudaGraphDeviceNode_t' in found_types}}
def cudaGraphDeviceNode_t_getter(cudaGraphDeviceNode_t x): return <uintptr_t><void*><cyruntime.cudaGraphDeviceNode_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaGraphDeviceNode_t, cudaGraphDeviceNode_t_getter)
{{endif}}
{{if 'cudaAsyncCallbackHandle_t' in found_types}}
def cudaAsyncCallbackHandle_t_getter(cudaAsyncCallbackHandle_t x): return <uintptr_t><void*><cyruntime.cudaAsyncCallbackHandle_t>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaAsyncCallbackHandle_t, cudaAsyncCallbackHandle_t_getter)
{{endif}}
{{if 'cudaLogsCallbackHandle' in found_types}}
def cudaLogsCallbackHandle_getter(cudaLogsCallbackHandle x): return <uintptr_t><void*><cyruntime.cudaLogsCallbackHandle>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaLogsCallbackHandle, cudaLogsCallbackHandle_getter)
{{endif}}
{{if True}}
def EGLImageKHR_getter(EGLImageKHR x): return <uintptr_t><void*><cyruntime.EGLImageKHR>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(EGLImageKHR, EGLImageKHR_getter)
{{endif}}
{{if True}}
def EGLStreamKHR_getter(EGLStreamKHR x): return <uintptr_t><void*><cyruntime.EGLStreamKHR>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(EGLStreamKHR, EGLStreamKHR_getter)
{{endif}}
{{if True}}
def EGLSyncKHR_getter(EGLSyncKHR x): return <uintptr_t><void*><cyruntime.EGLSyncKHR>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(EGLSyncKHR, EGLSyncKHR_getter)
{{endif}}
{{if True}}
def cudaEglStreamConnection_getter(cudaEglStreamConnection x): return <uintptr_t><void*><cyruntime.cudaEglStreamConnection>(x._pvt_ptr[0])
_add_cuda_native_handle_getter(cudaEglStreamConnection, cudaEglStreamConnection_getter)
{{endif}}
return 0
_add_native_handle_getters()

28 changes: 27 additions & 1 deletion cuda_bindings/cuda/bindings/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

from ._get_handle import get_cuda_native_handle
from typing import Any, Callable

from ._ptx_utils import get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver

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


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


def get_cuda_native_handle(obj: Any) -> int:
"""Returns the address of the provided CUDA Python object as a Python int.
Parameters
----------
obj : Any
CUDA Python object
Returns
-------
int : The object address.
"""
obj_type = type(obj)
try:
return _handle_getters[obj_type](obj)
except KeyError:
raise TypeError("Unknown type: " + str(obj_type)) from None
Loading
Loading