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 matrixc. - βa_type (
DType): Element type of the LHS input matrixa. - βb_type (
DType): Element type of the RHS input matrixb. - βa_scales_type (
DType): Element type of thea_scalesblock scale-factor tensor. - βb_scales_type (
DType): Element type of theb_scalesblock scale-factor tensor. - βaccum_type (
DType): Element type used for the dot-product accumulator. - βa_layout (
Layout): Memory layout of the LHS input matrixa. - βb_layout (
Layout): Memory layout of the RHS input matrixb. - βc_layout (
Layout): Memory layout of the output matrixc. - βa_scale_layout (
Layout): Memory layout of thea_scalesblock scale-factor tensor. - βb_scale_layout (
Layout): Memory layout of theb_scalesblock scale-factor tensor. - βscaling_kind (
UMMAKind):UMMAKindvariant selecting the block-scaled MMA instruction. - βSF_VECTOR_SIZE (
Int): Number of elements covered by each block scale factor. - βtranspose_b (
Bool): Whetherbis stored transposed (defaults toTrue). - β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 toNone).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!