Skip to content

Commit 3e7b711

Browse files
authored
Merge branch 'main' into enable-secret-scan
2 parents ff758ac + c918891 commit 3e7b711

51 files changed

Lines changed: 4697 additions & 551 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cuda_bindings/AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ subpackage in the `cuda-python` monorepo.
4242
- **Examples**: example coverage is pytest-based under `examples/`.
4343
- **Benchmarks**: run with `pytest --benchmark-only benchmarks/` when needed.
4444

45+
The `legacy_tests` subdirectory tests the old pre-v2 APIs of `driver`, `runtime`
46+
and `nvrtc`. These test files should not be added to, only updated when
47+
necessary to fix test failures. The canonical set of tests are those outside of
48+
the `legacy_tests` subdirectory.
49+
4550
## Build and environment notes
4651

4752
- `CUDA_HOME` or `CUDA_PATH` must point to a valid CUDA Toolkit for source

cuda_bindings/build_hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _cleanup_dst_files():
196196

197197
# Build extension list
198198
extensions = []
199-
cuda_bindings_files = glob.glob("cuda/bindings/*.pyx")
199+
cuda_bindings_files = glob.glob("cuda/bindings/*.pyx") + glob.glob("cuda/bindings/_v2/*.pyx")
200200
if sys.platform == "win32":
201201
cuda_bindings_files = [f for f in cuda_bindings_files if "cufile" not in f]
202202

cuda_bindings/cuda/bindings/_example_helpers/common.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
from cuda import pathfinder
1111
from cuda.bindings import driver as cuda
12-
from cuda.bindings import nvrtc
1312
from cuda.bindings import runtime as cudart
13+
from cuda.bindings._v2 import nvrtc
1414

1515
from .helper_cuda import check_cuda_errors
1616

@@ -44,7 +44,7 @@ def __init__(self, code, dev_id):
4444
requirement_not_met(f'pathfinder.find_nvidia_header_directory("{libname}") returned None')
4545
include_dirs.append(hdr_dir)
4646

47-
prog = check_cuda_errors(nvrtc.nvrtcCreateProgram(str.encode(code), b"sourceCode.cu", 0, None, None))
47+
prog = nvrtc.create_program(str.encode(code), b"sourceCode.cu")
4848

4949
# Initialize CUDA
5050
check_cuda_errors(cudart.cudaFree(0))
@@ -55,7 +55,7 @@ def __init__(self, code, dev_id):
5555
minor = check_cuda_errors(
5656
cudart.cudaDeviceGetAttribute(cudart.cudaDeviceAttr.cudaDevAttrComputeCapabilityMinor, dev_id)
5757
)
58-
_, nvrtc_minor = check_cuda_errors(nvrtc.nvrtcVersion())
58+
_, nvrtc_minor = nvrtc.version()
5959
use_cubin = nvrtc_minor >= 1
6060
prefix = "sm" if use_cubin else "compute"
6161
arch_arg = bytes(f"--gpu-architecture={prefix}_{major}{minor}", "ascii")
@@ -70,25 +70,19 @@ def __init__(self, code, dev_id):
7070
opts.append(f"--include-path={inc_dir}".encode())
7171

7272
try:
73-
check_cuda_errors(nvrtc.nvrtcCompileProgram(prog, len(opts), opts))
74-
except RuntimeError as err:
75-
log_size = check_cuda_errors(nvrtc.nvrtcGetProgramLogSize(prog))
76-
log = b" " * log_size
77-
check_cuda_errors(nvrtc.nvrtcGetProgramLog(prog, log))
73+
nvrtc.compile_program(prog, opts)
74+
except nvrtc.NvrtcError as err:
75+
log = nvrtc.get_program_log(prog)
7876
import sys
7977

8078
print(log.decode(), file=sys.stderr) # noqa: T201
8179
print(err, file=sys.stderr) # noqa: T201
8280
sys.exit(1)
8381

8482
if use_cubin:
85-
data_size = check_cuda_errors(nvrtc.nvrtcGetCUBINSize(prog))
86-
data = b" " * data_size
87-
check_cuda_errors(nvrtc.nvrtcGetCUBIN(prog, data))
83+
data = nvrtc.get_cubin(prog)
8884
else:
89-
data_size = check_cuda_errors(nvrtc.nvrtcGetPTXSize(prog))
90-
data = b" " * data_size
91-
check_cuda_errors(nvrtc.nvrtcGetPTX(prog, data))
85+
data = nvrtc.get_ptx(prog)
9286

9387
self.module = check_cuda_errors(cuda.cuModuleLoadData(np.char.array(data)))
9488

cuda_bindings/cuda/bindings/_lib/utils.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ cdef class _HelperCUcoredumpSettings:
162162
cdef cydriver.CUcoredumpSettings_enum _attrib
163163
cdef bint _is_getter
164164
cdef size_t _size
165+
cdef object _references # keeps caller bytes alive so _charstar stays valid
165166

166167
# Return values
167168
cdef bint _bool

cuda_bindings/cuda/bindings/_lib/utils.pxi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ cdef class _HelperCUcoredumpSettings:
664664
self._cptr = <void*><void_ptr>self._charstar
665665
self._size = 1024
666666
else:
667+
# Keep a reference so the borrowed _charstar buffer stays alive.
668+
self._references = init_value
667669
self._charstar = init_value
668670
self._cptr = <void*><void_ptr>self._charstar
669671
self._size = len(init_value)
@@ -680,7 +682,11 @@ cdef class _HelperCUcoredumpSettings:
680682
raise TypeError('Unsupported attribute: {}'.format(attr.name))
681683

682684
def __dealloc__(self):
683-
pass
685+
# Only the getter path owns heap (the calloc'd 1024-byte buffer). The
686+
# setter borrows caller bytes and the bool path points at &self._bool,
687+
# so only free for the getter.
688+
if self._is_getter:
689+
free(self._charstar)
684690

685691
@property
686692
def cptr(self):

cuda_bindings/cuda/bindings/_v2/__init__.py

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# This code was automatically generated across versions from 12.9.0 to 13.3.0. Do not modify it directly.
6+
7+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=223716a3d6961dfe7231f2c88e76a9ab4c0a8d888cc4bf3e889bfbcbf8580346
8+
from libc.stdint cimport intptr_t
9+
10+
from ..cynvrtc cimport *
11+
12+
13+
###############################################################################
14+
# Types
15+
###############################################################################
16+
17+
ctypedef nvrtcProgram Program
18+
19+
20+
###############################################################################
21+
# Enum
22+
###############################################################################
23+
24+
ctypedef nvrtcResult _Result
25+
26+
27+
###############################################################################
28+
# Functions
29+
###############################################################################
30+
31+
cpdef intptr_t create_program(bytes src, name, headers=*, include_names=*) except? 0
32+
cpdef compile_program(intptr_t prog, options=*)
33+
cpdef set_flow_callback(intptr_t prog, intptr_t callback, intptr_t payload)
34+
cpdef bytes get_lowered_name(intptr_t prog, bytes name_expression)
35+
cpdef install_bundled_headers(bytes install_path, unsigned int flags)
36+
cpdef tuple get_bundled_headers_info()
37+
cpdef remove_bundled_headers(bytes install_path)
38+
39+
cpdef str get_error_string(int result)
40+
cpdef tuple version()
41+
cpdef int get_num_supported_archs() except? -1
42+
cpdef object get_supported_archs()
43+
cpdef destroy_program(intptr_t prog)
44+
cpdef size_t get_ptx_size(intptr_t prog) except? 0
45+
cpdef bytes get_ptx(intptr_t prog)
46+
cpdef size_t get_cubin_size(intptr_t prog) except? 0
47+
cpdef bytes get_cubin(intptr_t prog)
48+
cpdef size_t get_ltoir_size(intptr_t prog) except? 0
49+
cpdef bytes get_ltoir(intptr_t prog)
50+
cpdef size_t get_optix_ir_size(intptr_t prog) except? 0
51+
cpdef bytes get_optix_ir(intptr_t prog)
52+
cpdef size_t get_program_log_size(intptr_t prog) except? 0
53+
cpdef bytes get_program_log(intptr_t prog)
54+
cpdef add_name_expression(intptr_t prog, name_expression)
55+
cpdef size_t get_pch_heap_size() except? 0
56+
cpdef set_pch_heap_size(size_t size)
57+
cpdef int get_pch_create_status(intptr_t prog) except? -1
58+
cpdef size_t get_pch_heap_size_required(intptr_t prog) except? 0
59+
cpdef size_t get_tile_ir_size(intptr_t prog) except? 0
60+
cpdef bytes get_tile_ir(intptr_t prog)

0 commit comments

Comments
 (0)