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
orstrides
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:
|
Create a global layout with row-major order. |
Create a global layout with column-major order. |
|
|
Create a global layout with specified strides. |
|
Compose multiple global layouts. |
|
Create a global layout with custom mapping. |
Please refer to the GlobalLayout
class for internals of the global layout.