Add CUDA version compatibility check
Summary
Adds a version compatibility check that warns users when cuda-bindings was compiled against a newer CUDA major version than the installed driver supports.
Changes
cuda-bindings
- Added
check_cuda_version_compatibility()function incuda/bindings/utils/_version_check.py - Compares compile-time
CUDA_VERSIONvs runtimecuDriverGetVersion() - Exported from
cuda.bindings.utils - Added comprehensive unit tests in
tests/test_version_check.py
cuda-core
-
Device.__new__callscheck_cuda_version_compatibility()aftercuInitsucceeds - Imports the function directly from
cuda.bindings.utils
Rationale
When cuda-bindings is built against CUDA 13 headers but the user's driver only supports CUDA 12, many features will silently fail or behave unexpectedly. This check provides early, clear feedback:
UserWarning: cuda-bindings was built against CUDA 13.0, but the installed driver
only supports CUDA 12.8. Some features may not work correctly. Consider updating
your NVIDIA driver. Set CUDA_PYTHON_DISABLE_VERSION_CHECK=1 to suppress this warning.
Design
-
Provided by cuda-bindings: The version check implementation lives in
cuda.bindings.utilssince it checks cuda-bindings' compile-time version -
Invoked by cuda-core: Called when
Devicefirst triggers CUDA initialization - Runs once: Uses a module-level flag to ensure the check runs only once per process
- Non-blocking: Warning only, does not prevent operation
-
Suppressible: Set
CUDA_PYTHON_DISABLE_VERSION_CHECK=1to disable - Major version only: No warning for minor version differences (handled by graceful degradation per PR #1409)
Future Work
We could not find a suitable place to invoke the version check automatically within cuda-bindings itself (e.g., hooking into cuInit), so the check is currently triggered by cuda-core. This may be revisited in the future.
Test Coverage
7 tests in cuda-bindings covering:
- No warning when driver is newer
- No warning when same major version
- Warning when compile major > driver major
- Warning only issued once per process
- Suppression via environment variable
- Silent handling of driver errors
- Silent handling of missing CUDA_VERSION attribute
Related Work
- Complements PR #1409 which handles graceful degradation for minor version mismatches
This pull request requires additional validation before any workflows can run on NVIDIA's runners.
Pull request vetters can view their responsibilities here.
Contributors can view more details about this message here.
/ok to test 7ce325c07b559e9a66472f5ba7a99fe980e17c09
/ok to test 1962e351a233d65f2288fd6d16a43f0b0b75d6ad
Doc Preview CI :---: |
:rocket: View preview athttps://nvidia.github.io/cuda-python/pr-preview/pr-1412/
|
https://nvidia.github.io/cuda-python/pr-preview/pr-1412/cuda-core/
|
https://nvidia.github.io/cuda-python/pr-preview/pr-1412/cuda-bindings/
|
https://nvidia.github.io/cuda-python/pr-preview/pr-1412/cuda-pathfinder/
|
Preview will be ready when the GitHub Pages deployment is complete.
/ok to test 73e5a4379fad3392c24499e245a521c86c53db42
/ok to test ddd92bd3ad9ef82f9d166897ec172dc0d42c850f
/ok to test 62dfccab0047bb6421358d011398bc4c661cb5d7
/ok to test b2083ed64147ce95739d141179466c582c63ee9a
/ok to test fdb3a7e89
/ok to test https://github.com/NVIDIA/cuda-python/commit/acadb3183278aca6201be0d1b733c2eb03b57dd5
/ok to test 3a5c210cd89c018dda27e6e659a36802b17bc077
/ok to test 424a113185c5163ec1c8a719bed392051c63cda5
/ok to test 6071609504b9c8aca4dc8bef7764a27ca2911f2f
/ok to test 96532b226
/ok to test 973af9b7a
/ok to test 7f23b08bc
/ok to test a368e0f249b051ed43c4b099a327a7e107425e0b
Doc Preview CI :---: Preview removed because the pull request was closed or merged.