[FEA] Centralize CUDA environment variable handling and prioritize CUDA_PATH over CUDA_HOME#1519
[FEA] Centralize CUDA environment variable handling and prioritize CUDA_PATH over CUDA_HOME#1519rparolin wants to merge 14 commits intoNVIDIA:mainfrom
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/ok to test |
|
Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/ok to test |
|
/ok to test |
|
/ok to test |
|
/ok to test |
|
|
/ok to test |
| "setuptools_scm[simple]>=8", | ||
| "cython>=3.2,<3.3", | ||
| "pyclibrary>=0.1.7", | ||
| "cuda-pathfinder", |
There was a problem hiding this comment.
It's already on line 34 below. Having it there seemed to work reliably in all situations?
|
This still uses the old pattern (seems like an easy fix):
This
should probably be updated to use pathfinder, similar to what I did here a few days ago: I could take care of that in a separate, small PR. Should I? |
| from cuda.pathfinder._utils.env_vars import get_cuda_home_or_path | ||
|
|
||
| CUDA_HOME = get_cuda_home_or_path() | ||
| except ImportError: |
There was a problem hiding this comment.
I don't think this fallback code is needed. cuda-bindings depends critically on cuda-pathfinder.
| Path to CUDA Toolkit, or None if neither variable is set. Empty strings are | ||
| preserved and returned as-is if explicitly set in the environment. |
There was a problem hiding this comment.
Hm, that seems like it could lead to confusing situations. Could we make it so that empty strings are equivalent to to undefined?
…d onto main. Adds cuda.pathfinder._utils.env_var_constants with canonical search order, enhances get_cuda_home_or_path() with robust path comparison and caching, and updates documentation across all packages to reflect the new priority. Co-authored-by: Rob Parolin <rparolin@nvidia.com> Made-with: Cursor
…PATH` over `CUDA_HOME` (#1801) * Squash-merge of PR #1519 (rparolin/env_var_improvements) rebased onto main. Adds cuda.pathfinder._utils.env_var_constants with canonical search order, enhances get_cuda_home_or_path() with robust path comparison and caching, and updates documentation across all packages to reflect the new priority. Co-authored-by: Rob Parolin <rparolin@nvidia.com> Made-with: Cursor * replace _get_cuda_paths() with _get_cuda_path() using pathfinder Drop os.pathsep splitting of CUDA_PATH/CUDA_HOME in both build_hooks.py files. Both functions now delegate to get_cuda_home_or_path() from cuda.pathfinder, returning a single path. See #1801 (comment) Made-with: Cursor * treat empty env vars as undefined in get_cuda_home_or_path() See #1801 (comment) for the rationale Made-with: Cursor * fix(pathfinder): clear get_cuda_home_or_path cache in test fixtures Made-with: Cursor * fix(core): update test_build_hooks for _get_cuda_path rename, drop multi-path test Made-with: Cursor * refactor(core): use get_cuda_home_or_path() in test conftest skipif Made-with: Cursor * refactor(core): use get_cuda_home_or_path() in examples Made-with: Cursor * rename get_cuda_home_or_path -> get_cuda_path_or_home Safe: currently an internal-only API (not yet public). Made-with: Cursor * make get_cuda_path_or_home a public API, privatize CUDA_ENV_VARS_ORDERED Export get_cuda_path_or_home from cuda.pathfinder.__init__. External consumers now import from cuda.pathfinder directly. Rename constant to _CUDA_PATH_ENV_VARS_ORDERED and remove all public references to it. Made-with: Cursor * docs(pathfinder): manually edit 1.5.0 release notes, fix RST formatting (Cursor) Made-with: Cursor * Add 1.5.0, 1.4.3, 1.4.2 in cuda_pathfinder/docs/nv-versions.json * docs: clarify that CUDA_PATH/CUDA_HOME priority comes from pathfinder Pathfinder 1.5.0 release notes no longer claim cross-package consistency (that depends on future bindings/core releases). cuda_bindings env var docs now defer to pathfinder release notes for migration guidance. Made-with: Cursor * fix oversights that slipped in when manually editing cuda_pathfinder/docs/nv-versions.json before Discovered via independent review from GPT-5.4 Extra High * fix(pathfinder): change found_via from "CUDA_HOME" to "CUDA_PATH" Aligns the provenance label with the new CUDA_PATH-first priority. The label signals the highest-priority env var name, not necessarily which variable supplied the value. Discovered via independent review from GPT-5.4 Extra High Made-with: Cursor * fix(build): don't import cuda.pathfinder in build_hooks.py The build backends run in an isolated venv created by pyproject-build. Although cuda-pathfinder is listed in build-system.requires and gets installed, the cuda namespace package from backend-path=["."] shadows the installed cuda-pathfinder, making `from cuda.pathfinder import ...` fail with ModuleNotFoundError. This broke all CI wheel builds. Revert _get_cuda_path() to use os.environ.get() directly with CUDA_PATH > CUDA_HOME priority, and remove cuda-pathfinder from build-system.requires (it was not there on main; our PR added it). Made-with: Cursor * Update pathfinder descriptor catalogs for cusparseLt release 0.9.0 * Slightly enhance comment in _get_cuda_path() * Add PR #1806 to 1.5.0-notes.rst * Systematically rename find_in_cuda_home → find_in_cuda_path * add _cuda_headers_available() guard to conftest files Add a helper that skips tests when no CUDA path is set, but asserts that the include/ subdirectory exists when one is — surfacing stale or incomplete toolkit roots at collection time instead of letting them fail later in compilation. Applied in both the root conftest.py and cuda_core/tests/conftest.py. Made-with: Cursor --------- Co-authored-by: Rob Parolin <rparolin@nvidia.com>
This PR introduces centralized CUDA environment variable handling across cuda-python packages with improved consistency and better handling of conflicting environment variable configurations.
The previous implicit priority of CUDA_HOME over CUDA_PATH was inconsistent with:
Key Changes
Breaking Change - Environment Variable Priority
Changed the search order priority from
CUDA_HOME > CUDA_PATHtoCUDA_PATH > CUDA_HOMEto align with NVIDIA tooling standards and industry conventions. This affects all packages that query CUDA Toolkit locations (cuda.pathfinder, cuda.core, cuda.bindings).New Module:
cuda.pathfinder._utils.env_var_constantsCUDA_ENV_VARS_ORDERED = ("CUDA_PATH", "CUDA_HOME")Enhanced
cuda.pathfinder._utils.env_varsget_cuda_home_or_path()with robust path comparison usingos.path.samefile()Closes #1433.