Repository navigation
BLD: Insert CCCL also via FLAGS environment to work around conda nvcc #3104
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -12,9 +12,11 @@ | |
| import importlib.util | ||
| import os | ||
| import re | ||
| import shlex | ||
| import sys | ||
| import tempfile | ||
| import zipfile | ||
| from distutils import sysconfig | ||
| from pathlib import Path | ||
|
|
||
| import Cython as _Cython | ||
|
|
@@ -340,7 +342,8 @@ def _build_define_macros(cuda_major: str, bindings_cuda_version: int | None = No | |
|
|
||
| def _build_config_key(cuda_major, toolchain, debug, coverage): | ||
| """Return a stable string key for the build configuration.""" | ||
| return f"cu{cuda_major}-{toolchain}-{'debug' if debug else 'opt'}{'-cov' if coverage else ''}" | ||
| # Rebuild artifacts made before the pinned CCCL took precedence over environment flags. | ||
| return f"cu{cuda_major}-{toolchain}-{'debug' if debug else 'opt'}{'-cov' if coverage else ''}-cccl-first" | ||
|
|
||
|
|
||
| def _check_build_config(toolchain, debug, coverage): | ||
|
|
@@ -445,6 +448,20 @@ def _get_cccl_include_dirs() -> list[str]: | |
| return [str(libcudacxx_include)] | ||
|
|
||
|
|
||
| def _configure_cccl_include_flags(include_dirs): | ||
| if sys.platform == "win32": | ||
| return | ||
|
|
||
| # setuptools puts environment flags before Extension.include_dirs; | ||
| # conda's cuda-nvcc activation adds a competing CCCL -I there. | ||
| cccl_flags = shlex.join([f"-I{path}" for path in include_dirs]) | ||
| default_flags = sysconfig.get_config_var("CFLAGS") or "" | ||
| for name in ("CFLAGS", "CXXFLAGS", "CPPFLAGS"): | ||
| flags = os.environ.get(name, "" if name == "CPPFLAGS" else default_flags) | ||
| if flags != cccl_flags and not flags.startswith(cccl_flags + " "): | ||
| os.environ[name] = f"{cccl_flags} {flags}" | ||
|
Comment on lines
+457
to
+462
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: git diff --no-ext-diff --unified=80 3f58a7bee17cef175a614a591b97733c2c0f569d 3aefb73e4ef474692b984a9d8857438ed0b2fc08 -- cuda_core/build_hooks.py cuda_core/tests/test_build_hooks.py
printf '\n--- helper and callers ---\n'
rg -n -C 12 '_configure_cccl_include_flags|_build_cuda_core|CFLAGS|CXXFLAGS|CPPFLAGS' cuda_core/build_hooks.py cuda_core/tests/test_build_hooks.py
printf '\n--- repository guidance ---\n'
find .. -name AGENTS.md -o -name CONTRIBUTING.md -o -name '*guideline*' -o -name '*style*' | head -80Repository: NVIDIA/cuda-python Length of output: 41763 🏁 Script executed: set -e
printf '%s\n' '--- applicable guidance ---'
for f in AGENTS.md cuda_core/AGENTS.md cuda_core/tests/AGENTS.md CONTRIBUTING.md; do
if [ -f "$f" ]; then
printf '\n### %s\n' "$f"
nl -ba "$f"
fi
done
printf '%s\n' '--- head helper and callers ---'
rg -n -F -C 20 -- '_configure_cccl_include_flags' cuda_core/build_hooks.py cuda_core/tests/test_build_hooks.py
printf '%s\n' '--- all test references to helper/caller and environment flags ---'
rg -n -F -C 8 -e '_configure_cccl_include_flags' -e '_build_cuda_core(' -e 'CFLAGS' -e 'CXXFLAGS' -e 'CPPFLAGS' cuda_core/tests cuda_core | sed -n '1,1400p'
printf '%s\n' '--- test declarations and relevant blocks ---'
python3 - <<'PY'
from pathlib import Path
p = Path('cuda_core/tests/test_build_hooks.py')
for i, line in enumerate(p.read_text().splitlines(), 1):
if any(x in line for x in ('def test_', 'class Test', '_capture_cythonize_kwargs', '_build_cuda_core()', '_configure_cccl_include_flags')):
print(f'{i}:{line}')
PY
printf '%s\n' '--- changed test diff ---'
git diff --no-ext-diff --unified=30 3f58a7bee17cef175a614a591b97733c2c0f569d 3aefb73e4ef474692b984a9d8857438ed0b2fc08 -- cuda_core/tests/test_build_hooks.py
printf '%s\n' '--- exact head source ranges around helper and every _build_cuda_core test call ---'
nl -ba cuda_core/build_hooks.py | sed -n '440,510p'
nl -ba cuda_core/tests/test_build_hooks.py | sed -n '380,430p;840,910p;980,1060p;1060,1190p'Repository: NVIDIA/cuda-python Length of output: 41996 🏁 Script executed: set -e
printf '%s\n' '--- scoped guidance ---'
for f in cuda_core/AGENTS.md cuda_core/tests/AGENTS.md; do
printf '\n### %s\n' "$f"
nl -ba "$f"
done
printf '%s\n' '--- helper call and test assertions ---'
rg -n -F -C 6 -e '_configure_cccl_include_flags' -e 'os.environ' -e 'CFLAGS' -e 'CXXFLAGS' -e 'CPPFLAGS' cuda_core/tests/test_build_hooks.py
printf '%s\n' '--- indirect caller test blocks ---'
nl -ba cuda_core/tests/test_build_hooks.py | sed -n '390,425p;870,905p;995,1045p'
printf '%s\n' '--- caller source ---'
nl -ba cuda_core/build_hooks.py | sed -n '451,520p'Repository: NVIDIA/cuda-python Length of output: 41756 suggestion: Add direct tests for CCCL flag ordering and repeated invocation.
|
||
|
|
||
|
|
||
| def _build_cuda_core(debug=False): | ||
| # Customizing the build hooks is needed because we must defer cythonization until cuda-bindings, | ||
| # now a required build-time dependency that's dynamically installed via the other hook below, | ||
|
|
@@ -491,7 +508,9 @@ def module_names(): | |
| yield mod | ||
|
|
||
| # The pinned CCCL must precede the toolkit's bundled headers. | ||
| all_include_dirs = [*_get_cccl_include_dirs(), os.path.join(cuda_path, "include")] | ||
| cccl_include_dirs = _get_cccl_include_dirs() | ||
| all_include_dirs = [*cccl_include_dirs, os.path.join(cuda_path, "include")] | ||
| _configure_cccl_include_flags(cccl_include_dirs) | ||
|
|
||
| # Resolve the C/C++ toolchain (CUDA_PYTHON_TOOLCHAIN). The default (gnu on | ||
| # Linux, msvc on Windows) reproduces the previous build behavior and does | ||
|
|
||
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.
distutilswas removed from the standard library in Python 3.12, so on 3.12+ this import only resolves through setuptools' compatibility shim (_distutils_hack, activated by thedistutils-precedence.pthfile that setuptools installs). Becausebuild_hooksis the build backend and this line runs beforefrom setuptools import ..., the import depends on that.pthhook having been processed. On 3.12 it fails withModuleNotFoundError: No module named 'distutils'under, for example,python -SorSETUPTOOLS_USE_DISTUTILS=stdlib.The stdlib
sysconfigmodule gives the same value (on 3.12,distutils.sysconfig.get_config_var("CFLAGS") == sysconfig.get_config_var("CFLAGS")), so the shim isn't needed here: