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).
Introduction to TileTensor
Mojo's layout package provides a
number of APIs for working with dense multidimensional arrays, which simplify
writing algorithms for handling linear algebra.
This section discusses the TileTensor abstraction and its related types:
TileTensoris a flexible tensor type that combines atile_layout.Layoutand a pointer to data.- The
tile_layout.Layoutstruct describes an arrangement of data in memory. A layout is a function that maps a set of logical coordinates (like (x, y) in a two-dimensional array) to a linear index value (such as an offset into a memory buffer). Layouts can describe simple row-major or column-major matrices, but also more complex organizations, like a matrix subdivided into tiles. Coordis a tuple-like container for storing integer coordinates that supports both compile-time and run-time values. It's used for defining logical coordinates and layout shapes, among other things.
The layout package also includes the older LayoutTensor type, and its
associated IntTuple-based layout type, layout.Layout. TileTensor is
essentially a new version of LayoutTensor that addresses several of the
shortcomings of that type. Most of the concepts are the same for both the old
and new types. TileTensor supports layouts with run-time dimensions, nested
layouts, and the newer Coord-based layout system, which minimizes the memory
footprint of the layout struct and can help reduce register pressure on GPUs.
LayoutTensor and its iterator, LayoutTensorIter, are deprecated as of MAX
26.7, so use TileTensor for new code:
- To step through a buffer of equally shaped tiles, such as the stages of a
pipelined shared-memory buffer, use
TileTensorIter, as shown in Stepping through a buffer of tiles. - To walk the tiles of a 2D tensor, loop over the tile coordinates and call
tile()for each one, as shown in Iterating over tiles. - If existing code depends on an operation that only
LayoutTensorprovides, such assimd_tile(), callto_layout_tensor()at that call site. The result is a view of the same memory, so the rest of the code can stay onTileTensor, but the result is itself a deprecatedLayoutTensor.
You can also convert a Coord-based layout into an IntTuple-based layout.
For more information on LayoutTensor, see the pages on
IntTuple-based layouts and
LayoutTensor.