Skip to content

Commit a5e28fd

Browse files
committed
Backport #914 and #894 to 12.9.x branch
1 parent 0831d1f commit a5e28fd

16 files changed

Lines changed: 550 additions & 564 deletions

File tree

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ cuda_bindings/cuda/bindings/_bindings/cynvrtc.pxd
2929
cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx
3030
cuda_bindings/cuda/bindings/_internal/nvjitlink.pyx
3131
cuda_bindings/cuda/bindings/_internal/nvvm.pyx
32-
cuda_bindings/cuda/bindings/_lib/cyruntime/cyruntime.pxd
33-
cuda_bindings/cuda/bindings/_lib/cyruntime/cyruntime.pyx
34-
cuda_bindings/cuda/bindings/_lib/cyruntime/utils.pxd
35-
cuda_bindings/cuda/bindings/_lib/cyruntime/utils.pyx
3632
cuda_bindings/cuda/bindings/_lib/utils.pxd
3733
cuda_bindings/cuda/bindings/_lib/utils.pyx
3834
cuda_bindings/cuda/bindings/cydriver.pxd
@@ -115,6 +111,7 @@ instance/
115111

116112
# Sphinx documentation
117113
docs_src/_build/
114+
*/docs/source/generated/
118115

119116
# PyBuilder
120117
.pybuilder/

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,8 @@ cdef bint __cuPythonInit = False
495495
ctypedef CUresult (*__cuGetProcAddress_v2_T)(const char*, void**, int, cuuint64_t, CUdriverProcAddressQueryResult*) except?CUDA_ERROR_NOT_FOUND nogil
496496
cdef __cuGetProcAddress_v2_T _F_cuGetProcAddress_v2 = NULL
497497

498-
cdef int cuPythonInit() except -1 nogil:
498+
cdef int _cuPythonInit() except -1 nogil:
499499
global __cuPythonInit
500-
if __cuPythonInit:
501-
return 0
502500

503501
cdef bint usePTDS
504502
cdef char libPath[260]
@@ -8946,6 +8944,13 @@ cdef int cuPythonInit() except -1 nogil:
89468944
__cuPythonInit = True
89478945
return 0
89488946

8947+
# Create a very small function to check whether we are init'ed, so the C
8948+
# compiler can inline it.
8949+
cdef inline int cuPythonInit() except -1 nogil:
8950+
if __cuPythonInit:
8951+
return 0
8952+
return _cuPythonInit()
8953+
89498954
{{if 'cuGetErrorString' in found_functions}}
89508955

89518956
cdef CUresult _cuGetErrorString(CUresult error, const char** pStr) except ?CUDA_ERROR_NOT_FOUND nogil:

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ cdef bint __cuPythonInit = False
4242
{{if 'nvrtcGetPCHHeapSizeRequired' in found_functions}}cdef void *__nvrtcGetPCHHeapSizeRequired = NULL{{endif}}
4343
{{if 'nvrtcSetFlowCallback' in found_functions}}cdef void *__nvrtcSetFlowCallback = NULL{{endif}}
4444

45-
cdef int cuPythonInit() except -1 nogil:
45+
cdef int _cuPythonInit() except -1 nogil:
4646
global __cuPythonInit
47-
if __cuPythonInit:
48-
return 0
4947

5048
# Load library
5149
with gil, __symbol_lock:
@@ -349,6 +347,13 @@ cdef int cuPythonInit() except -1 nogil:
349347
__cuPythonInit = True
350348
return 0
351349

350+
# Create a very small function to check whether we are init'ed, so the C
351+
# compiler can inline it.
352+
cdef inline int cuPythonInit() except -1 nogil:
353+
if __cuPythonInit:
354+
return 0
355+
return _cuPythonInit()
356+
352357
{{if 'nvrtcGetErrorString' in found_functions}}
353358

354359
cdef const char* _nvrtcGetErrorString(nvrtcResult result) except ?NULL nogil:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# This code was automatically generated with version 12.9.0. Do not modify it directly.
55
include "../cyruntime_types.pxi"
66

7+
include "../_lib/cyruntime/cyruntime.pxd"
8+
79
{{if 'cudaDeviceReset' in found_functions}}
810

911
cdef cudaError_t _cudaDeviceReset() except ?cudaErrorCallRequiresNewerDriver nogil

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ cimport cython
1010

1111
cdef bint __cudaPythonInit = False
1212
cdef bint __usePTDS = False
13-
cdef int cudaPythonInit() except -1 nogil:
13+
cdef int _cudaPythonInit() except -1 nogil:
1414
global __cudaPythonInit
1515
global __usePTDS
16-
if __cudaPythonInit:
17-
return __usePTDS
16+
1817
with gil:
1918
__usePTDS = os.getenv('CUDA_PYTHON_CUDA_PER_THREAD_DEFAULT_STREAM', default=False)
2019
__cudaPythonInit = True
2120
return __usePTDS
2221

22+
# Create a very small function to check whether we are init'ed, so the C
23+
# compiler can inline it.
24+
cdef inline int cudaPythonInit() except -1 nogil:
25+
if __cudaPythonInit:
26+
return __usePTDS
27+
return _cudaPythonInit()
28+
2329
{{if 'cudaDeviceReset' in found_functions}}
2430

2531
cdef cudaError_t _cudaDeviceReset() except ?cudaErrorCallRequiresNewerDriver nogil:
@@ -2647,3 +2653,6 @@ cdef cudaError_t _cudaProfilerStop() except ?cudaErrorCallRequiresNewerDriver no
26472653
return ptds._cudaProfilerStop()
26482654
return cudaProfilerStop()
26492655
{{endif}}
2656+
2657+
2658+
include "../_lib/cyruntime/cyruntime.pxi"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
cimport cuda.bindings.cyruntime as cyruntime
5+
cimport cuda.bindings._bindings.cydriver as _cydriver
6+
7+
# These graphics API are the reimplemented version of what's supported by CUDA Runtime.
8+
# Issue https://github.com/NVIDIA/cuda-python/issues/488 will remove them by letting us
9+
# use call into the static library directly.
10+
#
11+
# This is an ABI breaking change which can only happen in a major version bump.
12+
13+
# This file is included from cuda/bindings/_bindings/cyruntime.pxd.in but kept in a
14+
# separate file to keep it separated from the auto-generated code there.
15+
16+
# Prior to https://github.com/NVIDIA/cuda-python/pull/914, this was two
17+
# independent modules (c.b._lib.cyruntime.cyruntime and
18+
# c.b._lib.cyruntime.utils), but was merged into one.
19+
20+
cdef cudaError_t _cudaEGLStreamProducerPresentFrame(cyruntime.cudaEglStreamConnection* conn, cyruntime.cudaEglFrame eglframe, cudaStream_t* pStream) except ?cudaErrorCallRequiresNewerDriver nogil
21+
cdef cudaError_t _cudaEGLStreamProducerReturnFrame(cyruntime.cudaEglStreamConnection* conn, cyruntime.cudaEglFrame* eglframe, cudaStream_t* pStream) except ?cudaErrorCallRequiresNewerDriver nogil
22+
cdef cudaError_t _cudaGraphicsResourceGetMappedEglFrame(cyruntime.cudaEglFrame* eglFrame, cudaGraphicsResource_t resource, unsigned int index, unsigned int mipLevel) except ?cudaErrorCallRequiresNewerDriver nogil
23+
cdef cudaError_t _cudaVDPAUSetVDPAUDevice(int device, cyruntime.VdpDevice vdpDevice, cyruntime.VdpGetProcAddress* vdpGetProcAddress) except ?cudaErrorCallRequiresNewerDriver nogil
24+
cdef cudaError_t _cudaVDPAUGetDevice(int* device, cyruntime.VdpDevice vdpDevice, cyruntime.VdpGetProcAddress* vdpGetProcAddress) except ?cudaErrorCallRequiresNewerDriver nogil
25+
cdef cudaError_t _cudaGraphicsVDPAURegisterVideoSurface(cudaGraphicsResource** resource, cyruntime.VdpVideoSurface vdpSurface, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
26+
cdef cudaError_t _cudaGraphicsVDPAURegisterOutputSurface(cudaGraphicsResource** resource, cyruntime.VdpOutputSurface vdpSurface, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
27+
cdef cudaError_t _cudaGLGetDevices(unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int cudaDeviceCount, cyruntime.cudaGLDeviceList deviceList) except ?cudaErrorCallRequiresNewerDriver nogil
28+
cdef cudaError_t _cudaGraphicsGLRegisterImage(cudaGraphicsResource** resource, cyruntime.GLuint image, cyruntime.GLenum target, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
29+
cdef cudaError_t _cudaGraphicsGLRegisterBuffer(cudaGraphicsResource** resource, cyruntime.GLuint buffer, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
30+
cdef cudaError_t _cudaGraphicsEGLRegisterImage(cudaGraphicsResource_t* pCudaResource, cyruntime.EGLImageKHR image, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
31+
cdef cudaError_t _cudaEGLStreamConsumerConnect(cyruntime.cudaEglStreamConnection* conn, cyruntime.EGLStreamKHR eglStream) except ?cudaErrorCallRequiresNewerDriver nogil
32+
cdef cudaError_t _cudaEGLStreamConsumerConnectWithFlags(cyruntime.cudaEglStreamConnection* conn, cyruntime.EGLStreamKHR eglStream, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
33+
cdef cudaError_t _cudaEGLStreamConsumerDisconnect(cyruntime.cudaEglStreamConnection* conn) except ?cudaErrorCallRequiresNewerDriver nogil
34+
cdef cudaError_t _cudaEGLStreamConsumerAcquireFrame(cyruntime.cudaEglStreamConnection* conn, cudaGraphicsResource_t* pCudaResource, cudaStream_t* pStream, unsigned int timeout) except ?cudaErrorCallRequiresNewerDriver nogil
35+
cdef cudaError_t _cudaEGLStreamConsumerReleaseFrame(cyruntime.cudaEglStreamConnection* conn, cudaGraphicsResource_t pCudaResource, cudaStream_t* pStream) except ?cudaErrorCallRequiresNewerDriver nogil
36+
cdef cudaError_t _cudaEGLStreamProducerConnect(cyruntime.cudaEglStreamConnection* conn, cyruntime.EGLStreamKHR eglStream, cyruntime.EGLint width, cyruntime.EGLint height) except ?cudaErrorCallRequiresNewerDriver nogil
37+
cdef cudaError_t _cudaEGLStreamProducerDisconnect(cyruntime.cudaEglStreamConnection* conn) except ?cudaErrorCallRequiresNewerDriver nogil
38+
cdef cudaError_t _cudaEventCreateFromEGLSync(cudaEvent_t* phEvent, cyruntime.EGLSyncKHR eglSync, unsigned int flags) except ?cudaErrorCallRequiresNewerDriver nogil
39+
40+
# utility functions
41+
42+
cdef cudaError_t getDriverEglFrame(_cydriver.CUeglFrame *cuEglFrame, cyruntime.cudaEglFrame eglFrame) except ?cudaErrorCallRequiresNewerDriver nogil
43+
cdef cudaError_t getRuntimeEglFrame(cyruntime.cudaEglFrame *eglFrame, _cydriver.CUeglFrame cueglFrame) except ?cudaErrorCallRequiresNewerDriver nogil

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)