For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
apple_batched_matmul
def apple_batched_matmul[rank: Int, *, transpose_b: Bool = False](c: TileTensor[Engine=c.Engine, address_space=c.address_space, linear_idx_type=c.linear_idx_type], a: TileTensor[Engine=a.Engine, address_space=a.address_space, linear_idx_type=a.linear_idx_type], b: TileTensor[Engine=b.Engine, address_space=b.address_space, linear_idx_type=b.linear_idx_type], c_shape_idx: IndexList[rank])
Performs a batched single-precision matmul via the Apple Accelerate library.
Iterates over all batch dimensions (all axes except the last two), calling
apple_matmul for each 2D slice. Requires at least rank-3 tensors and
all operands to be DType.float32.
Parameters:
- rank (
Int): The rank of the output tensor (must be >= 3). - transpose_b (
Bool): Whether to treat B as transposed.
Args:
- c (
TileTensor[Engine=c.Engine, address_space=c.address_space, linear_idx_type=c.linear_idx_type]): Output batched tensor tile. - a (
TileTensor[Engine=a.Engine, address_space=a.address_space, linear_idx_type=a.linear_idx_type]): Input A batched tensor tile. - b (
TileTensor[Engine=b.Engine, address_space=b.address_space, linear_idx_type=b.linear_idx_type]): Input B batched tensor tile. - c_shape_idx (
IndexList[rank]): Shape of the output tensor used to compute batch strides.
def apple_batched_matmul[rank: Int, EpilogueFnType: ElementwiseEpilogueFn, //, *, transpose_b: Bool = False](c: TileTensor[Engine=c.Engine, address_space=c.address_space, linear_idx_type=c.linear_idx_type], a: TileTensor[Engine=a.Engine, address_space=a.address_space, linear_idx_type=a.linear_idx_type], b: TileTensor[Engine=b.Engine, address_space=b.address_space, linear_idx_type=b.linear_idx_type], c_shape_idx: IndexList[rank], epilogue_fn: EpilogueFnType)
Performs a batched single-precision matmul via the Apple Accelerate library, then applies epilogue_fn to the output.
epilogue_fn receives rank-rank coordinates in the original
(uncollapsed) output shape.
Parameters:
- rank (
Int): The rank of the output tensor (must be >= 3). - EpilogueFnType (
ElementwiseEpilogueFn): Type ofepilogue_fn(inferred). - transpose_b (
Bool): Whether to treat B as transposed.
Args:
- c (
TileTensor[Engine=c.Engine, address_space=c.address_space, linear_idx_type=c.linear_idx_type]): Output batched tensor tile. - a (
TileTensor[Engine=a.Engine, address_space=a.address_space, linear_idx_type=a.linear_idx_type]): Input A batched tensor tile. - b (
TileTensor[Engine=b.Engine, address_space=b.address_space, linear_idx_type=b.linear_idx_type]): Input B batched tensor tile. - c_shape_idx (
IndexList[rank]): Shape of the output tensor used to compute batch strides. - epilogue_fn (
EpilogueFnType): Epilogue applied element-wise to the output.
def apple_batched_matmul[rank: Int, ComputeFnType: ElementwiseComputeFn, //, *, transpose_b: Bool = False](c: TileTensor[Engine=c.Engine, address_space=c.address_space, linear_idx_type=c.linear_idx_type], a: TileTensor[Engine=a.Engine, address_space=a.address_space, linear_idx_type=a.linear_idx_type], b: TileTensor[Engine=b.Engine, address_space=b.address_space, linear_idx_type=b.linear_idx_type], c_shape_idx: IndexList[rank], compute_fn: ComputeFnType)
Performs a batched single-precision matmul via the Apple Accelerate library, storing compute_fn(idx, value) into c.
compute_fn receives rank-rank coordinates in the original
(uncollapsed) output shape.
Parameters:
- rank (
Int): The rank of the output tensor (must be >= 3). - ComputeFnType (
ElementwiseComputeFn): Type ofcompute_fn(inferred). - transpose_b (
Bool): Whether to treat B as transposed.
Args:
- c (
TileTensor[Engine=c.Engine, address_space=c.address_space, linear_idx_type=c.linear_idx_type]): Output batched tensor tile. - a (
TileTensor[Engine=a.Engine, address_space=a.address_space, linear_idx_type=a.linear_idx_type]): Input A batched tensor tile. - b (
TileTensor[Engine=b.Engine, address_space=b.address_space, linear_idx_type=b.linear_idx_type]): Input B batched tensor tile. - c_shape_idx (
IndexList[rank]): Shape of the output tensor used to compute batch strides. - compute_fn (
ComputeFnType): Maps each output index and value to the value to store.