Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c2ccdc2
feat(ck-tile): enable grouped rowcolquant/tensorquant GEMM bridges on…
ozturkosu Sep 1, 2026
32f66c6
fix(ck-tile): harden gfx1250 rowcolquant/tensorquant bridges against …
ozturkosu Sep 3, 2026
8c4a1dd
Merge branch 'develop' into users/muozturk/ck/rowcolquant-tensorquant…
ozturkosu Sep 9, 2026
36c88c1
fix(ck-tile): exact gfx1250 tile match and dynamic TileN diagnostics
ozturkosu Sep 9, 2026
c17151f
fix(ck-tile): version the .so cache key and normalize caller-supplied…
ozturkosu Sep 9, 2026
6bbbcb4
fix(ck-tile): reject gfx1250-invalid warp maps and warp tiles at vali…
ozturkosu Sep 10, 2026
99c7b1e
fix(ck-tile): refuse to build a gfx1250 grouped-quant library with an…
ozturkosu Sep 10, 2026
fd4a1b3
docs(ck-tile): correct the 8-warp gfx1250 claim to match the measured…
ozturkosu Sep 10, 2026
13a0f7d
docs(ck-tile): separate the warp-map and warp-tile failure modes
ozturkosu Sep 10, 2026
ce25d60
fix(ck-tile): close two holes in the gfx1250 guards found in review
ozturkosu Sep 10, 2026
678fb56
fix(ck-tile): scope the gfx1250 warp-map restriction to this operator
ozturkosu Sep 10, 2026
6795101
fix(ck-tile): align the 8-warp figures to one archive, and fold the g…
ozturkosu Sep 10, 2026
f74c979
Merge branch 'develop' into users/muozturk/ck/rowcolquant-tensorquant…
ozturkosu Sep 10, 2026
e1f8f28
refactor(ck-tile): make the arch-normalization comment match the code
ozturkosu Sep 10, 2026
f01bd53
fix(ck-tile): normalize the arch once per validator, not per comparison
ozturkosu Sep 10, 2026
43bda43
feat(ck-tile): give the codegen default config an architecture
ozturkosu Sep 10, 2026
25f9d41
fix(ck-tile): reject an unrecognized --gfx-arch instead of silently u…
ozturkosu Sep 10, 2026
0e879ed
fix(ck-tile): normalize the arch before validating it, not after
ozturkosu Sep 10, 2026
507e363
fix(ck-tile): confine the warp-table normalization to gfx1250
ozturkosu Sep 11, 2026
b7a262f
docs(ck-tile): drop a false justification for the raw warp-table lookup
ozturkosu Sep 10, 2026
742fe7f
docs(ck-tile): correct where suffixed gfx names actually come from
ozturkosu Sep 10, 2026
d81eebf
Merge develop into grouped quant gfx1250 enablement
ozturkosu Sep 18, 2026
728a208
fix(ck): address grouped quant architecture and ABI review feedback
ozturkosu Sep 18, 2026
ae2ea2c
Merge latest develop dispatcher CI and resolve quant bridge conflicts
ozturkosu Sep 18, 2026
4aefed2
fix(ck): align standalone quant CMake architecture features
ozturkosu Sep 18, 2026
031ef07
fix(ck): scope quant warp restrictions to grouped bridges
ozturkosu Sep 18, 2026
aff4c2f
fix(ck): isolate grouped quant architecture features
ozturkosu Sep 18, 2026
110c3ee
fix(ck): require target for custom grouped quant tiles
ozturkosu Sep 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static std::atomic<int> g_ref_count{0};
// Architectures this bridge is known to work on. These fp8/bf8 CompV3 kernels need
// native FP8, so gfx90a is deliberately absent -- it compiles but produces NaN.
// Enabling a new target is a one-line addition here plus a CMake arch entry.
static constexpr const char* kSupportedArchs[] = {"gfx942", "gfx950"};
static constexpr const char* kSupportedArchs[] = {"gfx942", "gfx950", "gfx1250"};
Comment thread
ozturkosu marked this conversation as resolved.
Resolved

Comment thread
ozturkosu marked this conversation as resolved.
Resolved
// True if `arch` starts with any entry of kSupportedArchs. Prefix-matching, because
// hipDeviceProp_t::gcnArchName carries feature suffixes (e.g. "gfx942:sramecc+:xnack-").
Expand All @@ -88,6 +88,11 @@ static bool is_supported_arch(const std::string& arch)
return false;
}

// True if this .so was compiled for a gfx12-class target (WMMA, wave32).
// Used to scope the M%4 rejection below to the architecture where the defect is
// actually observed, so gfx942/gfx950 callers are not restricted by it.
static bool is_gfx12_arch(const std::string& arch) { return arch.rfind("gfx12", 0) == 0; }

extern "C" {

/**
Expand Down Expand Up @@ -166,7 +171,21 @@ int dispatcher_init() { return dispatcher_initialize(); }
* k_batch - split-K factor (1 = no split)
* time_ms - output: kernel execution time in ms (may be NULL)
*
* Returns 0 on success, negative on error.
* Shape constraints (validated on gfx1250 with the default config; violations are
* rejected with an explanatory message and no output is written):
* K % 16 == 0 - required even when the kernel was generated with pad_k=true.
* pad_k covers the K-loop tail, not the global-load vector width.
* N % TileN == 0 - required whenever the kernel was generated with pad_n=false.
* TileN is 64 in the default config.
* M % 4 == 0 - gfx12 targets only. The RowColQuant per-row A-scale tile window
* has an unpadded M tail that zeroes row M-1 of C. See the guard
* in the body for the full explanation; gfx942/gfx950 are not
* subject to this restriction.
*
* Returns 0 on success, negative on error:
* -1 argument rejected by this bridge (including the constraints above)
* -2 argument rejected by the kernel's own IsSupportedArgument()
* -3 kernel launch threw
*/
int dispatcher_run_gemm(const void* A,
const void* B,
Expand Down Expand Up @@ -224,6 +243,57 @@ int dispatcher_run_gemm(const void* A,
return -1;
}

// ---------------------------------------------------------------------------
// Documented shape constraints.
//
// These were established empirically on gfx1250 with the default config and are
// enforced here so a violation produces an explanation instead of either a bare
// "unsupported args" code or, worse, a wrong answer.
// ---------------------------------------------------------------------------

// N must be a whole number of N-tiles unless the kernel pads N. This is derived
// from the kernel's own constants rather than hardcoded, so it stays correct if
// the tile or the padding trait changes.
if(!SelectedKernel::kPadN && (N % SelectedKernel::TileN) != 0)
{
std::cerr << "dispatcher_run_gemm: N must be a multiple of " << SelectedKernel::TileN
<< " for this kernel (it was generated with pad_n=false, so N has to be a "
<< "whole number of N-tiles); got N=" << N << "\n";
return -1;
}

// gfx12 only: the RowColQuant per-row A-scale path drops the final row of C when
// M is not a multiple of 4, writing zeros into row M-1 while leaving every other
// row correct to ~3e-4. The kernel returns success, so without this check the
// caller gets a silent wrong answer -- at M=1 the entire output is zero.
//
// Cause: MakeAQBlockWindow() builds the AQ view with
// make_naive_tensor_view(aq_ptr, {M, N}, {1, 0}, ...)
// and then, as its own comment says, creates the tile window with "no padding for
// AQ" -- unlike the A/B/C windows, which get right-pad transforms driven by
// kPadM/kPadN/kPadK. The M axis of that broadcast view therefore has an unguarded
// tail. The BQ view is the mirror image ({M, N} strided {0, 1}) and has the same
// unguarded tail on N; it is simply never exercised, because pad_n=false already
// forces N to a multiple of TileN (64) and hence of 4.
//
// The fix belongs in ck_tile's shared quant kernel header, not in this bridge:
// that header is common to gfx942/gfx950, where the behaviour has not been
// measured. Rejecting here is deliberately the narrow, reversible option -- it
// converts a silent wrong answer into a clean refusal without touching code paths
// that other architectures depend on. Remove this guard once the AQ tail is
// padded upstream.
if(is_gfx12_arch(std::string(GFX_ARCH)) && (M % 4) != 0)
{
std::cerr << "dispatcher_run_gemm: M must be a multiple of 4 on " << GFX_ARCH
<< " for RowColQuant; got M=" << M << ". The per-row A-scale (AQ) tile "
<< "window is built without a padding transform, so row M-1 of C is "
<< "written as zero while the remaining rows are correct. Refusing rather "
<< "than returning a silently wrong result. Pad M up to a multiple of 4 "
<< "and slice the result, or use the TensorQuant bridge, which applies "
<< "scalar scales and is unaffected.\n";
return -1;
}

// Only packed (contiguous) layouts are supported for A, B, C.
// stride_AQ and stride_BQ are unused here; the kernel uses broadcast strides (0).
//
Expand Down Expand Up @@ -429,7 +499,17 @@ int dispatcher_run_gemm(const void* A,

if(exec_time < 0.0f)
{
std::cerr << "dispatcher_run_gemm: kernel reported unsupported args\n";
// IsSupportedArgument() is a boolean inside ck_tile and gives no reason, so
// enumerate the constraints a caller is realistically violating. Observed on
// gfx1250 with the default config: K must be a multiple of 16 (this holds even
// with pad_k=true -- padding covers the K-loop tail, not the global-load vector
// width), and N a multiple of the N-tile when pad_n is false.
std::cerr << "dispatcher_run_gemm: kernel reported unsupported args for M=" << M
<< " N=" << N << " K=" << K << " k_batch=" << k_batch
<< ". Known constraints for this kernel: K must be a multiple of 16 "
<< "(required even though pad_k=" << (SelectedKernel::kPadK ? "true" : "false")
<< "); N must be a multiple of " << SelectedKernel::TileN
<< " when pad_n is false. No output was written.\n";
cleanup();
return -2;
}
Expand All @@ -449,6 +529,23 @@ int dispatcher_run_gemm(const void* A,
*/
const char* dispatcher_get_kernel_name() { return KERNEL_NAME; }

/**
* Return the N-tile of the force-included kernel.
*
* The shape checks in dispatcher_run_gemm derive their bound from SelectedKernel::TileN
* so they survive a tile change. Exporting it lets the Python runner report the same
* number instead of hardcoding the value of today's default config.
*/
int dispatcher_get_tile_n() { return static_cast<int>(SelectedKernel::TileN); }

/**
* Return 1 when the force-included kernel was generated with pad_n=true.
*
* When padding is on the N % TileN constraint does not apply, so the Python
* runner needs this to phrase its diagnostics correctly.
*/
int dispatcher_get_pad_n() { return SelectedKernel::kPadN ? 1 : 0; }

// This bridge is one-.so-per-kernel by construction: the build force-includes exactly
// one generated header via `hipcc -include <kernel.hpp>`, giving one SelectedKernel.
// Scaling to N kernels means N .so files (the pattern bquant/aquant/abquant follow),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static std::atomic<int> g_ref_count{0};
// Architectures this bridge is known to work on. These fp8/bf8 CompV3 kernels need
// native FP8, so gfx90a is deliberately absent -- it compiles but produces NaN.
// Enabling a new target is a one-line addition here plus a CMake arch entry.
static constexpr const char* kSupportedArchs[] = {"gfx942", "gfx950"};
static constexpr const char* kSupportedArchs[] = {"gfx942", "gfx950", "gfx1250"};
Comment thread
ozturkosu marked this conversation as resolved.
Resolved

// True if `arch` starts with any entry of kSupportedArchs. Prefix-matching, because
// hipDeviceProp_t::gcnArchName carries feature suffixes (e.g. "gfx942:sramecc+:xnack-").
Expand Down Expand Up @@ -165,7 +165,19 @@ int dispatcher_init() { return dispatcher_initialize(); }
* k_batch - split-K factor (1 = no split)
* time_ms - output: kernel execution time in ms (may be NULL)
*
* Returns 0 on success, negative on error.
* Shape constraints (validated on gfx1250 with the default config; violations are
* rejected with an explanatory message and no output is written):
* K % 16 == 0 - required even when the kernel was generated with pad_k=true.
* pad_k covers the K-loop tail, not the global-load vector width.
* N % TileN == 0 - required whenever the kernel was generated with pad_n=false.
* TileN is 64 in the default config.
* There is no M constraint: TensorQuant applies scalar A/B scales rather than a
* per-row scale vector, and is correct at every M tested on gfx1250.
*
* Returns 0 on success, negative on error:
* -1 argument rejected by this bridge (including the constraints above)
* -2 argument rejected by the kernel's own IsSupportedArgument()
* -3 kernel launch threw
*/
int dispatcher_run_gemm(const void* A,
const void* B,
Expand Down Expand Up @@ -220,6 +232,17 @@ int dispatcher_run_gemm(const void* A,
return -1;
}

// N must be a whole number of N-tiles unless the kernel pads N. Derived from the
// kernel's own constants rather than hardcoded, so it stays correct if the tile or
// the padding trait changes. Without this the caller only sees a bare -2.
if(!SelectedKernel::kPadN && (N % SelectedKernel::TileN) != 0)
{
std::cerr << "dispatcher_run_gemm: N must be a multiple of " << SelectedKernel::TileN
<< " for this kernel (it was generated with pad_n=false, so N has to be a "
<< "whole number of N-tiles); got N=" << N << "\n";
return -1;
}

// Only packed (contiguous) layouts are supported.
//
// B layout (rcr = row-major A, column-major B, row-major C):
Expand Down Expand Up @@ -416,7 +439,17 @@ int dispatcher_run_gemm(const void* A,

if(exec_time < 0.0f)
{
std::cerr << "dispatcher_run_gemm: kernel reported unsupported args\n";
// IsSupportedArgument() is a boolean inside ck_tile and gives no reason, so
// enumerate the constraints a caller is realistically violating. Observed on
// gfx1250 with the default config: K must be a multiple of 16 (this holds even
// with pad_k=true -- padding covers the K-loop tail, not the global-load vector
// width), and N a multiple of the N-tile when pad_n is false.
std::cerr << "dispatcher_run_gemm: kernel reported unsupported args for M=" << M
<< " N=" << N << " K=" << K << " k_batch=" << k_batch
<< ". Known constraints for this kernel: K must be a multiple of 16 "
<< "(required even though pad_k=" << (SelectedKernel::kPadK ? "true" : "false")
<< "); N must be a multiple of " << SelectedKernel::TileN
<< " when pad_n is false. No output was written.\n";
cleanup();
return -2;
}
Expand All @@ -436,6 +469,23 @@ int dispatcher_run_gemm(const void* A,
*/
const char* dispatcher_get_kernel_name() { return KERNEL_NAME; }

/**
* Return the N-tile of the force-included kernel.
*
* The shape checks in dispatcher_run_gemm derive their bound from SelectedKernel::TileN
* so they survive a tile change. Exporting it lets the Python runner report the same
* number instead of hardcoding the value of today's default config.
*/
int dispatcher_get_tile_n() { return static_cast<int>(SelectedKernel::TileN); }

/**
* Return 1 when the force-included kernel was generated with pad_n=true.
*
* When padding is on the N % TileN constraint does not apply, so the Python
* runner needs this to phrase its diagnostics correctly.
*/
int dispatcher_get_pad_n() { return SelectedKernel::kPadN ? 1 : 0; }

// This bridge is one-.so-per-kernel by construction: the build force-includes exactly
// one generated header via `hipcc -include <kernel.hpp>`, giving one SelectedKernel.
// Scaling to N kernels means N .so files (the pattern bquant/aquant/abquant follow),
Expand Down
49 changes: 49 additions & 0 deletions projects/composablekernel/dispatcher/codegen/codegen_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,26 @@ def make_gemm_rowcolquant_kernel_name(
)


# ============================================================================
# Arch string normalization
# ============================================================================


def normalize_gfx_arch(arch: str) -> str:
"""Strip feature suffixes from a gfx target string.

``rocm_agent_enumerator`` and ``hipDeviceProp_t::gcnArchName`` may report the
target with trailing feature flags, e.g. ``"gfx942:sramecc+:xnack-"`` or
``"gfx1250:xnack-"``. Every arch comparison in the codegen/runtime path (and
the ``--offload-arch`` we hand to hipcc) wants the bare target, so normalize
once at the boundary instead of scattering substring tests that happen to
tolerate the suffix.

This is the single source of truth for that rule; do not re-implement it.
"""
return arch.split(":", 1)[0]


# ============================================================================
# Arch-derived warp tile K
# ============================================================================
Expand Down Expand Up @@ -980,6 +1000,35 @@ def make_abquant_kernel_name(
"warp_tile_m": 32, "warp_tile_n": 32, "warp_tile_k": 16,
}

# gfx1250 (RDNA-style WMMA, MI400) cannot use the tile above: it is sized
# for the gfx9 MFMA 32x32x16 fragment, which does not exist on WMMA hardware, so the
# kernel compiles but produces all-zero output. The 8-bit WMMA fragment is 16x16x128,
# and the FlatMM 8-bit tile below is the shape validated against it.
ROWCOL_TENSOR_QUANT_DEFAULT_TILE_GFX1250 = {
"tile_m": 16, "tile_n": 64, "tile_k": 256,
"warp_m": 1, "warp_n": 4, "warp_k": 1,
"warp_tile_m": 16, "warp_tile_n": 16, "warp_tile_k": 128,
}


def rowcol_tensor_quant_default_tile(gfx_arch: str = "") -> dict:
"""Return the default RowColQuant/TensorQuant tile for `gfx_arch`.

Kept here, next to the tile dicts themselves, so the rowcolquant and tensorquant
runtime helpers select the arch-specific tile through one shared code path rather
than each carrying its own copy of the gfx1250 shape.

The gfx1250 test is EXACT, not a ``gfx12`` family test. gfx1200/gfx1201 are
also WMMA parts, but their 8-bit warp fragment is 16x16x16, not the 16x16x64 /
16x16x128 of gfx1250, so handing them the gfx1250 tile would compile cleanly
and return garbage. Contrast the OCP-FP8 define in the rowcolquant/tensorquant
runtime helpers, which *is* correctly family-wide.
"""
if normalize_gfx_arch(gfx_arch) == "gfx1250":
return dict(ROWCOL_TENSOR_QUANT_DEFAULT_TILE_GFX1250)
return dict(ROWCOL_TENSOR_QUANT_DEFAULT_TILE)


# Default traits, shared for the same reason as the tile above. pad_m is enabled
# because these kernels are used with M values that are not tile-aligned.
ROWCOL_TENSOR_QUANT_DEFAULT_TRAITS = {
Expand Down
Loading
Loading