Skip to content

[gfx1250] BF16 GEMM: Triton gemm_a16w16 leaves the rows of C past byte 2^31 unwritten #6402

Open

Description

@jhinpan

Measured on gfx1250 (MI450-class, 256 CUs), ROCm 10.0.0, AITER main cdb1950.

On gfx1250, the Gluon gemm_a16w16 kernel that DEFAULT.json selects (kernel_type bandwidth_bound) leaves every row of C past byte 2^31 unwritten, without an error. It stores C with buffer_store(c_ptr, offs_c) (gemm_a16w16.py L385-L399), so each store is an offset from the start of C. The compute_bound variant stores C through a TDM descriptor (L838-L845) and was right on the large shapes we tried. BF16 shapes without a tuned entry run this kernel by default on gfx1250, so a long prefill through a vocabulary projection can return garbage rows.

aiter.ops.triton.gemm.basic.gemm_a16w16.gemm_a16w16(x, w, dtype=torch.bfloat16) called directly, K = 4096, random BF16 inputs, against an FP32 reference:

M x N C (bytes) Past 2^31 Non-finite outputs First wrong row Row that holds byte 2^31
7067 x 151936 2,147,463,424 no 0 none (rel-L2 0.0017) 7067
7068 x 151936 2,147,767,296 yes 261 7067 7067
8192 x 151936 2,489,319,424 yes 332,463 7067 7067
14134 x 75968 2,147,463,424 no 0 none (rel-L2 0.0017) 14134
14135 x 75968 2,147,615,360 yes 0 14134 14134

The first wrong row is the one that holds byte 2^31. The rows after it keep whatever was in the output buffer. Through tuned_gemm.gemm_a16w16, all 6 of the 1146 untuned BF16 shapes we measured in #6397 whose C is larger than 2^31 bytes came out wrong (M = 8192 to 16384, N = 50016 to 151936, rel-L2 0.36 to 0.90). The one (N, K) with its own Gluon config among them, 129280 x 4096, uses compute_bound from M = 8 on and was right up to 4.24 GB.

AITER's FlyDSL kernel (gemm_a16w16_kernel_gfx1250.py) goes wrong near 2^32 bytes, in a different way. Its buffer stores take a 32-bit byte offset from the start of C, and it relies on the buffer's record count, M * ld_y * elem_bytes (L201-L205), to drop the rows of the last M tile that lie past M. Once the offsets of those rows pass 2^32, they wrap around to the start of C, fall inside the record count, and overwrite the first rows. Through flydsl_hgemm, N = 151936, K = 4096:

M C (bytes) Tile Rows with wrong values Rows of the last tile past M
12288, 13312, 13824 up to 4,200,726,528 256x128x64, 4x2 waves none -
14134 4,294,926,848 256x128x64, 4x2 waves 0 to 201 202
14134 4,294,926,848 128x128x64, 2x2 waves 0 to 73 74

Moving the buffer base of C to each tile's first row would keep the offsets small in both kernels.

@zufayu, could you take a look?

Activity

  1. jhinpan commented on Oct 15, 2026

    @jhinpan
    ContributorAuthor

    Both bugs reproduce on gfx1250 B0 (heliosr-1b114-d04-1, ASIC revision 1) and on the A0 benchtop, on main c118faf (with #6549's DEFAULT.json) and FlyDSL 0.4.0. Every row checked against FP32, output memory filled with NaN first; wrong rows:

    M x N x K C (bytes) Triton default config FlyDSL 128 FlyDSL 256
    7067 x 151936 x 4096 2,147,463,424 0 0 0
    7068 x 151936 x 4096 2,147,767,296 1, from row 7067 0 0
    14080 x 151936 x 4096 4,278,517,760 7013, from row 7067 0 0
    14081 x 151936 x 4096 4,278,821,632 7014, from row 7067 74, from row 0 202, from row 0
    21249 x 50016 x 6144, FP32 4,251,159,936 10516, from row 10733 0 37, from row 0

    #6397 now keeps these outputs off both kernels: torch takes what neither can write. torch is right, but with BF16 output it runs at about 145 TFLOPS on such shapes against FlyDSL's 1,600 to 1,700, so 16384 x 151936 x 4096 takes 141 ms. Fixing the kernels removes that cost.

    A fix, one change per kernel:

    1. Triton (gluon) bandwidth_bound gemm_a16w16 (gemm_a16w16.py L385-L399): add the tile origin to c_ptr in int64 and keep tile-local offsets, as section 2 of [gfx1250] Fix three gluon GEMM correctness bugs and tune the Kimi-K3 a16w16 shapes #4537 did. The buffer then starts at the tile, and its 32-bit offsets stay below BLOCK_M * stride_cm * elem_bytes.
    2. AITER's FlyDSL gfx1250 a16w16 (gemm_a16w16_kernel_gfx1250.py L200-L205, stores at L578-L626): build C's buffer view per M tile from fx.add_offset(arg_y, blk_m * ld_y), the way _mk_side already offsets A and B (L269-L282), with num_records_bytes = min(tile_m, M - blk_m) * ld_y * elem_bytes, and store at the tile-local row. Offsets then stay below tile_m * ld_y * elem_bytes, and the record count still drops the rows past M. The split-K workspace view has the same 32-bit record count and would need the same change.

    Tests: the shapes above as a per-row regression in op_tests (about 15 GB of device memory), with the 2^31 and 2^32 edge rows for BF16 and FP32 output. Once both kernels write such outputs, #6397's 2^31 and 2^32 checks and its torch fallback can go.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions