Skip to content

[Common] Fix clang host-compiler builds with CUDA 13: align CUtensorMap locals to 128 bytes - #4035

Open
ArchanaChetan07 wants to merge 1 commit into
NVIDIA:mainfrom
ArchanaChetan07:fix/clang-host-compiler
Open

ArchanaChetan07 wants to merge 1 commit into
NVIDIA:mainfrom
ArchanaChetan07:fix/clang-host-compiler

Conversation

@ArchanaChetan07

@ArchanaChetan07 ArchanaChetan07 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

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:

transformer_engine/common/cast/mxfp8/dequantize_mxfp8.cuh(307): error: alignment cannot be set to less than the default alignment
transformer_engine/common/cast/fp8/gated_fp8.cuh(351): error: alignment cannot be set to less than the default alignment
transformer_engine/common/hadamard_transform/hadamard_transform.cu(623): error: alignment cannot be set to less than the default alignment

CUDA 13's cuda.h declares CUtensorMap with alignas(128). In CUDA 12 it was alignas(64). TE declares its host-side tensor maps as alignas(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 is cicc (device front end, --clang mode) segfaulting about 5 s into util/cast.cu, and the alignas change does not affect it. On current main, cast/cast.cu builds 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

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • alignas(64) CUtensorMap → alignas(128) CUtensorMap in 15 files under transformer_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 .cu files whose nvcc -M dependencies include one of the 15 changed files: all 24 activation TUs, the 5 cast TUs, and 4 Hadamard TUs.

Toolchain Host Tree Result
CUDA 13.0 clang 18 main (3eac423) 33 / 33 affected TUs fail (all with the alignment error above)
CUDA 13.0 clang 18 this PR 94 / 95 of all non-RTC TUs build ¹, all 33 affected TUs included
CUDA 13.0 gcc 13 this PR 33 / 33 affected TUs build
CUDA 12.8 clang 18 this PR 33 / 33 affected TUs build
CUDA 12.8 gcc 13 this PR 33 / 33 affected TUs build

¹ The only failure is nvshmem_api/nvshmem_waitkernel.cu (nvshmem.h not installed locally). It doesn't include any changed file.

A full cast/cast.cu compile 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-side CUtensorMap locals on CUDA 12.

Repro (single TU)

# CUDA 13 nvcc, clang++ host; fails on main, passes with this PR
nvcc -ccbin clang++ -std=c++17 --expt-relaxed-constexpr -O3 -Xcompiler=-fPIC \
  -I transformer_engine -I transformer_engine/common/include \
  -I $CUDNN_FRONTEND_INCLUDE -isystem $CUDA_HOME/include -isystem $CUDA_HOME/include/cccl \
  -isystem $CUDNN_INCLUDE -isystem $NCCL_INCLUDE \
  --generate-code=arch=compute_100a,code=sm_100a \
  -x cu -c transformer_engine/common/cast/cast.cu -o /tmp/cast.o
# or a full build: CUDAHOSTCXX=clang++ NVTE_CUDA_ARCHS=100a pip install --no-build-isolation -v .

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

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
ArchanaChetan07 marked this pull request as ready for review December 5, 2026 05:06
@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

Raises local CUtensorMap alignment from 64 to 128 bytes across 15 cast and Hadamard files to address CUDA 13 builds using clang as the host compiler.

  • CUDA tensor-map locals now use 128-byte alignment.

Reviews (1) · Last reviewed commit: "[Common] Align CUtensorMap locals to 128..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant