-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix CUDA version hardcoding to support CUDA 13+ dynamically #26518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tianleiwu
merged 4 commits into
microsoft:main
from
GrigoryEvko:fix/dynamic-cuda-version-support
Nov 9, 2025
Merged
Fix CUDA version hardcoding to support CUDA 13+ dynamically #26518
tianleiwu
merged 4 commits into
microsoft:main
from
GrigoryEvko:fix/dynamic-cuda-version-support
Nov 9, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The runtime Python code had CUDA 12 hardcoded in multiple locations, causing library loading failures when building with CUDA 13. Changes in onnxruntime/__init__.py: - Dynamic library path generation using detected CUDA version - Updated version validation to accept CUDA 12+ - Fixed PyTorch compatibility check to compare CUDA versions dynamically - Updated diagnostic checks to report correct nvidia packages Changes in setup.py: - Added is_cuda_version_13 flag and proper version parsing - Added CUDA 13 library versions to dependency exclusion list - Added CUDA 13 extras_require with nvidia-*-cu13 packages - Fixed TensorRT RTX to use dynamic CUDA version Fixes runtime "CUDA 12 not found" errors on CUDA 13 systems while maintaining backward compatibility with CUDA 12 builds.
Contributor
Author
|
@microsoft-github-policy-service agree |
xadupre
reviewed
Nov 7, 2025
xadupre
reviewed
Nov 7, 2025
xadupre
reviewed
Nov 7, 2025
- Extract CUDA major version parsing into _extract_cuda_major_version() helper - Add _get_cufft_version() for CUDA-version-specific cufft mapping (11 for CUDA 12.x, 12 for CUDA 13.x) - Replace all try-except-pass blocks with contextlib.suppress() (fixes RUFF/SIM105) - Apply dynamic cufft version to both Windows and Linux DLL paths - Add contextlib import to setup.py and onnxruntime/__init__.py This eliminates code duplication and ensures correct library versions across CUDA versions.
…if blocks - Replace separate is_cuda_version_12/13 conditions with single dynamic block - Use cuda_major_version variable with f-strings for package names - Apply correct cufft version mapping (11.0 for CUDA 12, 12.0 for CUDA 13) - Works automatically for future CUDA versions
Contributor
|
Please format the code with lintrunner: https://github.com/microsoft/onnxruntime/blob/main/docs/Coding_Conventions_and_Standards.md#Linting |
tianleiwu
reviewed
Nov 8, 2025
tianleiwu
reviewed
Nov 8, 2025
Contributor
Author
|
Maybe this way? deduplicated some code |
Contributor
|
/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline,Windows x64 QNN CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
tianleiwu
approved these changes
Nov 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes runtime library loading failures when building with CUDA 13 by replacing hardcoded CUDA 12 references with dynamic version detection.
Related to #26516 which updates CUDA 13 build pipelines, but this PR fixes the Python runtime code that was still hardcoded to CUDA 12.
Problem
The build system correctly detects CUDA 13 via CMake, but the runtime Python code had CUDA 12 hardcoded in multiple locations, causing "CUDA 12 not found" errors on CUDA 13 systems.
Solution
Modified onnxruntime/init.py and setup.py to dynamically use the detected CUDA version instead of hardcoded "12" strings.
Changes
Impact
Testing
Verified with CUDA 13.0 build that library paths resolve correctly and preload_dlls() loads CUDA 13 libraries without errors.