For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
grouped_matmul_sm100_blockwise_scaled_fp8
def grouped_matmul_sm100_blockwise_scaled_fp8[c_type: DType, a_type: DType, b_type: DType, a_scales_type: DType, b_scales_type: DType, a_offsets_type: DType, expert_ids_type: DType, transpose_b: Bool, //, *, config: MatmulConfig[a_type, b_type, c_type, transpose_b], elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None] = None](c: TileTensor[c_type, Storage=c.Storage, linear_idx_type=c.linear_idx_type], a: TileTensor[a_type, Storage=a.Storage, linear_idx_type=a.linear_idx_type], b: TileTensor[b_type, Storage=b.Storage, linear_idx_type=b.linear_idx_type], a_scales: TileTensor[a_scales_type, Storage=a_scales.Storage, linear_idx_type=a_scales.linear_idx_type], b_scales: TileTensor[b_scales_type, Storage=b_scales.Storage, linear_idx_type=b_scales.linear_idx_type], a_offsets: TileTensor[a_offsets_type, Storage=a_offsets.Storage, linear_idx_type=a_offsets.linear_idx_type], expert_ids: TileTensor[expert_ids_type, Storage=expert_ids.Storage, linear_idx_type=expert_ids.linear_idx_type], max_num_tokens_per_expert: Int, num_active_experts: Int, ctx: DeviceContext)
Launches the basic (non-persistent) SM100 blockwise-scaled FP8 grouped GEMM kernel.
Converts the input TileTensors to LayoutTensors, builds TMA
descriptors for A, B, and the C output, and enqueues
matmul_sm100_grouped_blockwise_scaled_fp8_1d2d_kernel with a grid of
(N/BN, max_tokens/BM, num_active_experts) blocks.
Parameters:
- βc_type (
DType): Element type of the outputCtensor (inferred). - βa_type (
DType): Element type of the inputAtensor (inferred). Must befloat8_e4m3fn. - βb_type (
DType): Element type of the inputBtensor (inferred). Must befloat8_e4m3fn. - βa_scales_type (
DType): Element type of thea_scalestensor (inferred). - βb_scales_type (
DType): Element type of theb_scalestensor (inferred). - βa_offsets_type (
DType): Element type of thea_offsetstensor (inferred). - βexpert_ids_type (
DType): Element type of theexpert_idstensor (inferred). - βtranspose_b (
Bool): WhetherBis stored transposed (inferred). Must beTrue. - βconfig (
MatmulConfig[a_type, b_type, c_type, transpose_b]): Matmul configuration specifying block tile shape, MMA shape, and TMA swizzle modes. - βelementwise_lambda_fn (
Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]): Optional epilogue function applied to each output element before storing (defaults toNone).
Args:
- βc (
TileTensor[c_type, Storage=c.Storage, linear_idx_type=c.linear_idx_type]): Output tensor of shape[total_tokens, N]holding the grouped matmul results. - βa (
TileTensor[a_type, Storage=a.Storage, linear_idx_type=a.linear_idx_type]): Input activation tensor of shape[total_tokens, K]in FP8. - βb (
TileTensor[b_type, Storage=b.Storage, linear_idx_type=b.linear_idx_type]): Input weight tensor of shape[num_experts, N, K]in FP8. - βa_scales (
TileTensor[a_scales_type, Storage=a_scales.Storage, linear_idx_type=a_scales.linear_idx_type]): Per-block scales forAof shape[K // BK, total_tokens]whereBKis the scaling block size. - βb_scales (
TileTensor[b_scales_type, Storage=b_scales.Storage, linear_idx_type=b_scales.linear_idx_type]): Per-block scales forBof shape[num_experts, N // BN, K // BK]whereBNandBKare the scaling block sizes. - βa_offsets (
TileTensor[a_offsets_type, Storage=a_offsets.Storage, linear_idx_type=a_offsets.linear_idx_type]): Cumulative row offsets per expert, lengthnum_active_experts + 1. Entryi + 1minus entryigives the row count for experti. - βexpert_ids (
TileTensor[expert_ids_type, Storage=expert_ids.Storage, linear_idx_type=expert_ids.linear_idx_type]): Expert index for each active expert slot, mapping the grid Z index to the corresponding row offset inB. - βmax_num_tokens_per_expert (
Int): Maximum number of tokens assigned to any single expert, used to size the grid M dimension. - βnum_active_experts (
Int): Number of active experts in this grouped matmul, used to size the grid Z dimension. - βctx (
DeviceContext): Device context used to enqueue the kernel.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!