Skip to main content

Mojo function

row_major

row_major(var shape: Coord[shape.element_types]) -> Layout[shape.element_types, #kgen.variadic.reduce(#kgen.variadic.reduce(shape.element_types, base=, reducer=[PrevV: Variadic[CoordLike], VA: Variadic[CoordLike], idx: __mlir_type.index] #kgen.variadic.concat(PrevV, VA[(add (mul idx, -1), len(VA), -1)])), base=, reducer=[PrevV: Variadic[CoordLike], VA: Variadic[CoordLike], idx: __mlir_type.index] #kgen.variadic.concat(ComptimeInt[1] if (idx == 0)._mlir_value else RuntimeInt[VA[(add idx, -1)].DTYPE if VA[(add idx, -1)].is_static_value.__bool__().__invert__()._mlir_value else PrevV[0].DTYPE] if VA[(add idx, -1)].is_static_value.__bool__().__invert__() if VA[(add idx, -1)].is_static_value.__bool__().__invert__()._mlir_value else PrevV[0].is_static_value.__bool__().__invert__() else ComptimeInt[(VA[(add idx, -1)].static_value * PrevV[0].static_value)], PrevV))]

Creates a row-major layout from a shape Coord.

Row-major means the rightmost dimension has stride 1, and each preceding dimension has stride equal to the product of all following dimensions.

Args:

  • ​shape (Coord): The shape as a Coord.

Returns:

Layout: A Layout with row-major strides.

row_major[*idxs: Int]() -> Layout[#kgen.variadic.reduce(idxs, base=, reducer=[PrevV: Variadic[CoordLike], VA: Variadic[Int], idx: __mlir_type.index] #kgen.variadic.concat(PrevV, ComptimeInt[VA[idx]])), #kgen.variadic.reduce(#kgen.variadic.reduce(#kgen.variadic.reduce(idxs, base=, reducer=[PrevV: Variadic[CoordLike], VA: Variadic[Int], idx: __mlir_type.index] #kgen.variadic.concat(PrevV, ComptimeInt[VA[idx]])), base=, reducer=[PrevV: Variadic[CoordLike], VA: Variadic[CoordLike], idx: __mlir_type.index] #kgen.variadic.concat(PrevV, VA[(add (mul idx, -1), len(VA), -1)])), base=, reducer=[PrevV: Variadic[CoordLike], VA: Variadic[CoordLike], idx: __mlir_type.index] #kgen.variadic.concat(ComptimeInt[1] if (idx == 0)._mlir_value else RuntimeInt[VA[(add idx, -1)].DTYPE if VA[(add idx, -1)].is_static_value.__bool__().__invert__()._mlir_value else PrevV[0].DTYPE] if VA[(add idx, -1)].is_static_value.__bool__().__invert__() if VA[(add idx, -1)].is_static_value.__bool__().__invert__()._mlir_value else PrevV[0].is_static_value.__bool__().__invert__() else ComptimeInt[(VA[(add idx, -1)].static_value * PrevV[0].static_value)], PrevV))]

Creates a row-major layout from compile-time shape dimensions.

Parameters:

  • ​*idxs (Int): The shape dimensions as compile-time integers.

Returns:

Layout: A Layout with row-major strides.

row_major(idx: ComptimeInt[idx.val]) -> Layout[ComptimeInt[idx.val], ComptimeInt[1]]

Creates a 1D row-major layout from a compile-time dimension.

Args:

  • ​idx (ComptimeInt): The shape dimension as a ComptimeInt.

Returns:

Layout: A 1D Layout with stride 1.

row_major(idx: RuntimeInt[idx.dtype]) -> Layout[RuntimeInt[idx.dtype], ComptimeInt[1]]

Creates a 1D row-major layout from a runtime dimension.

Args:

  • ​idx (RuntimeInt): The shape dimension as a RuntimeInt.

Returns:

Layout: A 1D Layout with stride 1.

Was this page helpful?