Skip to main content

Mojo function

stack_allocation

stack_allocation[LayoutType: TensorLayout, //, dtype: DType, address_space: AddressSpace = AddressSpace.GENERIC](var layout: LayoutType) -> TileTensor[dtype, LayoutType, MutExternalOrigin, address_space=address_space] where LayoutType.all_dims_known

Allocate a TileTensor on the stack with the given layout.

Creates a stack-allocated buffer sized for the layout and returns a TileTensor pointing to it. The layout must have all dimensions known at compile time.

Constraints:

All layout dimensions must be statically known.

Parameters:

  • ​LayoutType (TensorLayout): The layout type (inferred from layout argument).
  • ​dtype (DType): The data type of tensor elements.
  • ​address_space (AddressSpace): Memory address space (default: GENERIC).

Args:

  • ​layout (LayoutType): The layout instance defining shape and strides.

Returns:

TileTensor: A mutable TileTensor backed by stack-allocated memory.

Was this page helpful?