fix: move pipeline barriers into dynamic SharedStorage for 128-byte alignment (#42) - #87
fix: move pipeline barriers into dynamic SharedStorage for 128-byte alignment (#42)#87XFDG wants to merge 1 commit into
Conversation
…lignment (Tencent#42) The static `__shared__ uint64_t writable/readable` arrays were placed by the compiler before the dynamic shared-memory region. The dynamic base alignment depends only on the static allocation's alignment, not on the `alignas(128)` on the `extern __shared__` declaration — so the TMA buffers (A, B, Y) could land at non-128-aligned offsets, causing TMA loads to fail with Misaligned on SM120 (Blackwell). Fix: move barriers into a `SharedStorage` struct inside the dynamic allocation. The dynamic base is then aligned to `alignof(SharedStorage)=128`, and every buffer member (also `alignas(128)`) is at a provable 128-multiple offset. This is the canonical CUTLASS pattern. Changes: - config.h: add SharedStorage struct to both GroupGEMMFp8Config and GroupGEMMBlockWiseFp8Config; get_shm_size() returns sizeof(SharedStorage). - kernels.cuh: replace static barriers + extern uint8_t[] with extern SharedStorage storage[]; pointer arithmetic for buffer offsets preserved exactly. Verified: PTX inspection confirms typed extern __shared__ struct[] emits .align 128 and all buffer offsets are 128-multiple. No functional change on SM90 (H200/H20); forward-looking hardening for SM120. Co-Authored-By: Claude <noreply@anthropic.com>
|
hi,I'd like to ask if you have successfully migrated HPC-OPS to the SM120? |
|
Hi @imusong, thanks for the question! No, we haven't tested on SM120 hardware — the available GPUs (H200, SM90a) don't include SM120. The fix is based on:
If you have SM120 hardware available, we'd be happy to test it there. Otherwise, we believe this is a correctness improvement that is safe on SM90 and fixes the alignment issue on SM120. |
Summary
__shared__arrays into a dynamically-allocatedSharedStoragestruct in bothGroupGEMMFp8ConfigandGroupGEMMBlockWiseFp8Config.get_shm_size()now returnssizeof(SharedStorage)so the launch-side allocation includes the barriers.Root cause
The kernels declared static
__shared__ uint64_t writable[kStage]/readable[kStage]before theextern __shared__dynamic region. The compiler places static SMEM first at a fixed offset; the dynamic base's alignment depends only on the static allocation's alignment — not onalignas(128)written on theextern __shared__declaration. PTX inspection confirms:On SM120 (Blackwell) this causes TMA loads to fail with Misaligned because the A/B buffers are not 128-byte aligned.
Fix
Move barriers inside the dynamic allocation as a typed
SharedStoragestruct. PTX confirms the typedextern __shared__declaration forces the dynamic base to 128:All buffer members (
alignas(128)) then land at provable 128-multiple offsets. This is the canonical CUTLASSSharedStoragepattern.Files changed
src/group_gemm/config.hSharedStoragestruct to both configs;get_shm_size()→sizeof(SharedStorage)(+36 lines)src/group_gemm/kernels.cuhextern uint8_t[]withextern SharedStorage storage[](−10 +11 lines)Testing
nvcc -arch=sm_90a -ptxconfirms.align 128on the typed dynamic declaration and all buffer offsets are 128-multiple.References