Global Layout

8.1. Global Layout

Global layout defines how tilus get the address of an element in a global tensor. When we use global_view() to create a global tensor (view) from a pointer, or when we use global_tensor() to allocate a global tensor, we can optionally specify the layout of the global tensor via layout or strides argument. There are different cases:

  • We do not provide either layout or strides argument, then tilus will use the default layout, which is a row-major compact layout.

  • We provide strides argument, then tilus will use the provided strides to construct a layout that using the provided strides to access the elements in the global tensor.

  • We provide layout argument, then tilus will use the provided layout directly.

No matter which case, tilus will generate a GlobalLayout object to represent the layout of the global tensor. To create a custom global layout, we can use the create() method of the GlobalLayout class, which allows us to define a custom mapping function from indices to offset.

We support the following functions to create a global layout:

tilus.ir.layout.global_row_major(*shape)

Create a global layout with row-major order.

tilus.ir.layout.global_column_major(*shape)

Create a global layout with column-major order.

tilus.ir.layout.global_strides(shape, strides)

Create a global layout with specified strides.

tilus.ir.layout.global_compose(lhs, rhs, *others)

Compose multiple global layouts.

tilus.ir.GlobalLayout.create(shape, size, ...)

Create a global layout with custom mapping.

Please refer to the GlobalLayout class for internals of the global layout.