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
matmul_kernel_naive
def matmul_kernel_naive[c_type: DType, a_type: DType, b_type: DType, c_layout_type: TensorLayout, a_layout_type: TensorLayout, b_layout_type: TensorLayout, BLOCK_DIM: Int, transpose_b: Bool = False, elementwise_lambda_fn: Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None] = None, s_type: DType = get_accum_type[c_type](), c_storage: TensorStorage = PointerStorage, a_storage: TensorStorage = PointerStorage, b_storage: TensorStorage = PointerStorage](c: TileTensor[c_type, c_layout_type, MutAnyOrigin, Storage=c_storage], a: TileTensor[a_type, a_layout_type, ImmutAnyOrigin, Storage=a_storage], b: TileTensor[b_type, b_layout_type, ImmutAnyOrigin, Storage=b_storage], m: Int, n: Int, k: Int)
Computes one output element of a matrix multiply per thread by iterating over the K dimension.
Each thread maps to a single (x, y) coordinate of c and accumulates the
dot product of the corresponding row of a and column of b (or row of
b when transpose_b is set). When elementwise_lambda_fn is supplied the
accumulated value is passed through it instead of being stored directly.
Parameters:
- βc_type (
DType): DType of the output tilecelements. - βa_type (
DType): DType of the input tileaelements. - βb_type (
DType): DType of the input tilebelements. - βc_layout_type (
TensorLayout): Tensor layout of the output tilec. - βa_layout_type (
TensorLayout): Tensor layout of the input tilea. - βb_layout_type (
TensorLayout): Tensor layout of the input tileb. - βBLOCK_DIM (
Int): Thread-block dimension used when launching the kernel. - βtranspose_b (
Bool): Whetherbis accessed transposed, so its rowyis read asb[y, i]instead ofb[i, y](defaults toFalse). - βelementwise_lambda_fn (
Optional[def[dtype: DType, width: SIMDLength, *, alignment: Int = Int(1)](IndexList[Int(2)], SIMD[dtype, width]) capturing thin -> None]): Optional epilogue applied to the accumulated value before it is stored toc(defaults toNone, which stores the raw accumulation). - βs_type (
DType): DType used for the inner accumulation (defaults to the accumulator type forc_type). - βc_storage (
TensorStorage): Storage type of the output tilec(defaults toPointerStorage[element_width=1]). - βa_storage (
TensorStorage): Storage type of the input tilea(defaults toPointerStorage[element_width=1]). - βb_storage (
TensorStorage): Storage type of the input tileb(defaults toPointerStorage[element_width=1]).
Args:
- βc (
TileTensor[c_type, c_layout_type, MutAnyOrigin, Storage=c_storage]): Output tile of shape(m, n). - βa (
TileTensor[a_type, a_layout_type, ImmutAnyOrigin, Storage=a_storage]): Input tile of shape(m, k). - βb (
TileTensor[b_type, b_layout_type, ImmutAnyOrigin, Storage=b_storage]): Input tile of shape(k, n), or(n, k)whentranspose_bis set. - βm (
Int): Number of rows ofaandc. - βn (
Int): Number of columns ofc. - βk (
Int): Contraction dimension shared byaandb.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!