From de3df790a2fee880ad75f4a248e79f7c7be411ec Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Sun, 9 Aug 2026 13:59:24 -0700 Subject: [PATCH] fix(bindings): CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING=0 must not disable it The suppression check tests the raw environment string for truthiness: if os.environ.get("CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING"): return so `=0` -- the obvious way to spell "no, keep warning me" -- suppresses the warning just as effectively as `=1`. The warning's own text says "(Set CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING=1 to suppress this warning.)", which reads as though 0 is the off value, and the other two boolean knobs in this repository disagree with it: cuda_bindings/.../_internal/runtime_linux.pyx:29 bool(int(os.getenv('CUDA_PYTHON_CUDA_PER_THREAD_DEFAULT_STREAM', default=0))) cuda_core/cuda/core/__init__.py:44 if int(os.environ.get("CUDA_CORE_DONT_FIX_TAB_COMPLETION", "0")): Both parse with int(), so `=0` is off for them. A user who sets all three to 0 gets the behaviour they asked for from two of them and the opposite from this one, silently losing a compatibility warning that exists to explain why their driver is too old. Parse the value with int() here too. Unset and empty still mean "not disabled". A value that is not an integer keeps the old set-means-disabled behaviour, so anyone currently relying on a spelling like `=true` does not start seeing the warning again -- `0` is the only input whose meaning changes. --- .../cuda/bindings/utils/_version_check.py | 33 +++++++++++-- cuda_bindings/tests/test_version_check.py | 47 +++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/cuda_bindings/cuda/bindings/utils/_version_check.py b/cuda_bindings/cuda/bindings/utils/_version_check.py index 5c68b50152e..9e36e229588 100644 --- a/cuda_bindings/cuda/bindings/utils/_version_check.py +++ b/cuda_bindings/cuda/bindings/utils/_version_check.py @@ -9,6 +9,32 @@ _major_version_compatibility_checked = False _lock = threading.Lock() +_DISABLE_WARNING_ENV_VAR = "CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING" + + +def _warning_disabled() -> bool: + """Whether the user asked to suppress the major-version warning. + + ``=0`` means "do not suppress". A bare truthiness test on the raw string + made ``CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING=0`` suppress the warning + -- the exact opposite of what the warning itself tells the user to type, + and the opposite of the other boolean knobs in this repository + (``CUDA_PYTHON_CUDA_PER_THREAD_DEFAULT_STREAM`` and + ``CUDA_CORE_DONT_FIX_TAB_COMPLETION``), which both parse their value with + ``int()``. + + Unset and empty still mean "not disabled". A value that is not an integer + keeps the old set-means-disabled behaviour, so anyone currently relying on + a spelling like ``=true`` does not silently start seeing the warning again. + """ + raw = os.environ.get(_DISABLE_WARNING_ENV_VAR, "").strip() + if not raw: + return False + try: + return int(raw) != 0 + except ValueError: + return True + def warn_if_cuda_major_version_mismatch(): """Warn if the CUDA driver major version is older than cuda-bindings compile-time version. @@ -21,7 +47,8 @@ def warn_if_cuda_major_version_mismatch(): The check runs only once per process. Subsequent calls are no-ops. The warning can be suppressed by setting the environment variable - ``CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING=1``. + ``CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING=1``. Setting it to ``0`` (or + leaving it unset or empty) keeps the warning enabled. """ global _major_version_compatibility_checked if _major_version_compatibility_checked: @@ -32,7 +59,7 @@ def warn_if_cuda_major_version_mismatch(): _major_version_compatibility_checked = True # Allow users to suppress the warning - if os.environ.get("CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING"): + if _warning_disabled(): return # Import here to avoid circular imports and allow lazy loading @@ -55,7 +82,7 @@ def warn_if_cuda_major_version_mismatch(): f"NVIDIA driver only supports up to CUDA {runtime_major}. Some cuda-bindings " f"features may not work correctly. Consider updating your NVIDIA driver, " f"or using a cuda-bindings version built for CUDA {runtime_major}. " - f"(Set CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING=1 to suppress this warning.)", + f"(Set {_DISABLE_WARNING_ENV_VAR}=1 to suppress this warning.)", UserWarning, stacklevel=3, ) diff --git a/cuda_bindings/tests/test_version_check.py b/cuda_bindings/tests/test_version_check.py index 03c3d7d3c2c..ec8192f19cf 100644 --- a/cuda_bindings/tests/test_version_check.py +++ b/cuda_bindings/tests/test_version_check.py @@ -84,6 +84,53 @@ def test_warning_suppressed_by_env_var(self): warn_if_cuda_major_version_mismatch() assert len(w) == 0 + @pytest.mark.agent_authored(model="claude-opus-5") + @pytest.mark.parametrize( + ("raw", "expected"), + [ + pytest.param("0", False, id="zero"), + pytest.param(" 0 ", False, id="zero-padded"), + pytest.param("", False, id="empty"), + pytest.param(" ", False, id="blank"), + pytest.param("1", True, id="one"), + pytest.param("2", True, id="two"), + # Not an integer: keep the old set-means-disabled behaviour so no + # one relying on a spelling like `=true` starts seeing the warning + # again. + pytest.param("true", True, id="true"), + pytest.param("yes", True, id="yes"), + ], + ) + def test_disable_flag_parsing(self, monkeypatch, raw, expected): + monkeypatch.setenv("CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING", raw) + assert _version_check._warning_disabled() is expected + + @pytest.mark.agent_authored(model="claude-opus-5") + def test_disable_flag_unset(self, monkeypatch): + monkeypatch.delenv("CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING", raising=False) + assert _version_check._warning_disabled() is False + + @pytest.mark.agent_authored(model="claude-opus-5") + def test_warning_not_suppressed_when_env_var_is_zero(self): + """``=0`` is how a user says "no, keep warning me". + + A bare truthiness test on the raw string made ``=0`` suppress the + warning -- the opposite of what the warning itself tells the user to + type, and the opposite of the other boolean knobs in this repository + (``CUDA_PYTHON_CUDA_PER_THREAD_DEFAULT_STREAM``, + ``CUDA_CORE_DONT_FIX_TAB_COMPLETION``), which both parse with ``int()``. + """ + with ( + mock.patch.object(driver, "CUDA_VERSION", 13000), + mock.patch.object(driver, "cuDriverGetVersion", return_value=(driver.CUresult.CUDA_SUCCESS, 12080)), + mock.patch.dict(os.environ, {"CUDA_PYTHON_DISABLE_MAJOR_VERSION_WARNING": "0"}), + warnings.catch_warnings(record=True) as w, + ): + warnings.simplefilter("always") + warn_if_cuda_major_version_mismatch() + assert len(w) == 1 + assert issubclass(w[0].category, UserWarning) + def test_error_when_driver_version_fails(self): """Should raise RuntimeError if cuDriverGetVersion fails.""" with (