Skip to content

build: unify compiler flags - #2998

Merged
juenglin merged 3 commits into
NVIDIA:mainfrom
juenglin:consolidate-toolchain-helpers
Oct 2, 2026
Merged

juenglin merged 3 commits into
NVIDIA:mainfrom
juenglin:consolidate-toolchain-helpers

Conversation

@juenglin

@juenglin juenglin commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1882. Implements part of #2965 (flag unification), which this PR supersedes.

The two packages' compiler flag sets had drifted for legacy reasons; this PR audits the differences and aligns them.

Changes

cuda_bindings/build_hooks.py

  • Drop -fpermissive and -fno-var-tracking-assignments. These were gcc-only and not needed by the current Cython-generated C++; confirmed by a clean rebuild after removal.
  • Change -O3 to -O2, consistent with cuda_core. The -O3 → -O2 step is not the source of the measured launch_{256,512}_args latency difference vs. -std=c++17; the C++ standard is.
  • Add /std:c++14 and /O2 on MSVC (previously missing entirely).
  • Expand the Linux flag lines with explanatory comments, including why bindings stays on C++14 and why -Wno-deprecated-declarations is kept.

cuda_core/build_hooks.py

  • Add /O2 on MSVC. Modern setuptools no longer forces /Ox, so the optimization level must be set explicitly for symmetry with Linux -O2.
  • Add comments at both the MSVC and Linux sites explaining why C++17 is required (structured bindings and if constexpr in cuda/core/_cpp/).

Not addressed in this PR (intentional differences noted in #1882):

  • Debug mode (-g -O0 -D _GLIBCXX_ASSERTIONS) was already present in both packages before this PR.
  • Cython directive differences (binding, warn.deprecated.IF) are out of scope.

Tests

  • TestResolveToolchain in both packages updated: bindings' test_gnu_keeps_gcc_only_flags replaced by test_linux_opt_flag_set (asserts -O2, no -O3, no gnu-only flags); test_msvc_opt_flag_set added to both.

Test plan

  • pytest cuda_bindings/tests/test_build_hooks.py --noconftest — 56 passed, 2 skipped
  • pytest cuda_core/tests/test_build_hooks.py --noconftest — 111 passed, 2 skipped
  • cuda_bindings rebuilt cleanly with the default gnu toolchain — no new errors or warnings
  • ruff check + ruff format --check clean on all touched files
  • Full CI

@copy-pr-bot

copy-pr-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module labels Oct 2, 2026
@juenglin

juenglin commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8e06f2c

@juenglin juenglin added the CI/CD CI/CD infrastructure label Oct 2, 2026
@juenglin juenglin self-assigned this Oct 2, 2026
@juenglin juenglin added this to the cuda.core 1.3.0 milestone Oct 2, 2026
@juenglin
juenglin requested a review from Andy-Jost October 2, 2026 15:14
@juenglin
juenglin marked this pull request as ready for review October 2, 2026 15:23
@juenglin juenglin mentioned this pull request Oct 2, 2026
6 of 7 tasks
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

Comment on lines +176 to +183
assert "-std=c++14" in cargs
assert "-Wno-deprecated-declarations" in cargs
assert "-g0" in cargs
assert "-O2" in cargs
assert "-O3" not in cargs
assert "-fpermissive" not in cargs
assert "-fno-var-tracking-assignments" not in cargs
assert "-Wl,--strip-all" in largs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this kind of test, but it seems unnecessary

Reuse the wheel Cython cache in tests/cython/build_tests.py so the
new test stage can hit CUDA_PYTHON_CYTHON_CACHE_DIR.

(cherry picked from commit 392178690f26c7d7cb8117a5556a70f2c728c321)
Close the audit from NVIDIA#1882. The two packages' Linux and MSVC flag sets had
drifted for legacy reasons; both now go through the same structure.

Changes in cuda-bindings:
- Drop -fpermissive and -fno-var-tracking-assignments (gcc-only; not
  needed by current Cython-generated C++; confirmed by a rebuild).
- Change -O3 to -O2 (consistent with cuda-core; -O3 was not the source
  of the measured launch_{256,512}_args latency difference vs c++17).
- Add /std:c++14 and /O2 on MSVC (was missing entirely).
- Split '-std=c++14 -Wno-deprecated-declarations' onto separate lines
  with an explanatory comment on each.

Changes in cuda-core:
- Add /O2 on MSVC (modern setuptools no longer forces /Ox).
- Add comments at both the MSVC and Linux flag sites explaining why
  c++17 is required (structured bindings / if constexpr in _cpp/).

Tests:
- Update the bindings TestResolveToolchain: replace test_gnu_keeps_gcc_only_flags
  with test_linux_opt_flag_set (asserts -O2, not -O3; no gnu-only flags);
  add test_msvc_opt_flag_set; update test_gnu_sets_env_and_flags assertions.
- Add test_linux_opt_flag_set and test_msvc_opt_flag_set to the core
  TestResolveToolchain; update the comment in test_gnu_sets_env_and_flags.
@juenglin
juenglin force-pushed the consolidate-toolchain-helpers branch from 8e06f2c to a04079f Compare October 2, 2026 17:23
@juenglin
juenglin enabled auto-merge (squash) October 2, 2026 17:28
@juenglin

juenglin commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a04079f

@juenglin
juenglin merged commit 5cddc15 into NVIDIA:main Oct 2, 2026
225 of 227 checks passed
juenglin added a commit to juenglin/cuda-python that referenced this pull request Oct 2, 2026
…in-helpers2

Keep the _build_shared refactor where it overlapped NVIDIA#2998's inlined flag
and test copies now on main.
github-actions Bot pushed a commit that referenced this pull request Oct 3, 2026
Removed preview folders for the following PRs:
- PR #2880
- PR #2917
- PR #2947
- PR #2965
- PR #2996
- PR #2998
- PR #3003
- PR #3005
- PR #3008
- PR #3010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda-core build_hooks.py missing compiler/linker flags present in cuda-bindings

2 participants