Skip to content

Fix misaligned local memory access in 02_dump_reg_shmem - #3633

Open
random25160765-collab wants to merge 1 commit into
NVIDIA:mainfrom
random25160765-collab:fix/example02-align-fragment
Open

Fix misaligned local memory access in 02_dump_reg_shmem#3633
random25160765-collab wants to merge 1 commit into
NVIDIA:mainfrom
random25160765-collab:fix/example02-align-fragment

Conversation

@random25160765-collab

@random25160765-collab random25160765-collab commented Sep 13, 2026

Copy link
Copy Markdown

Fixes #3581

examples/02_dump_reg_shmem faults on sm_120 with cudaErrorMisalignedAddress (error 716); the example prints Failed and exits 255.

Why

The iterator accesses its Fragment through a type that requires more alignment than Fragment itself declares:

  • include/cutlass/transform/threadblock/predicated_tile_iterator.h:181AccessType = AlignedArray<Element, AccessSize, (AccessSize * sizeof_bits<Element>::value / 8)>16-byte aligned for half_t
  • include/cutlass/transform/threadblock/predicated_tile_iterator.h:191Fragment = cutlass::Array<Element, ...>2-byte aligned (cutlass::Array declares no alignas; only AlignedArray does)
  • include/cutlass/transform/threadblock/predicated_tile_iterator.h:327AccessType *frag_ptr = reinterpret_cast<AccessType *>(&frag);

When the compiler homes the fragment in local memory, it allocates the frame slot from the declared alignment (2 → offset +0xc) but emits the stores from the cast-implied alignment (16 → STL.128). The slot lands at 12 (mod 16), so the 16-byte store is misaligned and the kernel faults.

Fix

examples/02_dump_reg_shmem/dump_reg_shmem.cu:85:

-  typename GmemIterator::Fragment frag;
+  alignas(16) typename GmemIterator::Fragment frag;

Verification

RTX 5060 (sm_120), CUDA 13.3, main @ 147295a3, unmodified apart from this change:

fragment slot STL.128 offsets result
stock +0xc 0xc, 0x1c, … 0x7c (all ≡ 12 mod 16) fault, exit 255
alignas(16) +0x10 0x10, 0x20, … 0x80 (all 16-byte aligned) completes, exit 0

Registers and frame size are unchanged (40 registers, 144-byte frame) — only the slot offset moves, so the placement is not constrained by the frame itself.

Built with -DCUTLASS_NVCC_ARCHS=120 -DCUTLASS_ENABLE_EXAMPLES=ON; the example prints all of its dumps and exits 0.

Scope

This is the minimal fix for the example. The underlying question — whether the Fragment typedef itself should declare the alignment its own accessors require — affects every caller that declares typename Iterator::Fragment frag; and is left to the maintainers. Details, SASS and a CUTLASS-free reproducer are in #3581.

🤖 Generated with Claude Code

Fragment is a plain cutlass::Array (2-byte aligned for half_t) but the
iterator accesses it through a 16-byte-aligned AlignedArray. When the
fragment is homed in local memory, the frame slot is allocated at +0xc
while the stores are emitted as 16-byte STL.128, so the effective address
is 12 (mod 16) and the kernel faults with cudaErrorMisalignedAddress on
sm_120. Aligning the fragment moves the slot to +0x10 and the example
completes.

Fixes NVIDIA#3581

Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

[BUG] 02_dump_reg_shmem faults on sm_120: Fragment is 2-byte aligned but accessed through a 16-byte-aligned pointer

1 participant