Skip to content

Commit 5d65e6f

Browse files
authored
fix(cuda_core): use nvJitLink-compatible 0/1 values for boolean linker options (#3128)
* fix: use nvJitLink-compatible 0/1 values for boolean options (nvbug 6621758) * refactor: drop explanatory comment on split_compile int coercion * add lto enabled runtime test for ftz/prec_div/prec_sqrt/fma
1 parent 8d2ec27 commit 5d65e6f

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

‎cuda_core/cuda/core/_linker.pyx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ class LinkerOptions:
400400
if self.lineinfo:
401401
options.append("-lineinfo")
402402
if self.ftz is not None:
403-
options.append(f"-ftz={'true' if self.ftz else 'false'}")
403+
options.append(f"-ftz={'1' if self.ftz else '0'}")
404404
if self.prec_div is not None:
405-
options.append(f"-prec-div={'true' if self.prec_div else 'false'}")
405+
options.append(f"-prec-div={'1' if self.prec_div else '0'}")
406406
if self.prec_sqrt is not None:
407-
options.append(f"-prec-sqrt={'true' if self.prec_sqrt else 'false'}")
407+
options.append(f"-prec-sqrt={'1' if self.prec_sqrt else '0'}")
408408
if self.fma is not None:
409-
options.append(f"-fma={'true' if self.fma else 'false'}")
409+
options.append(f"-fma={'1' if self.fma else '0'}")
410410
if self.kernels_used is not None:
411411
if isinstance(self.kernels_used, str):
412412
options.append(f"-kernels-used={self.kernels_used}")
@@ -428,9 +428,9 @@ class LinkerOptions:
428428
for opt in self.ptxas_options:
429429
options.append(f"-Xptxas={opt}")
430430
if self.split_compile is not None:
431-
options.append(f"-split-compile={self.split_compile}")
431+
options.append(f"-split-compile={int(self.split_compile)}")
432432
if self.split_compile_extended is not None:
433-
options.append(f"-split-compile-extended={self.split_compile_extended}")
433+
options.append(f"-split-compile-extended={int(self.split_compile_extended)}")
434434
if self.no_cache is True:
435435
options.append("-no-cache")
436436

‎cuda_core/tests/test_linker.py‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,36 @@ def test_linker_options_as_bytes_nvjitlink():
206206
options_str = [opt.decode() for opt in nvjitlink_options]
207207
assert "-arch=sm_80" in options_str
208208
assert "-g" in options_str
209-
assert "-ftz=true" in options_str
209+
assert "-ftz=1" in options_str
210210
assert "-maxrregcount=32" in options_str
211211

212212

213+
@pytest.mark.agent_authored(model="claude-sonnet-5")
214+
@pytest.mark.skipif(is_culink_backend, reason="ftz/prec_div/prec_sqrt/fma are nvjitlink-only options")
215+
def test_linker_lto_enabled_runtime_accepts_bool_options(compile_ltoir_functions):
216+
"""Regression test for nvbug 6621758: actual LTO-enabled link, not just option setter.
217+
218+
With ``link_time_optimization=True``, ``-ftz``/``-prec-div``/``-prec-sqrt``/``-fma``
219+
are forwarded to libnvvm and actually validated at link time, unlike in a non-LTO
220+
link where legacy ``true``/``false`` values are silently ignored. Only ``0``/``1``
221+
reliably takes effect here on any CUDA version.
222+
223+
The test checks that Python ``True``/``False`` values are correctly
224+
mapped to ``1``/``0`` and accepted by the nvJitLink backend during an LTO-enabled link.
225+
"""
226+
options = LinkerOptions(
227+
arch=ARCH,
228+
link_time_optimization=True,
229+
ftz=True,
230+
prec_div=True,
231+
prec_sqrt=True,
232+
fma=True,
233+
)
234+
linker = Linker(*compile_ltoir_functions, options=options)
235+
linked_code = linker.link("cubin")
236+
assert isinstance(linked_code, ObjectCode)
237+
238+
213239
@pytest.mark.agent_authored(model="gpt-5.6")
214240
@pytest.mark.skipif(is_culink_backend, reason="as_bytes() only supported for nvjitlink backend")
215241
@pytest.mark.parametrize("value,expected_count", [(None, 0), (False, 0), (True, 1)])

0 commit comments

Comments
 (0)