IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

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[dtype, LayoutType, MutExternalOrigin, address_space=address_space]: A mutable TileTensor backed by stack-allocated memory.