Commit 5305cdd
[rocm-libraries] ROCm/rocm-libraries#9166 (commit 61284f3)
feat(ck-tile): add BQuantGrouped GEMM dispatcher with ctypes
bridge (#9166)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
JIRA ID : AICK-1289
## Motivation
The CK tile dispatcher lacked a Python-callable path for BQuantGrouped
GEMM,
which is the primary quantized GEMM kernel used for weight-only
quantization
inference on gfx950 (MI350X). This PR adds a complete three-layer bridge
(codegen → compile → dispatch) so that Python callers can drive BQuant
GEMM
through the dispatcher without writing any C++ directly.
The implementation is based on the reference kernels in
`example/ck_tile/38_block_scale_gemm/gemm_bquant_quantgrouped_*` and
covers
all variants used in production: fp8/bf8 decode and prefill tiles,
fp8i4/bf8i4
weight-only quantization, preshuffle variants (preshuffle_b,
preshuffle_bquant,
both combined), and MX microscale (bf16+bf16, bf16+bf8, bf16+fp4 with
e8m0
block scale).
## Technical Details
**New files added:**
- `dispatcher/bindings/ctypes/grouped_gemm_bquant_ctypes_lib.cpp` — C
API
(`dispatcher_initialize`, `dispatcher_run_bquant_gemm`) for Python
ctypes
integration. Manages host↔device memory transfers internally. Compiled
per-kernel via `hipcc -include <kernel.hpp>` force-include pattern.
- `dispatcher/codegen/unified_grouped_gemm_bquant_codegen.py` — kernel
header
generator. Produces one `.hpp` per config, selecting `PermuteNEpilogue`
vs
`CShuffleEpilogue` based on `TiledMMAPermuteN` (mirrors
`run_gemm_quant_example.inc`).
- `dispatcher/python/grouped_gemm_bquant_utils.py` — Python bridge:
`BQuantKernelConfig` describes a kernel, `BQuantDispatcherLib` wraps the
ctypes API, `BQuantGpuGemmRunner` accepts NumPy arrays and returns
results.
Build pipeline runs codegen + hipcc in parallel via
`ThreadPoolExecutor`.
- `dispatcher/examples/gemm/python/13_grouped_gemm_bquant.py` —
end-to-end
example demonstrating codegen → hipcc compile → GPU run → CPU reference
verification using real fp8 bit patterns via `ml_dtypes`.
- `dispatcher/tests/test_grouped_gemm_bquant_utils.py` — 58 CPU-only
unit
tests covering kernel name generation, config serialization round-trips,
and problem dimension helpers for all variant families.
**Modified files:**
-
`include/ck_tile/ops/gemm_quant/pipeline/gemm_abquant_pipeline_ag_bg_cr_policy.hpp`
—
adds `wg_attr_num_access` selection logic to `WarpGemmDispatcher`
instantiation
in `GemmABQuantPipelineAgBgCrDefaultPolicy`, required for ABQuant
pipeline
correctness on prefill tiles.
**Shared infrastructure:**
- `dispatcher/codegen/codegen_common.py` — adds
`make_bquant_kernel_name()`
so both the codegen (`BQuantKernelSpec.name`) and the utils
(`BQuantKernelConfig.name`) produce byte-exact identical kernel names
from
a single implementation.
## Test Plan
- Run the 58 CPU-only unit tests (no GPU required):
python3 -m pytest dispatcher/tests/test_grouped_gemm_bquant_utils.py -v
- Run the end-to-end example on gfx950 (MI350X):
python3 dispatcher/examples/gemm/python/13_grouped_gemm_bquant.py
--dtype fp8
python3 dispatcher/examples/gemm/python/13_grouped_gemm_bquant.py
--dtype bf8
- Build and run `test_gemm_quant_abquant_preshuffle_preshuffleQuant` on
gfx950
and gfx120 to verify the ABQuant pipeline policy change.
## Test Result
- All 58 CPU-only unit tests pass.
- End-to-end GPU tests pending on gfx950 hardware.
- `test_gemm_quant_abquant_preshuffle_preshuffleQuant` build and run
pending.
## Submission Checklist
- [ ] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.1 parent e6d9916 commit 5305cdd
13 files changed
Lines changed: 4399 additions & 0 deletions
File tree
- dispatcher
- bindings/ctypes
- codegen
- examples/gemm/python
- python
- tests
- tile_engine/ops/gemm/block_scale_gemm/gemm_bquant
- configs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
157 | 203 | | |
158 | 204 | | |
159 | 205 | | |
| |||
0 commit comments