23#ifndef TVM_TIRX_LAYOUT_H_
24#define TVM_TIRX_LAYOUT_H_
26#include <tvm/ffi/container/array.h>
27#include <tvm/ffi/container/tuple.h>
28#include <tvm/ffi/enum.h>
29#include <tvm/ffi/function.h>
30#include <tvm/ffi/object.h>
56 virtual PrimExpr GetSize(ffi::Optional<ffi::String> axis_name = std::nullopt)
const = 0;
59 virtual PrimExpr GetSpan(ffi::Optional<ffi::String> axis_name = std::nullopt)
const = 0;
62 virtual ffi::Map<ffi::String, PrimExpr>
Apply(ffi::Array<PrimExpr> coord)
const = 0;
63 virtual ffi::Map<ffi::String, PrimExpr>
Apply(
PrimExpr coord)
const = 0;
64 virtual ffi::Map<ffi::String, PrimExpr>
Apply(
const ffi::Array<PrimExpr>& coord,
65 const ffi::Array<PrimExpr>& shape)
const;
72 const ffi::Array<PrimExpr>& inner_shape)
const = 0;
75 virtual ffi::Optional<Layout>
Slice(
const ffi::Array<PrimExpr>& shape,
76 const ffi::Array<Range>& region)
const = 0;
83 const ffi::Array<PrimExpr>& right_shape)
const = 0;
93 const ffi::Array<PrimExpr>& tiled_shape,
94 const ffi::Array<PrimExpr>& inner_shape)
const = 0;
104 const ffi::Array<PrimExpr>& tiled_shape,
105 const ffi::Array<PrimExpr>& outer_shape)
const = 0;
114 const Layout& sum_layout,
const ffi::Array<PrimExpr>& interleaved_shape,
115 const ffi::Array<PrimExpr>& right_shape)
const = 0;
124 const ffi::Array<PrimExpr>& interleaved_shape,
125 const ffi::Array<PrimExpr>& left_shape)
const = 0;
172 const ffi::String&
name()
const {
return get()->_str_index; }
196 namespace refl = tvm::ffi::reflection;
197 refl::ObjectDef<IterNode>()
207class Iter :
public ffi::ObjectRef {
220 namespace refl = tvm::ffi::reflection;
221 refl::ObjectDef<TileLayoutNode>()
247 const ffi::Array<
PrimExpr>& shape) const final;
254 const ffi::Array<
PrimExpr>& inner_shape) const final;
257 const ffi::Array<
PrimExpr>& right_shape) const final;
261 const ffi::Array<
PrimExpr>& tiled_shape,
262 const ffi::Array<
PrimExpr>& inner_shape) const final;
266 const ffi::Array<
PrimExpr>& tiled_shape,
267 const ffi::Array<
PrimExpr>& outer_shape) const final;
270 const ffi::Array<
PrimExpr>& interleaved_shape,
271 const ffi::Array<
PrimExpr>& right_shape) const final;
274 const ffi::Array<
PrimExpr>& interleaved_shape,
275 const ffi::Array<
PrimExpr>& left_shape) const final;
282 const ffi::Array<
Range>& region) const final;
305 ffi::Map<Axis, PrimExpr>
offset);
328 namespace refl = tvm::ffi::reflection;
329 refl::ObjectDef<ComposeLayoutNode>()
330 .def_ro(
"per_element", &ComposeLayoutNode::per_element)
331 .def_ro(
"swizzle_len", &ComposeLayoutNode::swizzle_len)
332 .def_ro(
"atom_len", &ComposeLayoutNode::atom_len)
333 .def_ro(
"swizzle_inner", &ComposeLayoutNode::swizzle_inner)
334 .def_ro(
"inner_mask", &ComposeLayoutNode::inner_mask)
335 .def_ro(
"outer_mask", &ComposeLayoutNode::outer_mask)
336 .def_ro(
"tile_layout", &ComposeLayoutNode::tile_layout);
346 PrimExpr GetSize(ffi::Optional<ffi::String> axis_name = std::nullopt) const final;
349 PrimExpr GetSpan(ffi::Optional<ffi::String> axis_name = std::nullopt) const final;
355 const ffi::Array<
PrimExpr>& shape) const final;
362 const ffi::Array<
PrimExpr>& inner_shape) const final;
365 const ffi::Array<
PrimExpr>& right_shape) const final;
369 const ffi::Array<
PrimExpr>& tiled_shape,
370 const ffi::Array<
PrimExpr>& inner_shape) const final;
374 const ffi::Array<
PrimExpr>& tiled_shape,
375 const ffi::Array<
PrimExpr>& outer_shape) const final;
378 const ffi::Array<
PrimExpr>& interleaved_shape,
379 const ffi::Array<
PrimExpr>& right_shape) const final;
382 const ffi::Array<
PrimExpr>& interleaved_shape,
383 const ffi::Array<
PrimExpr>& left_shape) const final;
387 const ffi::Array<
Range>& region) const final;
395 TileLayout tile_layout,
bool swizzle_inner =
true);
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Range container
Definition expr.h:1025
Managed reference class to TargetObj.
Definition target.h:136
bool IsThreadAxis() const
Check if the axis is a thread axis.
ffi::Optional< FAxisSplitter > GetSplitter() const
Get the splitter of the (thread) axis.
ffi::Optional< ExecScope > GetScope() const
Get the scope of the (thread) axis.
ffi::Optional< ffi::String > GetBackend() const
The backend owning this axis, if any.
bool IsMemoryAxis() const
Check if the axis is a memory axis.
ffi::Optional< ExecScope > GetSubscope() const
Get the subscope of the (thread) axis.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Axis", AxisNode, ffi::EnumObj)
ffi::Optional< FAxisFuser > GetFuser() const
Get the fuser of the (thread) axis.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Axis, ffi::Enum, AxisNode)
static TVM_TIRX_DLL Axis Get(const ffi::String &name)
Get or create the axis with the given name.
const ffi::String & name() const
Return the canonical axis name.
Definition layout.h:172
int atom_len
Definition layout.h:319
int swizzle_len
Definition layout.h:318
int inner_mask
Definition layout.h:324
TileLayout tile_layout
Definition layout.h:321
bool CompatibleWithShape(const ffi::Array< PrimExpr > &shape) const final
Check if the layout is compatible with the shape.
ComposeLayoutNode(ffi::UnsafeInit)
Definition layout.h:315
bool swizzle_inner
Definition layout.h:320
int outer_mask
Definition layout.h:325
ComposeLayoutNode(TileLayout tile_layout)
Definition layout.h:314
static void RegisterReflection()
Definition layout.h:327
bool VerifyWellFormed() const final
Verify if the layout is well-formed.
int per_element
Definition layout.h:317
TVM_DEFINE_OBJECT_REF_COW_METHOD(ComposeLayoutNode)
TVM_TIRX_DLL ComposeLayout(int per_element, int swizzle_len, int atom_len, TileLayout tile_layout, bool swizzle_inner=true)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ComposeLayout, Layout, ComposeLayoutNode)
Definition exec_scope.h:47
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition layout.h:203
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Iter", IterNode, ffi::Object)
IterNode(PrimExpr extent, PrimExpr stride, Axis axis)
Definition layout.h:188
Axis axis
Definition layout.h:193
PrimExpr extent
Definition layout.h:191
PrimExpr stride
Definition layout.h:192
IterNode(ffi::UnsafeInit tag)
Definition layout.h:186
static void RegisterReflection()
Definition layout.h:195
TVM_TIRX_DLL Iter(PrimExpr extent, PrimExpr stride, Axis axis)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Iter, ffi::ObjectRef, IterNode)
virtual PrimExpr GetSpan(ffi::Optional< ffi::String > axis_name=std::nullopt) const =0
Get the span of the layout (of some axis)
TVM_FFI_DECLARE_OBJECT_INFO("tirx.Layout", LayoutNode, ffi::Object)
virtual bool VerifyWellFormed() const =0
Verify if the layout is well-formed.
virtual ffi::Optional< Layout > IsTileOuter(const Layout &tile_layout, const ffi::Array< PrimExpr > &tiled_shape, const ffi::Array< PrimExpr > &outer_shape) const =0
Check if the layout is the outer layout of a tiled layout.
virtual ffi::Optional< Layout > IsDirectSumLeft(const Layout &sum_layout, const ffi::Array< PrimExpr > &interleaved_shape, const ffi::Array< PrimExpr > &left_shape) const =0
Check if this layout is the left addend A in a direct-sum A + B over the interleaved domain S_A \otim...
virtual PrimExpr GetSize(ffi::Optional< ffi::String > axis_name=std::nullopt) const =0
Get the size of the layout (of some axis)
virtual Layout Canonicalize() const =0
Turn the layout to canonical form.
virtual Layout DirectSum(const TileLayout &left, const ffi::Array< PrimExpr > &left_shape, const ffi::Array< PrimExpr > &right_shape) const =0
Direct-sum on the tiling domain (unscaled composition) Given left layout A (grouped by left_shape) an...
virtual ffi::Map< ffi::String, PrimExpr > Apply(PrimExpr coord) const =0
virtual bool CompatibleWithShape(const ffi::Array< PrimExpr > &shape) const =0
Compatible with shape.
virtual ffi::Optional< Layout > Slice(const ffi::Array< PrimExpr > &shape, const ffi::Array< Range > ®ion) const =0
Slice the layout with a given shape and region.
virtual ffi::Map< ffi::String, PrimExpr > Apply(ffi::Array< PrimExpr > coord) const =0
Apply layout on the input coordinate and get the mapped output.
virtual Layout Tile(const TileLayout &outer, const ffi::Array< PrimExpr > &outer_shape, const ffi::Array< PrimExpr > &inner_shape) const =0
Tile the current layout with a given layout.
virtual ffi::Map< ffi::String, PrimExpr > Apply(const ffi::Array< PrimExpr > &coord, const ffi::Array< PrimExpr > &shape) const
virtual ffi::Optional< TileLayout > IsTileInner(const Layout &tile_layout, const ffi::Array< PrimExpr > &tiled_shape, const ffi::Array< PrimExpr > &inner_shape) const =0
Check if the layout is the inner layout of a tiled layout.
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition layout.h:127
virtual ffi::Optional< TileLayout > IsDirectSumRight(const Layout &sum_layout, const ffi::Array< PrimExpr > &interleaved_shape, const ffi::Array< PrimExpr > &right_shape) const =0
Check if this layout is the right addend B in a direct-sum A + B over the interleaved domain S_A \oti...
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Layout, ffi::ObjectRef, LayoutNode)
ffi::Map< Axis, PrimExpr > offset
Definition layout.h:217
PrimExpr GetSpan(ffi::Optional< ffi::String > axis_name=std::nullopt) const final
Get the span of the layout (of some axis)
PrimExpr GetSize(ffi::Optional< ffi::String > axis_name=std::nullopt) const final
Get the size of the layout (of some axis)
ffi::Optional< Layout > Slice(const ffi::Array< PrimExpr > &shape, const ffi::Array< Range > ®ion) const final
Slice the layout with a given shape and region.
ffi::Optional< Layout > IsTileOuter(const Layout &tile_layout, const ffi::Array< PrimExpr > &tiled_shape, const ffi::Array< PrimExpr > &outer_shape) const final
Check if the layout is the outer layout of a tiled layout.
ffi::Array< Iter > replica
Definition layout.h:216
bool IsTrivial() const
Is the layout trivial (pure memory, identical mapping)
ffi::Map< ffi::String, PrimExpr > Apply(ffi::Array< PrimExpr > coord) const final
Apply the input coordinate and get the mapped output.
ffi::Array< Iter > shard
Definition layout.h:215
ffi::Array< PrimExpr > GetShardShape() const
Get the shape of the shard.
ffi::Optional< Layout > IsDirectSumLeft(const Layout &sum_layout, const ffi::Array< PrimExpr > &interleaved_shape, const ffi::Array< PrimExpr > &left_shape) const final
Check if this layout is the left addend A in a direct-sum A + B over the interleaved domain S_A \otim...
static void RegisterReflection()
Definition layout.h:219
bool VerifyWellFormed() const final
Verify if the layout is well-formed.
ffi::Optional< TileLayout > IsDirectSumRight(const Layout &sum_layout, const ffi::Array< PrimExpr > &interleaved_shape, const ffi::Array< PrimExpr > &right_shape) const final
Check if this layout is the right addend B in a direct-sum A + B over the interleaved domain S_A \oti...
ffi::Optional< TileLayout > IsTileInner(const Layout &tile_layout, const ffi::Array< PrimExpr > &tiled_shape, const ffi::Array< PrimExpr > &inner_shape) const final
Check if the layout is the inner layout of a tiled layout.
bool HasMemoryAxis() const
Has Memory Axis.
Layout Canonicalize() const final
Turn the layout to canonical form.
Layout DirectSum(const TileLayout &left, const ffi::Array< PrimExpr > &left_shape, const ffi::Array< PrimExpr > &right_shape) const final
Direct-sum on the tiling domain (unscaled composition) Given left layout A (grouped by left_shape) an...
bool HasThreadAxis() const
Has Thread Axis.
static TileLayout DefaultLayout(ffi::Array< PrimExpr > shape)
Get the default layout for the shape.
bool CompatibleWithShape(const ffi::Array< PrimExpr > &shape) const final
Check if the layout is compatible with the shape.
ffi::Optional< Tuple< ExecScope, ExecScope > > GetScope() const
Get the scope pair of the layout.
Layout Tile(const TileLayout &outer, const ffi::Array< PrimExpr > &outer_shape, const ffi::Array< PrimExpr > &inner_shape) const final
Tile the layout with an outer layout.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.TileLayout", TileLayoutNode, LayoutNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TileLayout, Layout, TileLayoutNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(TileLayoutNode)
TVM_TIRX_DLL TileLayout(ffi::Array< Iter > shard, ffi::Array< Iter > replica, ffi::Map< Axis, PrimExpr > offset)
IRModule that holds the functions and type definitions.
ffi::TypedFunction< ffi::Array< Iter, void >(Target, ffi::String, Iter)> FAxisSplitter
Definition layout.h:140
constexpr int kPSUMMaxElemPerBank
Definition layout.h:401
constexpr int kPSUMBankNum
Definition layout.h:402
ffi::TypedFunction< ffi::Optional< Iter >(Target, ffi::String, ffi::String, Iter)> FAxisFuser
Definition layout.h:137
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_TIRX_DLL
Definition base.h:83
Compilation target object.