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
def naive_block_scaled_matmul[c_type: DType, a_type: DType, b_type: DType, a_scales_type: DType, b_scales_type: DType, //, *, scaling_kind: UMMAKind, SF_VECTOR_SIZE: Int, accum_type: DType = DType.float32, 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, BLOCK_DIM: Int = Int(16)](c: LayoutTensor[c_type, element_layout=c.element_layout, layout_int_type=c.layout_int_type, linear_idx_type=c.linear_idx_type, masked=c.masked, alignment=c.alignment], a: LayoutTensor[a_type, element_layout=a.element_layout, layout_int_type=a.layout_int_type, linear_idx_type=a.linear_idx_type, masked=a.masked, alignment=a.alignment], b: LayoutTensor[b_type, element_layout=b.element_layout, layout_int_type=b.layout_int_type, linear_idx_type=b.linear_idx_type, masked=b.masked, alignment=b.alignment], a_scales: LayoutTensor[a_scales_type, element_layout=a_scales.element_layout, layout_int_type=a_scales.layout_int_type, linear_idx_type=a_scales.linear_idx_type, masked=a_scales.masked, alignment=a_scales.alignment], b_scales: LayoutTensor[b_scales_type, element_layout=b_scales.element_layout, layout_int_type=b_scales.layout_int_type, linear_idx_type=b_scales.linear_idx_type, masked=b_scales.masked, alignment=b_scales.alignment], ctx: DeviceContext, alpha: Float32 = 1)
Reference block-scaled matmul that emulates TCGEN scale-factor accumulation on SM100 hardware.
Validates input and scale dimensions, then enqueues the
naive_block_scaled_matmul_kernel with a 16x16 thread block grid.
Parameters:
- βc_type (
DType): Element type of the output matrix (inferred). - βa_type (
DType): Element type of the LHS input matrix (inferred). - βb_type (
DType): Element type of the RHS input matrix (inferred). - βa_scales_type (
DType): Element type of thea_scalesblock scale-factor tensor (inferred). - βb_scales_type (
DType): Element type of theb_scalesblock scale-factor tensor (inferred). - βscaling_kind (
UMMAKind):UMMAKindvariant selecting the block-scaled MMA instruction. - βSF_VECTOR_SIZE (
Int): Number of elements covered by each block scale factor. - βaccum_type (
DType): Accumulator element type (defaults toDType.float32). - β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). - βBLOCK_DIM (
Int): Thread block tile dimension in rows and columns (defaults to 16).
def naive_block_scaled_matmul[c_type: DType, a_type: DType, b_type: DType, a_scales_type: DType, b_scales_type: DType, //, *, scaling_kind: UMMAKind, SF_VECTOR_SIZE: Int, accum_type: DType = DType.float32, 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, BLOCK_DIM: Int = Int(16)](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], ctx: DeviceContext, alpha: Float32 = 1)
TileTensor overload for the naive reference block-scaled matmul.
The reference implementation remains LayoutTensor-based outside SM100. Keep that compatibility shim here so the SM100 testbed can stay TileTensor-native.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!