Skip to content

Commit 792ab3c

Browse files
authored
numba_debug (#2158)
1 parent 02cd045 commit 792ab3c

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

cuda_core/cuda/core/_linker.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class LinkerOptions:
285285
split_compile: int | None = None
286286
split_compile_extended: int | None = None
287287
no_cache: bool | None = None
288+
numba_debug: bool | None = None
288289

289290
def __post_init__(self):
290291
_lazy_init()

cuda_core/cuda/core/_program.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ cdef inline object _translate_program_options(object options):
734734
split_compile=options.split_compile,
735735
ptxas_options=options.ptxas_options,
736736
no_cache=options.no_cache,
737+
numba_debug = options.numba_debug
737738
)
738739

739740

@@ -1223,6 +1224,8 @@ cdef inline object _prepare_nvvm_options_impl(object opts, bint as_bytes):
12231224
options.append(f"-arch={arch}")
12241225
if opts.debug is not None and opts.debug:
12251226
options.append("-g")
1227+
if opts.numba_debug:
1228+
options.append("--numba-debug")
12261229
if opts.device_code_optimize is False:
12271230
options.append("-opt=0")
12281231
elif opts.device_code_optimize is True:
@@ -1299,8 +1302,6 @@ cdef inline object _prepare_nvvm_options_impl(object opts, bint as_bytes):
12991302
unsupported.append("fdevice_syntax_only")
13001303
if opts.minimal is not None and opts.minimal:
13011304
unsupported.append("minimal")
1302-
if opts.numba_debug is not None and opts.numba_debug:
1303-
unsupported.append("numba_debug")
13041305
if unsupported:
13051306
raise CUDAError(f"The following options are not supported by NVVM backend: {', '.join(unsupported)}")
13061307

cuda_core/tests/test_program.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ def _check_nvvm_arch(arch: str) -> bool:
9292
return check_nvvm_compiler_options([f"-arch={arch}"])
9393

9494

95+
def _check_nvvm_supports_numba_debug() -> bool:
96+
"""Check if the installed libNVVM recognizes --numba-debug (CTK 13.2+)."""
97+
if not _has_check_nvvm_compiler_options():
98+
return False
99+
from cuda.bindings.utils import check_nvvm_compiler_options
100+
101+
return check_nvvm_compiler_options(["--numba-debug"])
102+
103+
95104
@pytest.fixture(scope="session")
96105
def nvvm_ir():
97106
"""Generate working NVVM IR with proper version metadata.
@@ -303,6 +312,8 @@ def test_cpp_program_pch_status_none_without_pch(init_cuda):
303312
ProgramOptions(prec_div=True),
304313
ProgramOptions(prec_sqrt=True),
305314
ProgramOptions(fma=True),
315+
# Plumb-through; no-op at link time. See #1287.
316+
ProgramOptions(debug=True, numba_debug=True),
306317
]
307318
if not is_culink_backend:
308319
options += [
@@ -552,7 +563,6 @@ def test_nvvm_program_with_single_extra_source(nvvm_ir):
552563

553564
nvvm = _get_nvvm_module()
554565
major, minor, debug_major, debug_minor = nvvm.ir_version()
555-
# helper nvvm ir for multiple module loading
556566
helper_nvvmir = f"""target triple = "nvptx64-unknown-cuda"
557567
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
558568
@@ -740,6 +750,33 @@ def test_program_options_as_bytes_nvvm_unsupported_option():
740750
options.as_bytes("nvvm")
741751

742752

753+
@nvvm_available
754+
def test_nvvm_program_options_as_bytes_numba_debug():
755+
"""numba_debug must be plumbed through to libNVVM as --numba-debug
756+
(see #1287)."""
757+
options = ProgramOptions(arch="sm_80", debug=True, numba_debug=True)
758+
nvvm_bytes = options.as_bytes("nvvm")
759+
assert b"--numba-debug" in nvvm_bytes
760+
assert b"-g" in nvvm_bytes
761+
762+
763+
@nvvm_available
764+
@pytest.mark.skipif(
765+
not _check_nvvm_supports_numba_debug(),
766+
reason="installed libNVVM does not recognize --numba-debug (needs CTK 13.2+)",
767+
)
768+
def test_nvvm_program_numba_debug(init_cuda, nvvm_ir):
769+
options = ProgramOptions(arch="sm_80", debug=True, numba_debug=True)
770+
program = Program(nvvm_ir, "nvvm", options)
771+
try:
772+
assert program.backend == "NVVM"
773+
result = program.compile("ptx")
774+
assert isinstance(result, ObjectCode)
775+
assert len(result.code) > 0
776+
finally:
777+
program.close()
778+
779+
743780
def test_program_options_repr():
744781
"""ProgramOptions.__repr__ returns a human-readable string."""
745782
opts = ProgramOptions(name="mykernel", arch="sm_80")

0 commit comments

Comments
 (0)