Repository navigation
[Common] Fix clang host-compiler builds with CUDA 13: align CUtensorMap locals to 128 bytes - #4035
Open
ArchanaChetan07 wants to merge 1 commit into
Open
ArchanaChetan07 wants to merge 1 commit into
ArchanaChetan07 wants to merge 1 commit into
Conversation
CUDA 13's cuda.h declares CUtensorMap with alignas(128) (it was alignas(64) in CUDA 12). Declaring a CUtensorMap variable with alignas(64) therefore asks for less than the type's own alignment, which is ill-formed C++. With g++ as the nvcc host compiler cudafe++ accepts it, but with clang++ (-ccbin clang++ / CUDAHOSTCXX=clang++) it fails with: error: alignment cannot be set to less than the default alignment That breaks every TU that includes the cast/activation/hadamard kernels (cast.cu, the activation TUs, hadamard_transform*.cu, ...). Use alignas(128) instead, as the grouped TMA code already does. 128 is the native alignment on CUDA 13 and a valid over-alignment on CUDA 12, so nothing changes for gcc builds. Refs NVIDIA#2384 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: ArchanaChetan07 <[email protected]>
ArchanaChetan07
marked this pull request as ready for review
December 5, 2026 05:06
Contributor
Confidence Score: 5/5
[Medium impact] This PR appears safe to merge; no actionable issues were found. SummaryRaises local
Reviews (1) · Last reviewed commit: "[Common] Align CUtensorMap locals to 128..." · Reviewed by Greptile |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Building TE with clang++ as the nvcc host compiler (
CUDAHOSTCXX=clang++/-ccbin clang++) fails on current main with CUDA 13. Every TU that pulls in the cast, activation or Hadamard kernels stops in cudafe++ with:CUDA 13's
cuda.hdeclaresCUtensorMapwithalignas(128). In CUDA 12 it wasalignas(64). TE declares its host-side tensor maps asalignas(64) CUtensorMap ..., which on CUDA 13 asks for less than the type's own alignment. That is ill-formed C++ ([dcl.align]/5). In gcc mode, cudafe++ lets it through, and in clang mode it rejects it.This PR changes those 53 declarations to
alignas(128), as the grouped TMA code already does (cast/core/grouped_tma.cuh,group_dequantize_mxfp8.cuh). 128 is the native alignment on CUDA 13 and a valid over-alignment on CUDA 12. These are host-side local variables that get filled and passed to kernels by value, so there is no ABI or kernel-signature change, and gcc builds are unaffected.About the original report in #2384 (v2.8/v2.9, CUDA 12.8, clang 18, segfault in
util/cast.cu): I reproduced that crash on v2.9. It iscicc(device front end,--clangmode) segfaulting about 5 s intoutil/cast.cu, and thealignaschange does not affect it. On current main,cast/cast.cubuilds cleanly with CUDA 12.8 + clang 18, so that crash appears to be gone after the cast refactor. The remaining clang failure on main is the CUDA 13 one fixed here.Refs #2384
Type of change
Changes
alignas(64) CUtensorMap→alignas(128) CUtensorMapin 15 files undertransformer_engine/common/{cast,hadamard_transform}(53 declarations, no other changes; clang-format 18.1.6 clean).Verification
Environment: WSL2 Ubuntu 24.04, g++ 13.3.0, clang 18.1.8 (conda-forge, using system libstdc++ 13), nvcc 13.0.88 (pip) and nvcc 12.8.93 (conda-forge). TUs were compiled directly with nvcc using the CMake include set,
-std=c++17 --expt-relaxed-constexpr -O3 -Xcompiler=-fPIC, for one arch (compute_100a, PTX). "Affected TUs" means the 33.cufiles whosenvcc -Mdependencies include one of the 15 changed files: all 24 activation TUs, the 5 cast TUs, and 4 Hadamard TUs.¹ The only failure is
nvshmem_api/nvshmem_waitkernel.cu(nvshmem.hnot installed locally). It doesn't include any changed file.A full
cast/cast.cucompile to SASS (--generate-code=arch=compute_100a,code=sm_100a) also succeeds with clang 18 on both CUDA 13.0 and 12.8.Builds were run on a base of 3eac423. The branch was then rebased onto 3db2f13, which doesn't touch any of the changed or affected files, and was not rebuilt after the rebase.
Not done: a full
pip install/ CMake wheel build, or any runtime test. The change doesn't affect codegen beyond possibly 64 extra bytes of stack alignment for host-sideCUtensorMaplocals on CUDA 12.Repro (single TU)
Checklist:
Prepared with AI assistance (Claude Code).
🤖 Generated with Claude Code