Skip to content

Commit cdfd5e3

Browse files
committed
fixup! feat(core.utils): use is-not-None gate for driver-linker unsupported fields
1 parent 55f4d47 commit cdfd5e3

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,12 @@ def _linker_option_fingerprint(options: ProgramOptions) -> list[bytes]:
219219
return [f"{name}={getattr(options, name, None)!r}".encode() for name in _LINKER_RELEVANT_FIELDS]
220220

221221

222-
# LinkerOptions fields that the cuLink (driver) backend rejects outright
223-
# (_linker.pyx _prepare_driver_options). nvJitLink accepts all of them.
224-
_DRIVER_LINKER_UNSUPPORTED_FIELDS = ("time", "ptxas_options", "split_compile", "split_compile_extended")
222+
# ProgramOptions fields that map to LinkerOptions fields the cuLink (driver)
223+
# backend rejects outright (see _prepare_driver_options in _linker.pyx).
224+
# ``split_compile_extended`` exists on LinkerOptions but is not exposed via
225+
# ProgramOptions / _translate_program_options, so it cannot reach the driver
226+
# linker from the cache path and is omitted here.
227+
_DRIVER_LINKER_UNSUPPORTED_FIELDS = ("time", "ptxas_options", "split_compile")
225228

226229

227230
def _driver_version() -> int:
@@ -424,7 +427,13 @@ def make_program_cache_key(
424427
except Exception:
425428
use_driver_linker = None
426429
if use_driver_linker is True:
427-
unsupported = [name for name in _DRIVER_LINKER_UNSUPPORTED_FIELDS if _option_is_set(options, name)]
430+
# Mirror ``_prepare_driver_options``'s exact gate: the driver
431+
# linker checks ``is not None`` for these fields, so ``time=False``
432+
# or ``ptxas_options=[]`` is still a rejection. Do NOT use the
433+
# truthiness-based ``_option_is_set`` helper here.
434+
unsupported = [
435+
name for name in _DRIVER_LINKER_UNSUPPORTED_FIELDS if getattr(options, name, None) is not None
436+
]
428437
if unsupported:
429438
raise ValueError(
430439
f"the cuLink driver linker does not support these options: "

cuda_core/tests/test_program_cache.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,25 @@ def test_make_program_cache_key_nvvm_probe_changes_key(monkeypatch):
355355
@pytest.mark.parametrize(
356356
"option_kw",
357357
[
358-
pytest.param({"time": True}, id="time"),
359-
pytest.param({"ptxas_options": "-v"}, id="ptxas_options"),
360-
pytest.param({"split_compile": 0}, id="split_compile"),
358+
pytest.param({"time": True}, id="time_true"),
359+
# ``_prepare_driver_options`` checks ``is not None``, so even the
360+
# "falsy-but-set" cases must still be rejected at key time.
361+
pytest.param({"time": False}, id="time_false"),
362+
pytest.param({"ptxas_options": "-v"}, id="ptxas_options_str"),
363+
pytest.param({"ptxas_options": ["-v", "-O2"]}, id="ptxas_options_list"),
364+
pytest.param({"ptxas_options": []}, id="ptxas_options_empty_list"),
365+
pytest.param({"split_compile": 0}, id="split_compile_zero"),
366+
pytest.param({"split_compile": 4}, id="split_compile_nonzero"),
367+
# split_compile_extended is a LinkerOptions-only field; ProgramOptions
368+
# does not expose it, so it cannot reach the driver linker via
369+
# Program.compile and is not part of the cache-time guard.
361370
],
362371
)
363372
def test_make_program_cache_key_ptx_rejects_driver_linker_unsupported(option_kw, monkeypatch):
364373
"""When the driver (cuLink) linker backend is selected, options that
365374
``_prepare_driver_options`` rejects must also be rejected at key time
366-
so we never cache a compilation that would fail."""
375+
so we never cache a compilation that would fail. Uses ``is not None``
376+
to exactly mirror the driver-linker's own gate."""
367377
from cuda.core import _linker
368378

369379
monkeypatch.setattr(_linker, "_decide_nvjitlink_or_driver", lambda: True) # driver

0 commit comments

Comments
 (0)