-
Notifications
You must be signed in to change notification settings - Fork 264
Use cuda-pathfinder in build-system.requires
#1817
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
base: main
Are you sure you want to change the base?
Changes from all commits
01f33cd
0fc4597
3d422de
73e840e
6892ae0
5a06d6f
b779d0d
6facaa5
f1ef076
3cb0313
a9995ac
cb5ffbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,13 +28,41 @@ | |
| COMPILE_FOR_COVERAGE = bool(int(os.environ.get("CUDA_PYTHON_COVERAGE", "0"))) | ||
|
|
||
|
|
||
| # Please keep in sync with the copy in cuda_bindings/build_hooks.py. | ||
| def _import_get_cuda_path_or_home(): | ||
| """Import get_cuda_path_or_home, working around PEP 517 namespace shadowing. | ||
|
|
||
| See https://github.com/NVIDIA/cuda-python/issues/1824 for why this helper is needed. | ||
| """ | ||
| try: | ||
| import cuda.pathfinder | ||
| except ModuleNotFoundError as exc: | ||
| if exc.name not in ("cuda", "cuda.pathfinder"): | ||
| raise | ||
| try: | ||
| import cuda | ||
| except ModuleNotFoundError: | ||
| cuda = None | ||
|
|
||
| for p in sys.path: | ||
| sp_cuda = os.path.join(p, "cuda") | ||
| if os.path.isdir(os.path.join(sp_cuda, "pathfinder")): | ||
| cuda.__path__ = list(cuda.__path__) + [sp_cuda] | ||
| break | ||
| else: | ||
| raise ModuleNotFoundError( | ||
| "cuda-pathfinder is not installed in the build environment. " | ||
| "Ensure 'cuda-pathfinder>=1.5' is in build-system.requires." | ||
| ) | ||
| import cuda.pathfinder | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we include some message explaining that we iterated through sys.path looking for pathfinder and couldn't find it? That seems to be important information that would be missing from just throwing we couldn't import pathfinder module.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: commit 3d422de |
||
|
|
||
| return cuda.pathfinder.get_cuda_path_or_home | ||
|
|
||
|
|
||
| @functools.cache | ||
| def _get_cuda_path() -> str: | ||
| # Not using cuda.pathfinder.get_cuda_path_or_home() here because this | ||
| # build backend runs in an isolated venv where the cuda namespace package | ||
| # from backend-path shadows the installed cuda-pathfinder. See #1803 for | ||
| # a workaround to apply after cuda-pathfinder >= 1.5 is released. | ||
| cuda_path = os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")) | ||
| get_cuda_path_or_home = _import_get_cuda_path_or_home() | ||
| cuda_path = get_cuda_path_or_home() | ||
| if not cuda_path: | ||
| raise RuntimeError("Environment variable CUDA_PATH or CUDA_HOME is not set") | ||
| print("CUDA path:", cuda_path) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid duplicating implementations. Could we not hoist this into a separate file and import from both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
No 😭
In the words of Cursor Opus 4.6 1M Thinking:
There's no reasonable way to share code between the two
build_hooks.pyfiles:backend-path=["."]from its own package directory (cuda_bindings/orcuda_core/). They can't import from the monorepo root or from each other.cuda.pathfindercan't be imported normally in this context — so it can't live insidecuda-pathfindereither.build-system.requireswould be massive overkill for ~15 lines of stable code.The only alternatives are worse: a new PyPI package just for this,
importlibfile-path hacks, or copying a shared file into both directories at CI time.The "please keep in sync" comments are the pragmatic solution here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have other existing cases of "please keep in sync" that are impractical to avoid.
It just crossed my mind: a pre-commit check to enforce that they stay in sync is probably pretty easy to implement.