IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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

naive_block_scaled_matmul_kernel

def naive_block_scaled_matmul_kernel[c_type: DType, a_type: DType, b_type: DType, a_scales_type: DType, b_scales_type: DType, accum_type: DType, a_layout: Layout, b_layout: Layout, c_layout: Layout, a_scale_layout: Layout, b_scale_layout: Layout, scaling_kind: UMMAKind, SF_VECTOR_SIZE: Int, transpose_b: Bool = True, elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None] = None](c: LayoutTensor[c_type, c_layout, MutAnyOrigin], a: LayoutTensor[a_type, a_layout, MutAnyOrigin], b: LayoutTensor[b_type, b_layout, MutAnyOrigin], a_scales: LayoutTensor[a_scales_type, a_scale_layout, MutAnyOrigin], b_scales: LayoutTensor[b_scales_type, b_scale_layout, MutAnyOrigin], alpha: Float32)

Naive GPU kernel that emulates a block-scaled matmul using TCGEN scale factors.

Both A and B must be in K-major format with 5D TCGEN scale-factor layouts. Each thread accumulates one output element by iterating over K, applying per-block scale factors, and optionally invoking an elementwise epilogue lambda.

Parameters:

  • ​c_type (DType): Element type of the output matrix c.
  • ​a_type (DType): Element type of the LHS input matrix a.
  • ​b_type (DType): Element type of the RHS input matrix b.
  • ​a_scales_type (DType): Element type of the a_scales block scale-factor tensor.
  • ​b_scales_type (DType): Element type of the b_scales block scale-factor tensor.
  • ​accum_type (DType): Element type used for the dot-product accumulator.
  • ​a_layout (Layout): Memory layout of the LHS input matrix a.
  • ​b_layout (Layout): Memory layout of the RHS input matrix b.
  • ​c_layout (Layout): Memory layout of the output matrix c.
  • ​a_scale_layout (Layout): Memory layout of the a_scales block scale-factor tensor.
  • ​b_scale_layout (Layout): Memory layout of the b_scales block scale-factor tensor.
  • ​scaling_kind (UMMAKind): UMMAKind variant selecting the block-scaled MMA instruction.
  • ​SF_VECTOR_SIZE (Int): Number of elements covered by each block scale factor.
  • ​transpose_b (Bool): Whether b is stored transposed (defaults to True).
  • ​elementwise_lambda_fn (Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]): Optional epilogue lambda applied to the matmul result (defaults to None).