Kernels
shangrilar Claude Opus 5.5 commited on
Commit
bc79cf2
·
1 Parent(s): 5adea7d

build: select C++20 when building against torch 2.14+

Browse files

torch 2.14 headers (NGC pytorch 26.09) require C++20, and setup.py hard-codes
-std=c++17, so the extension does not compile against it. Pick the standard
from the installed torch major/minor (nightly and local versions such as
2.14.0a0+nv parse the same way). Builds with torch < 2.14 get exactly the
previous flags.

The existing sm_100 cubin also runs on B300 (sm_103), so no new
architecture targets are needed.

Motif-Tests: wheel builds with torch 2.14 / CUDA 13 (NGC 26.09); full tests/ suite passes on 1x B300 with this change
Motif-Upstream: n/a (this is the upstream)
Motif-Remove-When: n/a

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Files changed (2) hide show
  1. CLAUDE.md +1 -1
  2. setup.py +7 -2
CLAUDE.md CHANGED
@@ -21,7 +21,7 @@ python setup.py build_ext --inplace # build only
21
 
22
  After `pip install -e .`, all imports work directly (`import activation`, `from activation.grouped_poly_norm import ...`). No PYTHONPATH manipulation needed.
23
 
24
- NVCC flags: `-O3 --use_fast_math -std=c++17`, targets sm_80 (A100), sm_89 (L40/4090), sm_90 (H100), sm_100 (B200, CUDA 12.8+).
25
 
26
  ### CI / HuggingFace distribution build
27
 
 
21
 
22
  After `pip install -e .`, all imports work directly (`import activation`, `from activation.grouped_poly_norm import ...`). No PYTHONPATH manipulation needed.
23
 
24
+ NVCC flags: `-O3 --use_fast_math -std=c++17` (`-std=c++20` with PyTorch >= 2.14), targets sm_80 (A100), sm_89 (L40/4090), sm_90 (H100), sm_100 (B200, CUDA 12.8+).
25
 
26
  ### CI / HuggingFace distribution build
27
 
setup.py CHANGED
@@ -38,11 +38,16 @@ INCLUDE_DIRS = [
38
  str(ROOT / "torch-ext"),
39
  ]
40
 
 
 
 
 
 
41
  # CUDA flags matching the existing kernel style
42
  NVCC_FLAGS = [
43
  "-O3",
44
  "--use_fast_math",
45
- "-std=c++17",
46
  # Generate code for common architectures
47
  "-gencode=arch=compute_80,code=sm_80", # A100
48
  "-gencode=arch=compute_89,code=sm_89", # L40/4090
@@ -54,7 +59,7 @@ cuda_version = tuple(int(x) for x in torch.version.cuda.split(".")[:2])
54
  if cuda_version >= (12, 8):
55
  NVCC_FLAGS.append("-gencode=arch=compute_100,code=sm_100")
56
 
57
- CXX_FLAGS = ["-O3", "-std=c++17"]
58
 
59
  ext_modules = [
60
  CUDAExtension(
 
38
  str(ROOT / "torch-ext"),
39
  ]
40
 
41
+ # PyTorch 2.14 headers require C++20; preserve C++17 for older releases.
42
+ # Major/minor parsing also accepts nightly/local versions (e.g. 2.14.0a0+nv).
43
+ torch_version = tuple(int(x) for x in torch.__version__.split(".")[:2])
44
+ CXX_STD = "-std=c++20" if torch_version >= (2, 14) else "-std=c++17"
45
+
46
  # CUDA flags matching the existing kernel style
47
  NVCC_FLAGS = [
48
  "-O3",
49
  "--use_fast_math",
50
+ CXX_STD,
51
  # Generate code for common architectures
52
  "-gencode=arch=compute_80,code=sm_80", # A100
53
  "-gencode=arch=compute_89,code=sm_89", # L40/4090
 
59
  if cuda_version >= (12, 8):
60
  NVCC_FLAGS.append("-gencode=arch=compute_100,code=sm_100")
61
 
62
+ CXX_FLAGS = ["-O3", CXX_STD]
63
 
64
  ext_modules = [
65
  CUDAExtension(