Skip to content

Commit efa983c

Browse files
committed
Merge branch 'main' into path_finder_cont
2 parents b9f66be + db7c854 commit efa983c

15 files changed

+137
-42
lines changed

cuda_bindings/cuda/__init__.pxd

Whitespace-only changes.

cuda_bindings/cuda/__init__.py

-14
This file was deleted.

cuda_bindings/cuda/ccuda.pxd

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ from cuda.bindings.cydriver cimport *
22

33
cdef extern from *:
44
"""
5+
#ifdef _MSC_VER
56
#pragma message ( "The cuda.ccuda module is deprecated and will be removed in a future release, " \
67
"please switch to use the cuda.bindings.cydriver module instead." )
8+
#else
9+
#warning The cuda.ccuda module is deprecated and will be removed in a future release, \
10+
please switch to use the cuda.bindings.cydriver module instead.
11+
#endif
712
"""

cuda_bindings/cuda/ccuda.pyx

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
from cuda.bindings.cydriver cimport *
2-
3-
cdef extern from *:
4-
"""
5-
#pragma message ( "The cuda.ccuda module is deprecated and will be removed in a future release, " \
6-
"please switch to use the cuda.bindings.cydriver module instead." )
7-
"""
8-
9-
102
from cuda.bindings import cydriver
113
__pyx_capi__ = cydriver.__pyx_capi__
124
del cydriver

cuda_bindings/cuda/ccudart.pxd

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ from cuda.bindings.cyruntime cimport *
22

33
cdef extern from *:
44
"""
5+
#ifdef _MSC_VER
56
#pragma message ( "The cuda.ccudart module is deprecated and will be removed in a future release, " \
67
"please switch to use the cuda.bindings.cyruntime module instead." )
8+
#else
9+
#warning The cuda.ccudart module is deprecated and will be removed in a future release, \
10+
please switch to use the cuda.bindings.cyruntime module instead.
11+
#endif
712
"""

cuda_bindings/cuda/ccudart.pyx

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
from cuda.bindings.cyruntime cimport *
2-
3-
cdef extern from *:
4-
"""
5-
#pragma message ( "The cuda.ccudart module is deprecated and will be removed in a future release, " \
6-
"please switch to use the cuda.bindings.cyruntime module instead." )
7-
"""
8-
9-
102
from cuda.bindings import cyruntime
113
__pyx_capi__ = cyruntime.__pyx_capi__
124
del cyruntime

cuda_bindings/cuda/cnvrtc.pxd

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ from cuda.bindings.cynvrtc cimport *
22

33
cdef extern from *:
44
"""
5+
#ifdef _MSC_VER
56
#pragma message ( "The cuda.cnvrtc module is deprecated and will be removed in a future release, " \
67
"please switch to use the cuda.bindings.cynvrtc module instead." )
8+
#else
9+
#warning The cuda.cnvrtc module is deprecated and will be removed in a future release, \
10+
please switch to use the cuda.bindings.cynvrtc module instead.
11+
#endif
712
"""

cuda_bindings/cuda/cnvrtc.pyx

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
from cuda.bindings.cynvrtc cimport *
2-
3-
cdef extern from *:
4-
"""
5-
#pragma message ( "The cuda.cnvrtc module is deprecated and will be removed in a future release, " \
6-
"please switch to use the cuda.bindings.cynvrtc module instead." )
7-
"""
8-
9-
102
from cuda.bindings import cynvrtc
113
__pyx_capi__ = cynvrtc.__pyx_capi__
124
del cynvrtc

cuda_bindings/cuda/cuda.pyx

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ from cuda.bindings.driver import *
55

66
cdef extern from *:
77
"""
8+
#ifdef _MSC_VER
89
#pragma message ( "The cuda.cuda module is deprecated and will be removed in a future release, " \
910
"please switch to use the cuda.bindings.driver module instead." )
11+
#else
12+
#warning The cuda.cuda module is deprecated and will be removed in a future release, \
13+
please switch to use the cuda.bindings.driver module instead.
14+
#endif
1015
"""
1116

1217

1318
_warnings.warn("The cuda.cuda module is deprecated and will be removed in a future release, "
14-
"please switch to use the cuda.bindings.driver module instead.", DeprecationWarning, stacklevel=2)
19+
"please switch to use the cuda.bindings.driver module instead.", FutureWarning, stacklevel=2)

cuda_bindings/cuda/cudart.pyx

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ from cuda.bindings.runtime import *
55

66
cdef extern from *:
77
"""
8+
#ifdef _MSC_VER
89
#pragma message ( "The cuda.cudart module is deprecated and will be removed in a future release, " \
910
"please switch to use the cuda.bindings.runtime module instead." )
11+
#else
12+
#warning The cuda.cudart module is deprecated and will be removed in a future release, \
13+
please switch to use the cuda.bindings.runtime module instead.
14+
#endif
1015
"""
1116

1217

1318
_warnings.warn("The cuda.cudart module is deprecated and will be removed in a future release, "
14-
"please switch to use the cuda.bindings.runtime module instead.", DeprecationWarning, stacklevel=2)
19+
"please switch to use the cuda.bindings.runtime module instead.", FutureWarning, stacklevel=2)

cuda_bindings/cuda/nvrtc.pyx

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ from cuda.bindings.nvrtc import *
55

66
cdef extern from *:
77
"""
8+
#ifdef _MSC_VER
89
#pragma message ( "The cuda.nvrtc module is deprecated and will be removed in a future release, " \
910
"please switch to use the cuda.bindings.nvrtc module instead." )
11+
#else
12+
#warning The cuda.nvrtc module is deprecated and will be removed in a future release, \
13+
please switch to use the cuda.bindings.nvrtc module instead.
14+
#endif
1015
"""
1116

1217

1318
_warnings.warn("The cuda.nvrtc module is deprecated and will be removed in a future release, "
14-
"please switch to use the cuda.bindings.nvrtc module instead.", DeprecationWarning, stacklevel=2)
19+
"please switch to use the cuda.bindings.nvrtc module instead.", FutureWarning, stacklevel=2)

cuda_bindings/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ classifiers = [
2525
"Programming Language :: Python :: 3.10",
2626
"Programming Language :: Python :: 3.11",
2727
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
2829
"Environment :: GPU :: NVIDIA CUDA",
2930
]
3031
dynamic = [

cuda_bindings/setup.py

+74-1
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
@@ -10,6 +10,7 @@
1010
import contextlib
1111
import glob
1212
import os
13+
import pathlib
1314
import platform
1415
import shutil
1516
import sys
@@ -23,6 +24,8 @@
2324
from setuptools import find_packages, setup
2425
from setuptools.command.bdist_wheel import bdist_wheel
2526
from setuptools.command.build_ext import build_ext
27+
from setuptools.command.build_py import build_py
28+
from setuptools.command.editable_wheel import _TopLevelFinder, editable_wheel
2629
from setuptools.extension import Extension
2730

2831
# ----------------------------------------------------------------------
@@ -402,9 +405,79 @@ def build_extension(self, ext):
402405
super().build_extension(ext)
403406

404407

408+
################################################################################
409+
# Adapted from NVIDIA/numba-cuda
410+
# TODO: Remove this block once we get rid of cuda.__version__ and the .pth files
411+
412+
REDIRECTOR_PTH = "_cuda_bindings_redirector.pth"
413+
REDIRECTOR_PY = "_cuda_bindings_redirector.py"
414+
SITE_PACKAGES = pathlib.Path("site-packages")
415+
416+
417+
class build_py_with_redirector(build_py): # noqa: N801
418+
"""Include the redirector files in the generated wheel."""
419+
420+
def copy_redirector_file(self, source, destination="."):
421+
destination = pathlib.Path(self.build_lib) / destination
422+
self.copy_file(str(source), str(destination), preserve_mode=0)
423+
424+
def run(self):
425+
super().run()
426+
self.copy_redirector_file(SITE_PACKAGES / REDIRECTOR_PTH)
427+
self.copy_redirector_file(SITE_PACKAGES / REDIRECTOR_PY)
428+
429+
def get_source_files(self):
430+
src = super().get_source_files()
431+
src.extend(
432+
[
433+
str(SITE_PACKAGES / REDIRECTOR_PTH),
434+
str(SITE_PACKAGES / REDIRECTOR_PY),
435+
]
436+
)
437+
return src
438+
439+
def get_output_mapping(self):
440+
mapping = super().get_output_mapping()
441+
build_lib = pathlib.Path(self.build_lib)
442+
mapping[str(build_lib / REDIRECTOR_PTH)] = REDIRECTOR_PTH
443+
mapping[str(build_lib / REDIRECTOR_PY)] = REDIRECTOR_PY
444+
return mapping
445+
446+
447+
class TopLevelFinderWithRedirector(_TopLevelFinder):
448+
"""Include the redirector files in the editable wheel."""
449+
450+
def get_implementation(self):
451+
for item in super().get_implementation(): # noqa: UP028
452+
yield item
453+
454+
with open(SITE_PACKAGES / REDIRECTOR_PTH) as f:
455+
yield (REDIRECTOR_PTH, f.read())
456+
457+
with open(SITE_PACKAGES / REDIRECTOR_PY) as f:
458+
yield (REDIRECTOR_PY, f.read())
459+
460+
461+
class editable_wheel_with_redirector(editable_wheel):
462+
def _select_strategy(self, name, tag, build_lib):
463+
# The default mode is "lenient" - others are "strict" and "compat".
464+
# "compat" is deprecated. "strict" creates a tree of links to files in
465+
# the repo. It could be implemented, but we only handle the default
466+
# case for now.
467+
if self.mode is not None and self.mode != "lenient":
468+
raise RuntimeError(f"Only lenient mode is supported for editable install. Current mode is {self.mode}")
469+
470+
return TopLevelFinderWithRedirector(self.distribution, name)
471+
472+
473+
################################################################################
474+
475+
405476
cmdclass = {
406477
"bdist_wheel": WheelsBuildExtensions,
407478
"build_ext": ParallelBuildExtensions,
479+
"build_py": build_py_with_redirector,
480+
"editable_wheel": editable_wheel_with_redirector,
408481
}
409482

410483
# ----------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import _cuda_bindings_redirector
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2025 NVIDIA Corporation. All rights reserved.
2+
3+
import sys
4+
from types import ModuleType
5+
6+
7+
class LazyCudaModule(ModuleType):
8+
9+
def __getattr__(self, name):
10+
if name == '__version__':
11+
import warnings
12+
warnings.warn(
13+
"accessing cuda.__version__ is deprecated, " "please switch to use cuda.bindings.__version__ instead",
14+
FutureWarning,
15+
stacklevel=2,
16+
)
17+
from cuda.bindings import __version__
18+
19+
return __version__
20+
21+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
22+
23+
24+
# Important: We need to populate the cuda namespace module first, otherwise
25+
# we'd lose access to any of its submodules. This is a cheap op because there
26+
# is nothing under cuda.bindings.
27+
import cuda.bindings
28+
sys.modules['cuda'].__class__ = LazyCudaModule

0 commit comments

Comments
 (0)