huangpustar/metainfer/int8-w8a8-gemm-foundations
Claude Code and agent skill by huangpustar/metainfer
- community
Checking that the SKILL.md file is still in the repository.
Shared foundations for INT8 W8A8 GEMM on Hygon K500SM_AI/gfx928: operator and layout contracts, DUMMA/epilogue rules, Graph-safe PyTorch bindings, SGLang integration, fair benchmarking, and correctness gates. Always load this together with the phase skill: int8-w8a8-gemm-decode (M<=32) or int8-w8a8-gemm-prefill (M>32).
Install
npx vskill@latest install huangpustar/metainfer/int8-w8a8-gemm-foundationsSKILL.md
INT8 W8A8 GEMM — Shared Foundations (gfx928 / SGLang TP4)
This skill records the implementation and evidence validated on worker29 with DTK 26.04. It supersedes generic rules when the exact TP4 shapes below match. Do not transfer measured latency or routing to another architecture, TP size, DTK version, or weight layout without rerunning the benchmark.
0. Phase routing (read first)
The INT8 W8A8 GEMM skill family is split by execution phase because the two regimes have non-transferable recipes, different bottlenecks, and different acceptance protocols:
| M | Skill to load | Kernel family | Bottleneck | |
|---|---|---|---|---|
| M <= 32 (decode) | int8-w8a8-gemm-decode | split-K partial + fused combine, small tiles | launch/latency-bound, µs-scale | |
| M > 32 (prefill) | int8-w8a8-gemm-prefill | 2D M-tile, staged LDS, no split-K | LDS/compute-bound, ms-scale |
Load this foundations skill together with the phase skill. Recipes do NOT transfer across the boundary: the M=16 decode kernel's direct-B-from-global win does not transfer to prefill, and prefill's "no split-K" rule does not apply to decode. M in (32, 128] is a measured-boundary gap (validated decode covers M<=16, validated prefill starts at M=3072): route by measurement and keep both a staged prefill arm and a decode-compatible arm until measured.
1. Operator Contract
The timed GEMM includes integer accumulation, both scales, bf16 conversion, and output writeback. It excludes activation quantization, weight preprocessing, tensor allocation, output clearing, JIT compilation, and Graph capture.
Target TP4 shapes:
| Layer | K | N | |
|---|---|---|---|
| wqkv_a | 4096 | 1536 | |
| wq_b / indexer.wq_b | 1024 | 8192 | |
| wo_b | 2048 | 4096 | |
| shared gate_up_proj | 4096 | 1024 | |
| shared down_proj | 512 | 4096 |
All target K values are divisible by 128 and all N values by 64.
The M=4096 chunked-prefill family adds four fixed-M shapes (see int8-w8a8-gemm-prefill): hy3_tp4_qkv_proj_m4096 (M,N,K = 4096,2560,4096), hy3_tp4_o_proj_m4096 (4096,4096,2048), hy3_tp4_shared_gate_up_proj_m4096 (4096,768,4096), and hy3_tp4_shared_down_proj_m4096 (4096,4096,384).
2. Shape and Layout Contract
SGLang data flow:
Checkpoint and runtime weight flow:
Keep both layouts:
- Preserve
layer.weightas the original transposed view for safe fallback. - Register a non-persistent contiguous HIP buffer once after checkpoint load.
- Never replace
layer.weight.datawith the contiguous copy. Doing so changes
the Triton fallback layout and was observed to regress TTFT.
- Weight preprocessing is allowed by the task and must remain outside timed
execution and Graph capture.
For the M=4096 lineage the packed weight layout is shape-specific and opaque (o_proj: [N/64, K, 64] int8 panels; gate_up: [K,N]→[N,K] transpose; down_proj: n-major packed[n][k]; qkv: n-major packed[n][k] for (k,n)==(4096,2560)); packing is one-time, out-of-timed-region, out-of-Graph, keeps the same byte count and buffer (graph-stable addresses unchanged), and correctness is always checked against the raw logical [K,N] weight.
3. DUMMA and Epilogue Rules
gfx928 uses wavefront=64. Block size must be a multiple of 64.
For INT8, the supported primitive is:
API rules:
du_fill_fragment(acc, 0)before the K loop.- Load matrix A/B with
du_load_matrix_sync. - Accumulate with
du_mma_sync. du_store_matrix_syncaccepts an accumulator fragment, not a raw array.- If materializing C in LDS, pass a scalar pointer such as
&smem_c[0][0] and synchronize before other lanes read it.
- A direct epilogue may use the verified gfx928 accumulator ownership:
row=lane&15, col_mod4=lane>>4, frag.x[i] maps to columns col_mod4+4*i. Re-derive this mapping when changing architecture or fragment type.
Prefer direct fragment epilogues when they are verified: they remove the accumulator LDS round trip and one barrier. For the final non-split wo_b kernel, the resource report was 40 VGPR, 32 SGPR, 6144 bytes LDS, and zero scratch.
3.1 ISA use for memory-compute overlap
Use ISA as an acceptance test after HIP/DUMMA architecture choices have been measured, not as a substitute for tile and stage exploration:
- Save the exact gfx928 code object used by the timing run.
- Locate the exact template symbol; do not disassemble a stale sibling.
- Check load/MMAC/wait/LDS-store order in the steady-state stage.
- Read VGPR, SGPR, LDS, scratch, and spill fields from code-object metadata.
- Reject a candidate if the compiler removes a required load, moves the wait
before MMAC, spills prefetched values, or changes cache semantics silently.
- Use raw inline assembly only for a minimal operation whose constraint and
hazard behavior is already verified on the current DTK/gfx928 toolchain.
- Re-run exact correctness, Graph replay with changed contents, median, and
P90 after every ISA-level change.
For large-M prefill, prefer HIP/DUMMA for loads and MMAC. The accepted raw asm is limited to s_waitcnt vmcnt(0) before alternate-LDS writes and the validated LDS-ready sequence s_waitcnt lgkmcnt(0); s_barrier. Do not copy raw global-load/store or raw MMAC templates without a lane-layout microtest.
4. Graph-Safe PyTorch Interface
Preferred API:
Requirements:
- Build/load the extension before capture.
- Allocate output and workspace before capture for the low-level interface.
- Launch on
at::cuda::getCurrentCUDAStream(device). - Do not create streams, synchronize, allocate device memory, autotune,
preprocess weights, inspect GPU values on the CPU, or change tensor addresses inside capture.
- The launcher should contain only shape validation, static dispatch, and
asynchronous kernel launches.
- A Graph replay may update tensor contents but not captured addresses or
shapes.
Python exposure:
5. SGLang Integration
Integration flow:
Files on worker29:
Enable before server start:
Unsupported conditions must return None and retain the original SGLang path. Current custom path excludes non-TP4 target K/N shapes, bias, non-bf16 output, wrong dtype/rank/scale shape, non-contiguous HIP buffers, and weights that were not prepared.
6. Fair Benchmarking
Keep three scopes separate:
- Existing Python operator: may include
torch.zeros, allocation, and extra
fill kernels.
- Fair
gemm_out: preallocated output; times all kernels needed to produce
final bf16 output.
- PMC kernel sample: diagnostic only; profiler timing is not the final score.
Formal fair baseline:
Use unprofiled GPU Events for acceptance. Report eager and Graph separately:
Never compare HIP Graph against Triton eager. Use identical warmups, samples, launches/sample, inputs, output ownership, and cache policy.
Recommended stable hot-cache protocol:
Use PMC after timing to explain VGPR/LDS/scratch, bank conflicts, MFMA use, and cache behavior. Do not treat lower VGPR or bank conflicts alone as a performance win. lds_wait ≈ lds_instructions alone is not a bottleneck signal (true in accepted kernels too). Profiled durations are perturbed — never use PMC time as the score. Derived TOPS / bandwidth numbers are 2*M*N*K / median style logical rates, not measured HBM traffic; use PMC vmem_read for real global reads. Phase-specific acceptance protocols live in the decode / prefill skills.
7. Correctness and Acceptance (shared)
Before accepting a variant:
- Compare against the reference for all five TP4 shapes.
- Test extreme int8 values and random values.
- Test M=1/2/4/8/16, M tails such as 65, and actual prefill M=3072.
- Require exact bf16 equality when comparing implementations with identical
int32 accumulation order; otherwise define and justify tolerance.
- Capture Graph, update static input contents, replay, and compare again.
- Verify current stream behavior and absence of hidden synchronization.
- Run fair unprofiled median/P90.
- Then use hipprof/PMC to explain the result.
- Run SGLang fallback tests and a representative end-to-end workload.
After a killed/aborted round, restore the accepted source to its recorded digest before the next experiment. hipLaunchKernelGGL + HIP_KERNEL_NAME(templated<...>) is valid and used by every accepted kernel; compile failures of a proposal are candidate/infra failures, never evidence that templates/DUMMA/INT8 are unsupported.
Relevant tests:
8. Shared Guardrails (rejected evidence)
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingmetainfer/tasks/dcu_kernel_auto_opt/skills/int8-w8a8-gemm-foundations/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/huangpustar/metainfer/int8-w8a8-gemm-foundations)