Archived
libr4d: GLM-5.3's kernels -- mHC, KDA, the DSA indexer, MLA, f32-scaled FP8, MXFP4 experts
The device rows for GLM-5.3-Flash's ops, at its geometry and at TP4 and TP8 slices: - mhc_pre / mhc_post / mhc_contract, and mhc_pre_partial / mhc_pre_finish, which run mhc_pre's own projection and finishing kernels with its chunk-sum order, so the pair is byte-identical to mhc_pre at n 4096, hc 4, chunk 2048. - kda_update_k128_v128_bf16, one, two or four value rows a wave, both state forms. - dsa_pool_fp8, dsa_query_fp8 and dsa_score_fp8 (fp8 WMMA, 32 heads of 128). - mla_attn: a matrix row whose WMMA tile holds a query's heads, or pairs eight heads of two neighbouring queries over the union of their page tables, above the wave row; mla_project with up to eight rows a thread or wave. - gemm_nt_f32 and router_sigmoid_topk in tiled and one-wave-a-row forms; gemm_fp8a8_f32scale and moe_gemm_fp8a8_f32scale read f32 block scales in place; moe_gemm_mxfp4a8 decodes e2m1 into exact E4M3 bytes for fp8 WMMA, with an expert-major decode form and a wide prefill form. - swiglu_clamped, and the device-only fusions of GLM's MoE block: swiglu_clamped_quant_fp8, router_sigmoid_topk_scatter, and moe_scatter_inv / moe_gather_inv, which pass the gather's slot table from the sort instead of rebuilding it. moe_gather takes f32 routing weights in its column-per-thread kernel. The sort and the gather kernels move from r4d_moe.hip into r4d_moe_sort.h and r4d_moe_gather.h, so the fused router and gather instantiate the same code. Every form that replaces another gives its bytes: tests/r4d_emu runs the kernels on the host (test_f32, test_fp8f32, test_kda, test_mhc, test_mla, test_moefuse, test_moemx), r4d_selftest compares them on a card against libref and against each other, and plugin_test pins the mla_attn band. docs/OPS.md states what libr4d serves. Co-Authored-By: John McDonough <18016200+JohnCMcDonough@users.noreply.github.com>
This commit is contained in:
1 parent
da77f86332
commit
78c58841bf
31 files changed
+12371
-302
No files matched your search
@@ -296,6 +296,15 @@ int r4d_rad_dflash_select (const RadArgs*, RadStream);
|
||||
|
||||
/* -- the gated residual (r4d_hc_bf16.hip) -- */
|
||||
int r4d_rad_hc_enter (const RadArgs*, RadStream);
|
||||
int r4d_rad_mhc_pre(const RadArgs*, RadStream);
|
||||
int r4d_rad_mhc_pre_partial(const RadArgs*, RadStream);
|
||||
int r4d_rad_mhc_pre_finish(const RadArgs*, RadStream);
|
||||
int r4d_rad_kda_update(const RadArgs*, RadStream);
|
||||
int r4d_rad_moe_mxfp4(const RadArgs*, RadStream);
|
||||
int r4d_rad_layout_moe_mxfp4(const RadParam*, int, int, const RadEncoding*, const int*,
|
||||
const RadTensor*, int, RadLayout*);
|
||||
int r4d_rad_mhc_post(const RadArgs*, RadStream);
|
||||
int r4d_rad_mhc_contract(const RadArgs*, RadStream);
|
||||
int r4d_rad_mtp_enter (const RadArgs*, RadStream);
|
||||
int64_t r4d_rad_mtp_enter_scratch(const RadArgs*);
|
||||
int r4d_rad_hc_read (const RadArgs*, RadStream);
|
||||
@@ -604,6 +613,35 @@ int r4d_rad_fill (const RadArgs*, RadStream);
|
||||
int r4d_rad_logit_softcap (const RadArgs*, RadStream);
|
||||
int r4d_rad_scale (const RadArgs*, RadStream);
|
||||
int r4d_rad_silu_mul (const RadArgs*, RadStream);
|
||||
int r4d_rad_swiglu_clamped(const RadArgs*, RadStream);
|
||||
int r4d_rad_swiglu_clamped_quant_fp8(const RadArgs*, RadStream);
|
||||
int r4d_rad_dsa_pool(const RadArgs*, RadStream);
|
||||
int r4d_shape_dsa_pool(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_dsa_query(const RadArgs*, RadStream);
|
||||
int r4d_rad_fp8_f32scale(const RadArgs*, RadStream);
|
||||
int r4d_rad_moe_fp8_f32scale(const RadArgs*, RadStream);
|
||||
int r4d_layout_fp8_f32scale(const RadParam*, int, int, const RadEncoding*, const int*,
|
||||
const RadTensor*, int, RadLayout*);
|
||||
int r4d_shape_dsa_query(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_gemm_nt_f32(const RadArgs*, RadStream);
|
||||
int r4d_shape_gemm_nt_f32(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_mla_project(const RadArgs*, RadStream);
|
||||
int r4d_shape_mla_project(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_dsa_score(const RadArgs*, RadStream);
|
||||
int r4d_shape_dsa_score(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_mla_attn(const RadArgs*, RadStream);
|
||||
int64_t r4d_rad_mla_attn_scratch(const RadArgs*);
|
||||
int r4d_rad_mla_attn_matrix(const RadArgs*, RadStream);
|
||||
int64_t r4d_rad_mla_attn_matrix_scratch(const RadArgs*);
|
||||
int r4d_shape_mla_attn(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_router_sigmoid_topk(const RadArgs*, RadStream);
|
||||
int r4d_shape_router_sigmoid_topk(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_router_sigmoid_topk_scatter(const RadArgs*, RadStream);
|
||||
int r4d_rad_moe_scatter_inv(const RadArgs*, RadStream);
|
||||
int r4d_shape_moe_scatter_inv(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_moe_gather_inv(const RadArgs*, RadStream);
|
||||
int r4d_shape_moe_gather_inv(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_router_sigmoid_topk_scatter(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_gelu_mul (const RadArgs*, RadStream);
|
||||
int r4d_rad_rope (const RadArgs*, RadStream);
|
||||
/* -- the vision tower's ops (r4d_vit_bf16.hip) -- */
|
||||
@@ -656,6 +694,13 @@ int r4d_shape_scatter_rows_u8(const RadParam*, int, int operand, RadOpdDesc*);
|
||||
int r4d_shape_cast (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
int r4d_shape_rmsnorm (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
int r4d_shape_hc_enter (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
int r4d_shape_mhc_pre(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_mhc_pre_partial(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_mhc_pre_finish(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_kda_update(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_moe_mxfp4(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_mhc_post(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_mhc_contract(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_shape_mtp_enter (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
int r4d_shape_hc_read (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
int r4d_shape_hc_write (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
@@ -750,6 +795,8 @@ int r4d_shape_dflash_select (const RadParam*, int, int operand, RadOpdDesc*);
|
||||
* Pure host code, like r4d_rows.cpp, r4d_layout.cpp and r4d_shapes.cpp. */
|
||||
int r4d_fuse_rmsnorm_quant_fp8 (const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
int r4d_fuse_gated_quant_fp8 (const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
int r4d_fuse_swiglu_clamped_quant_fp8(const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
int r4d_fuse_router_sigmoid_topk_scatter(const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
int r4d_fuse_gate_quant_fp8 (const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
int r4d_fuse_gemm_nt_q_gated (const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
int r4d_fuse_gdn_conv_recurrent_update(const RadParam*, int, uint64_t, int, RadFuseStep*);
|
||||
|
||||
Reference in new issue
Block a user