Skip to main content

Overview

cute::Layout is the fundamental abstraction in CuTe for describing the mapping between logical multi-dimensional coordinates and linear memory offsets. A Layout is defined by a Shape (extents in each dimension) and a Stride (steps between adjacent elements in each dimension).

Class Template

Template Parameters

IntTuple
The shape of the layout, specifying the extent in each mode. Can be a single integer or a hierarchical tuple of integers.
IntTuple
default:"LayoutLeft::Apply<Shape>"
The stride of the layout, specifying the step size in each mode. Defaults to column-major (LayoutLeft) ordering.

Source Location

include/cute/layout.hpp:98-311

Member Functions

Accessors

shape()

Returns the shape of the layout or a specific mode. Example:

stride()

Returns the stride of the layout or a specific mode. Example:

Mapping Operations

operator()

Maps a logical coordinate to a linear index, or slices the layout if the coordinate contains _ (underscore). Parameters:
  • coord: Logical coordinate (single integer or tuple)
Returns: Linear index (integer) or sliced layout Example:

Composition

compose()

Composes this layout with another layout: result(c) = this(other(c)). Example:

with_shape()

Composes this layout with a layout having the given shape.

Tiling

tile()

Tiles this layout by dividing it into blocks defined by the other layout. Example:

Coordinate Conversion

get_hier_coord()

Converts a linear index to hierarchical logical coordinates. Returns: Coordinate with the same hierarchical structure as the shape

get_flat_coord()

Converts a linear index to flat logical coordinates. Returns: Flat rank-N coordinate tuple

get_1d_coord()

Converts a linear index to a generalized column-major 1D coordinate. Returns: Single integer coordinate

Factory Functions

make_layout()

Creates a Layout with the specified shape and stride. If stride is omitted, defaults to LayoutLeft (column-major). Example:

make_identity_layout()

Creates an identity layout where layout(i) = i.

make_layout_like()

Creates a compact layout with the same shape and stride ordering as the input layout.

Utility Functions

size()

Returns the number of elements in the layout or a specific mode.

rank()

Returns the number of modes (dimensions) in the layout.

depth()

Returns the hierarchical depth of the layout.

cosize()

Returns the codomain size (maximum value + 1 that the layout can produce).

coalesce()

Simplifies the layout by combining adjacent modes that can be merged. Example:

filter()

Removes all stride-0 modes and size-1 modes from the layout.

complement()

Builds the complement layout that points to elements not covered by the input layout.

right_inverse()

Builds the right-inverse layout such that layout(result(i)) == i.

Common Layout Types

LayoutLeft

Column-major (Fortran-style) layout where the first mode has stride-1.

LayoutRight

Row-major (C-style) layout where the last mode has stride-1.

Usage Examples

Basic Layout Creation

Hierarchical Layouts

Slicing and Tiling

Working with Strides

See Also