Skip to content

Commit be6f948

Browse files
committed
Remove callback wrappers for Driver
1 parent 776e762 commit be6f948

15 files changed

Lines changed: 41 additions & 132 deletions

cuda_bindings/cuda/bindings/_bindings/cydriver.pxd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of

cuda_bindings/cuda/bindings/_bindings/cydriver.pyx.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of

cuda_bindings/cuda/bindings/_bindings/cynvrtc.pxd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of

cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of

cuda_bindings/cuda/bindings/_lib/cyruntime/cyruntime.pxd.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# is strictly prohibited.
88
from cuda.bindings.cyruntime cimport *
99

10+
# These graphics API are the reimplemented version of what's supported by CUDA Runtime.
11+
# Issue https://github.com/NVIDIA/cuda-python/issues/488 will remove them by letting us
12+
# use call into the static library directly.
13+
#
14+
# This is an ABI breaking change which can only happen in a major version bump.
1015
{{if True}}cdef cudaError_t _cudaEGLStreamProducerPresentFrame(cudaEglStreamConnection* conn, cudaEglFrame eglframe, cudaStream_t* pStream) except ?cudaErrorCallRequiresNewerDriver nogil{{endif}}
1116
{{if True}}cdef cudaError_t _cudaEGLStreamProducerReturnFrame(cudaEglStreamConnection* conn, cudaEglFrame* eglframe, cudaStream_t* pStream) except ?cudaErrorCallRequiresNewerDriver nogil{{endif}}
1217
{{if True}}cdef cudaError_t _cudaGraphicsResourceGetMappedEglFrame(cudaEglFrame* eglFrame, cudaGraphicsResource_t resource, unsigned int index, unsigned int mipLevel) except ?cudaErrorCallRequiresNewerDriver nogil{{endif}}

cuda_bindings/cuda/bindings/_lib/cyruntime/utils.pxd.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
from cuda.bindings.cyruntime cimport *
99
cimport cuda.bindings._bindings.cydriver as cydriver
1010

11+
# These are hard-coded helper function from the initial reimplementation of CUDA Runtime
12+
# and will be removed as part of https://github.com/NVIDIA/cuda-python/issues/488
1113
cdef cudaError_t getDriverEglFrame(cydriver.CUeglFrame *cuEglFrame, cudaEglFrame eglFrame) except ?cudaErrorCallRequiresNewerDriver nogil
1214
cdef cudaError_t getRuntimeEglFrame(cudaEglFrame *eglFrame, cydriver.CUeglFrame cueglFrame) except ?cudaErrorCallRequiresNewerDriver nogil

cuda_bindings/cuda/bindings/cydriver.pyx.in

Lines changed: 4 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -602,47 +602,14 @@ cdef CUresult cuMemAllocManaged(CUdeviceptr* dptr, size_t bytesize, unsigned int
602602

603603
{{if 'cuDeviceRegisterAsyncNotification' in found_functions}}
604604

605-
ctypedef struct cuAsyncCallbackData_st:
606-
CUasyncCallback callback
607-
void *userData
608-
609-
ctypedef cuAsyncCallbackData_st cuAsyncCallbackData
610-
611-
@cython.show_performance_hints(False)
612-
cdef void cuAsyncNotificationCallbackWrapper(CUasyncNotificationInfo *info, void *data, CUasyncCallbackHandle handle) nogil:
613-
cdef cuAsyncCallbackData *cbData = <cuAsyncCallbackData *>data
614-
with gil:
615-
cbData.callback(info, cbData.userData, handle)
616-
617-
618605
cdef CUresult cuDeviceRegisterAsyncNotification(CUdevice device, CUasyncCallback callbackFunc, void* userData, CUasyncCallbackHandle* callback) except ?CUDA_ERROR_NOT_FOUND nogil:
619-
cdef cuAsyncCallbackData *cbData = NULL
620-
cdef CUresult err = CUDA_SUCCESS
621-
cbData = <cuAsyncCallbackData *>malloc(sizeof(cbData[0]))
622-
623-
if cbData == NULL:
624-
return CUDA_ERROR_OUT_OF_MEMORY
625-
626-
cbData.callback = callbackFunc
627-
cbData.userData = userData
628-
err = cydriver._cuDeviceRegisterAsyncNotification(device, <CUasyncCallback>cuAsyncNotificationCallbackWrapper, <void *>cbData, callback)
629-
if err != CUDA_SUCCESS:
630-
free(cbData)
631-
return err
632-
633-
m_global._asyncCallbackDataMap[callback[0]] = cbData
634-
return err
606+
return cydriver._cuDeviceRegisterAsyncNotification(device, callbackFunc, userData, callback)
635607
{{endif}}
636608

637609
{{if 'cuDeviceUnregisterAsyncNotification' in found_functions}}
638610

639611
cdef CUresult cuDeviceUnregisterAsyncNotification(CUdevice device, CUasyncCallbackHandle callback) except ?CUDA_ERROR_NOT_FOUND nogil:
640-
cdef CUresult err = CUDA_SUCCESS
641-
err = cydriver._cuDeviceUnregisterAsyncNotification(device, callback)
642-
if err == CUDA_SUCCESS:
643-
free(m_global._asyncCallbackDataMap[callback])
644-
m_global._asyncCallbackDataMap.erase(callback)
645-
return err
612+
return cydriver._cuDeviceUnregisterAsyncNotification(device, callback)
646613
{{endif}}
647614

648615
{{if 'cuDeviceGetByPCIBusId' in found_functions}}
@@ -1331,35 +1298,8 @@ cdef CUresult cuStreamWaitEvent(CUstream hStream, CUevent hEvent, unsigned int F
13311298

13321299
{{if 'cuStreamAddCallback' in found_functions}}
13331300

1334-
ctypedef struct cuStreamCallbackData_st:
1335-
CUstreamCallback callback
1336-
void *userData
1337-
1338-
ctypedef cuStreamCallbackData_st cuStreamCallbackData
1339-
1340-
@cython.show_performance_hints(False)
1341-
cdef void cuStreamCallbackWrapper(CUstream stream, CUresult status, void *data) nogil:
1342-
cdef cuStreamCallbackData *cbData = <cuStreamCallbackData *>data
1343-
with gil:
1344-
cbData.callback(stream, status, cbData.userData)
1345-
free(cbData)
1346-
1347-
13481301
cdef CUresult cuStreamAddCallback(CUstream hStream, CUstreamCallback callback, void* userData, unsigned int flags) except ?CUDA_ERROR_NOT_FOUND nogil:
1349-
cdef cuStreamCallbackData *cbData = NULL
1350-
cdef CUresult err = CUDA_SUCCESS
1351-
cbData = <cuStreamCallbackData *>malloc(sizeof(cbData[0]))
1352-
1353-
if cbData == NULL:
1354-
return CUDA_ERROR_OUT_OF_MEMORY
1355-
1356-
cbData.callback = callback
1357-
cbData.userData = userData
1358-
err = cydriver._cuStreamAddCallback(hStream, <CUstreamCallback>cuStreamCallbackWrapper, <void *>cbData, flags)
1359-
if err != CUDA_SUCCESS:
1360-
free(cbData)
1361-
return err
1362-
return err
1302+
return cydriver._cuStreamAddCallback(hStream, callback, userData, flags)
13631303
{{endif}}
13641304

13651305
{{if 'cuStreamBeginCapture_v2' in found_functions}}
@@ -1658,35 +1598,8 @@ cdef CUresult cuLaunchCooperativeKernelMultiDevice(CUDA_LAUNCH_PARAMS* launchPar
16581598

16591599
{{if 'cuLaunchHostFunc' in found_functions}}
16601600

1661-
ctypedef struct cuHostCallbackData_st:
1662-
CUhostFn callback
1663-
void *userData
1664-
1665-
ctypedef cuHostCallbackData_st cuHostCallbackData
1666-
1667-
@cython.show_performance_hints(False)
1668-
cdef void cuHostCallbackWrapper(void *data) nogil:
1669-
cdef cuHostCallbackData *cbData = <cuHostCallbackData *>data
1670-
with gil:
1671-
cbData.callback(cbData.userData)
1672-
free(cbData)
1673-
1674-
16751601
cdef CUresult cuLaunchHostFunc(CUstream hStream, CUhostFn fn, void* userData) except ?CUDA_ERROR_NOT_FOUND nogil:
1676-
cdef cuHostCallbackData *cbData = NULL
1677-
cdef CUresult err = CUDA_SUCCESS
1678-
cbData = <cuHostCallbackData *>malloc(sizeof(cbData[0]))
1679-
1680-
if cbData == NULL:
1681-
return CUDA_ERROR_OUT_OF_MEMORY
1682-
1683-
cbData.callback = fn
1684-
cbData.userData = userData
1685-
err = cydriver._cuLaunchHostFunc(hStream, <CUhostFn>cuHostCallbackWrapper, <void *>cbData)
1686-
if err != CUDA_SUCCESS:
1687-
free(cbData)
1688-
return err
1689-
return err
1602+
return cydriver._cuLaunchHostFunc(hStream, fn, userData)
16901603
{{endif}}
16911604

16921605
{{if 'cuFuncSetBlockShape' in found_functions}}
@@ -2908,17 +2821,3 @@ cdef CUresult cuGraphicsVDPAURegisterOutputSurface(CUgraphicsResource* pCudaReso
29082821
{{endif}}
29092822

29102823

2911-
cdef class cudaBindingsDriverGlobal:
2912-
{{if 'cuDeviceRegisterAsyncNotification' in found_functions}}
2913-
cdef map[CUasyncCallbackHandle, cuAsyncCallbackData*] _asyncCallbackDataMap
2914-
{{endif}}
2915-
2916-
def __dealloc__(self):
2917-
pass
2918-
{{if 'cuDeviceRegisterAsyncNotification' in found_functions}}
2919-
for item_asyncCallbackDataMap in self._asyncCallbackDataMap:
2920-
free(item_asyncCallbackDataMap.second)
2921-
self._asyncCallbackDataMap.clear()
2922-
{{endif}}
2923-
2924-
cdef cudaBindingsDriverGlobal m_global = cudaBindingsDriverGlobal()

cuda_bindings/cuda/bindings/cynvrtc.pxd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of

cuda_bindings/cuda/bindings/cynvrtc.pyx.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of
@@ -7,6 +7,9 @@
77
# is strictly prohibited.
88
#
99
# This code was automatically generated with version 12.8.0. Do not modify it directly.
10+
import cython
11+
from libcpp.map cimport map
12+
from libc.stdlib cimport malloc, free
1013
cimport cuda.bindings._bindings.cynvrtc as cynvrtc
1114

1215
{{if 'nvrtcGetErrorString' in found_functions}}
@@ -164,3 +167,5 @@ cdef nvrtcResult nvrtcGetPCHHeapSizeRequired(nvrtcProgram prog, size_t* size) ex
164167
cdef nvrtcResult nvrtcSetFlowCallback(nvrtcProgram prog, void* callback, void* payload) except ?NVRTC_ERROR_INVALID_INPUT nogil:
165168
return cynvrtc._nvrtcSetFlowCallback(prog, callback, payload)
166169
{{endif}}
170+
171+

cuda_bindings/cuda/bindings/driver.pxd.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2024 NVIDIA Corporation. All rights reserved.
1+
# Copyright 2021-2025 NVIDIA Corporation. All rights reserved.
22
#
33
# Please refer to the NVIDIA end user license agreement (EULA) associated
44
# with this source code for terms and conditions that govern your use of

0 commit comments

Comments
 (0)