[Bug]: C++17 build cannot compile torch 2.12 headers with nvcc, but C++20 breaks float2(fp8) functional casts
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.7k
- Forks
- 2.8k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 489
Description
System Info
- CPU architecture: x86_64
- GPU: not required to reproduce (compile-only)
- TensorRT-LLM commit:
4476ee3eacc1639c28f7e3e845b67ec246f2e482(main) - CUDA: 13.4, nvcc V13.4.59
- Host compiler: gcc 13.3.0 (Ubuntu 24.04)
- Container:
nvcr.io/nvidia/cuda-dl-base:26.08-cuda13.4-devel-ubuntu24.04 - torch: 2.12.0+cu130 (from
--extra-index-url https://download.pytorch.org/whl/cu130, as pinned byrequirements.txt)
Who can help?
Build / C++ runtime.
Information about the problem
Building outside the prebuilt NGC container hits a C++ standard conflict that
originates entirely inside this repository:
requirements.txt:29pinstorch>=2.12.0a0,<=2.13.0a0.- torch 2.12 ships
share/cmake/Torch/TorchConfig.cmake:158withCXX_STANDARD 20,
andshare/cmake/Caffe2/public/utils.cmake:340sets the same property on its targets.
torch 2.12 therefore requires C++20. cpp/CMakeLists.txt:343setsCMAKE_CXX_STANDARD 17, and line 346 derives
CMAKE_CUDA_STANDARDfrom it.
The two requirements cannot both be satisfied:
At C++17, nvcc cannot compile torch 2.12 headers. Any .cu that transitively
includes ATen/core/function_schema.h fails:
ATen/core/List_inl.h:202:49: error: need 'typename' before
'decltype(((c10::List<T>*)this)->c10::List<T>::impl_->list)::difference_type'
because '...' is a dependent scope
This reaches several targets through pgUtils.h and thUtils.h, for example
tensorrt_llm/kernels/trtllmGenKernels/blockScaleMoe/runner.cu.
At C++20, torch compiles, but 45 functional casts in
cpp/tensorrt_llm/kernels/decoderMaskedMultiheadAttentionUtils.h break, producing
over 150 diagnostics:
decoderMaskedMultiheadAttentionUtils.h(1210): error: no suitable conversion function
from "const __nv_fp8x2_e4m3" to "float" exists
The cause is parenthesized aggregate initialization, added in C++20. float2(x) is a
functional cast in C++17 and selects __nv_fp8x2_e4m3::operator float2(). In C++20 the
same expression is an aggregate initialization of float2, so the compiler tries to
initialize the first member float x from the fp8 value and fails.
Reproduction
Three lines, no GPU and no TensorRT-LLM checkout required:
#include <cuda_fp8.h>
__global__ void k(const __nv_fp8x2_e4m3 a, float2* o) { *o = float2(a); }
nvcc -std=c++17 -arch=sm_90 -c repro.cu # succeeds
nvcc -std=c++20 -arch=sm_90 -c repro.cu # fails with the error above
The full build was run as:
python scripts/build_wheel.py --cpp_only --use_ccache \
-a "90-real;100-real;103-real" -j 48 --no-venv
Suggested fix
Replacing the functional cast with an explicit static_cast compiles under both
standards and keeps the same conversion operator, so the generated code is unchanged:
- float2 fb0 = float2(fp8_2[0]);
+ float2 fb0 = static_cast<float2>(fp8_2[0]);
Verified:
| expression | C++17 | C++20 |
|---|---|---|
float2(a) |
compiles | fails |
static_cast<float2>(a) |
compiles | compiles |
45 lines in decoderMaskedMultiheadAttentionUtils.h use the affected pattern. The
change is mechanical and safe at C++17, so it does not require the project to move to
C++20; it only removes the blocker if and when the standard is raised.
I am happy to open a PR with this change if the approach looks right.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in cpp/tensorrt_llm/kernels/decoderMaskedMultiheadAttentionUtils.h and review the 45 functional casts identified in the issue. Verify the minimal repro with nvcc under C++17 and C++20, update the affected casts as described, then run the cpp-only build to confirm both the torch headers and CUDA kernels compile.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, pytorch
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100