From 7ccd9bd0dbf5e06b03724b915bc138debf45ce12 Mon Sep 17 00:00:00 2001 From: leconcio Date: Mon, 19 Oct 2026 11:55:54 -0400 Subject: [PATCH] Let PyTorch choose the C++ standard when building ops (#341) torch.utils.cpp_extension compiles extensions with -std=c++20 since PyTorch 2.12, but the op builder appended -std=c++17 to the host C++ flags and to the ROCm hipcc flags. The later flag wins, so every op was compiled as C++17. PyTorch 2.14 headers require C++20 (ATen.h raises "C++20 or later compatible compiler is required", and c10 uses std::strong_ordering and requires-clauses), so every op fails to build, both when JIT-built on first use and when prebuilt with APEX_BUILD_*=1. Remove every hard-coded -std flag from the op builder: from cxx_args(), from the ROCm branch of nvcc_args(), and the CUDA-version-based selection in the CUDA branch. torch.utils.cpp_extension adds the standard that matches the installed PyTorch headers whenever no -std flag is passed, on both the JIT and setup.py paths. This follows NVIDIA/apex#2006, which made the same change upstream. Co-authored-by: Claude Opus 5.5 --- op_builder/builder.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/op_builder/builder.py b/op_builder/builder.py index 2a573d5cf..907f71ccb 100644 --- a/op_builder/builder.py +++ b/op_builder/builder.py @@ -770,7 +770,7 @@ def cxx_args(self): if sys.platform == "win32": return ['-O2'] else: - return ['-O3', '-std=c++17', '-g', '-Wno-reorder'] + return ['-O3', '-g', '-Wno-reorder'] def nvcc_args(self): if self.build_for_cpu: @@ -779,7 +779,7 @@ def nvcc_args(self): if self.is_rocm_pytorch(): ROCM_MAJOR, ROCM_MINOR = self.installed_rocm_version() args += [ - '-std=c++17', '-U__HIP_NO_HALF_OPERATORS__', '-U__HIP_NO_HALF_CONVERSIONS__', + '-U__HIP_NO_HALF_OPERATORS__', '-U__HIP_NO_HALF_CONVERSIONS__', '-U__HIP_NO_HALF2_OPERATORS__', '-DROCM_VERSION_MAJOR=%s' % ROCM_MAJOR, '-DROCM_VERSION_MINOR=%s' % ROCM_MINOR @@ -792,16 +792,8 @@ def nvcc_args(self): except ValueError: nvcc_threads = min(os.cpu_count(), 8) - cuda_major, cuda_minor = installed_cuda_version() - if cuda_major > 10: - if cuda_major == 12 and cuda_minor >= 5: - std_lib = '-std=c++20' - else: - std_lib = '-std=c++17' - else: - std_lib = '-std=c++14' args += [ - '-allow-unsupported-compiler' if sys.platform == "win32" else '', '--use_fast_math', std_lib, + '-allow-unsupported-compiler' if sys.platform == "win32" else '', '--use_fast_math', '-U__CUDA_NO_HALF_OPERATORS__', '-U__CUDA_NO_HALF_CONVERSIONS__', '-U__CUDA_NO_HALF2_OPERATORS__', f'--threads={nvcc_threads}' ]