Files
Linjun-AMD 5c7b7ec3f1 [rocm-libraries] ROCm/rocm-libraries#7272 (commit d02f3c0)
[ck_tile][fmha_bwd] Fix sink_host OOB in group mode reference
 runner (#7272)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

## Summary

In `fmha_bwd_runner.hpp`, the `sink_host` `HostTensor` is allocated with
first
dimension `shape_batch` (= 1 in group mode), but the reference forward
loop
accesses `sink_host(wb, i_h)` with `wb ∈ [0, batch-1]`. For any `wb >=
1` this
is an out-of-bounds heap read, silently corrupting the reference forward
math
chain (`lse_host`, `o_host`) and turning the bwd-side `d_sink_head_acc`
  reference into non-deterministic garbage.

`HostTensor::operator()` does not bounds check, so the OOB is not caught
at
runtime. This manifests as intermittent `tile_example_fmha_bwd` failures
(25–67% fail rate) when `-sink_grad=1` is combined with `-mode=1` (group
mode),
  with bit-exact but spurious `max_err` values like 4.27 / 14.6.

  ## Fix

One-line: allocate `sink_host` with `batch` (the real per-batch dim)
instead of
  `shape_batch`, mirroring how `sink_host` is accessed by the loop.

  ```diff
  -    sink_grad ? std::array<ck_tile::index_t, 2>{shape_batch, nhead}
  +    sink_grad ? std::array<ck_tile::index_t, 2>{batch, nhead}

  Repro

  tile_example_fmha_bwd -b=2 -h=2 -s=516 -s_k=253 -prec=bf16 -d=72 \
    -bias=n -dbias=0 -p_drop=0 -iperm=1 -operm=1 -deterministic=0 \
    -v=3 -mode=1 -kname=1 -sink_grad=1

  Verification

  - 0/30 fail on the repro config after fix
  - Baselines (before fix):
    - sink=1, mask=n: 25% fail rate (p ≈ 1.8e-4)
    - sink=1, mask=t: 67% fail rate (p ≈ 6e-15)

  Attribution

Shape bug introduced together with sink_grad in #5504. Unrelated to
#6914
  (which is a fwd-only fix on a different code path)
```

## Submission Checklist

- [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
2026-05-13 08:49:13 +00:00
..
2026-02-02 16:04:40 +08:00

CK Tile Testing Guide

This document describes the test organization and available test targets for CK Tile operations.

Overview

CK Tile tests are organized with multiple levels of granularity to support different development workflows:

  1. Global test labels - Run tests across all operations
  2. Operation-specific umbrella targets - Run all tests for a specific operation
  3. Individual test executables - Run specific tests

Global Test Labels

These targets run tests across all CK operations (not just CK Tile):

ninja smoke

Run fast smoke tests (tests that complete within ~30 seconds on gfx90a).

ninja smoke

ninja regression

Run slower, more comprehensive regression tests.

ninja regression

ninja check

Run ALL available tests in the entire codebase.

ninja check

Operation-Specific Umbrella Targets

These targets allow you to run all tests for a specific CK Tile operation. This is useful when making changes to a particular operation and wanting to validate all related tests without running the entire test suite.

GEMM Operations

ck_tile_gemm_tests

Run all basic GEMM pipeline tests (memory, compute variants, persistent, etc.)

ninja ck_tile_gemm_tests

Test executables included:

  • test_ck_tile_gemm_pipeline_mem
  • test_ck_tile_gemm_pipeline_compv3
  • test_ck_tile_gemm_pipeline_compv4
  • test_ck_tile_gemm_pipeline_persistent
  • test_ck_tile_gemm_pipeline_compv6
  • test_ck_tile_gemm_pipeline_comp_async (gfx95 only)
  • test_ck_tile_gemm_pipeline_*_wmma variants (gfx11/gfx12 only)

ck_tile_gemm_block_scale_tests

Run all GEMM tests with block-scale quantization (AQuant, BQuant, ABQuant, etc.)

ninja ck_tile_gemm_block_scale_tests

Test executables included: 29 test executables covering:

  • AQuant tests (memory pipelines, base layouts, prefill, preshuffle, transpose)
  • ABQuant tests (base, padding, preshuffle)
  • BQuant tests (1D/2D variants, transpose)
  • BQuant with PreshuffleB (decode/prefill, 1D/2D)
  • BQuant with PreshuffleQuant (decode/prefill, 1D/2D)
  • RowColQuant and TensorQuant tests

ck_tile_gemm_streamk_tests

Run all GEMM StreamK tests (tile partitioner, reduction, smoke, extended)

ninja ck_tile_gemm_streamk_tests

Test executables included:

  • test_ck_tile_streamk_tile_partitioner
  • test_ck_tile_streamk_reduction
  • test_ck_tile_streamk_smoke
  • test_ck_tile_streamk_extended

ck_tile_grouped_gemm_quant_tests

Run all grouped GEMM quantization tests

ninja ck_tile_grouped_gemm_quant_tests

Test executables included:

  • test_ck_tile_grouped_gemm_quant_rowcol
  • test_ck_tile_grouped_gemm_quant_tensor
  • test_ck_tile_grouped_gemm_quant_aquant
  • test_ck_tile_grouped_gemm_quant_bquant
  • test_ck_tile_grouped_gemm_quant_bquant_preshuffleb

Other Operations

ck_tile_fmha_tests

Run all FMHA (Flash Multi-Head Attention) tests

ninja ck_tile_fmha_tests

Test executables included: Forward and backward tests for fp16, bf16, fp8bf16, fp32

ck_tile_reduce_tests

Run all reduce operation tests

ninja ck_tile_reduce_tests

Test executables included:

  • test_ck_tile_reduce2d
  • test_ck_tile_multi_reduce2d_threadwise
  • test_ck_tile_multi_reduce2d_multiblock

Individual Test Executables

You can also build and run individual test executables:

Build a specific test

ninja test_ck_tile_gemm_pipeline_mem

Run a specific test directly

./build/bin/test_ck_tile_gemm_pipeline_mem

Run a specific test through ctest

ctest -R test_ck_tile_gemm_pipeline_mem --output-on-failure