25#ifndef TVM_S_TIR_DATA_LAYOUT_H_
26#define TVM_S_TIR_DATA_LAYOUT_H_
28#include <tvm/ffi/reflection/registry.h>
55 inline bool IsPrimal()
const {
return name_ >=
'A' && name_ <=
'Z'; }
56 inline std::string
name()
const {
return std::string(1, name_); }
61 if (name_ >=
'A' && name_ <=
'Z') {
111 ffi::Array<tirx::IterVar>
axes;
114 namespace refl = tvm::ffi::reflection;
115 refl::ObjectDef<SLayoutNode>()
128 explicit SLayout(
const ffi::Array<tirx::IterVar>& axes);
210 for (
auto x : iter_vars) {
252 if (!this->
defined())
return -1;
254 for (
size_t i = 0;
i < axes.size(); ++
i) {
255 if (axes[
i]->var->name == axis)
return static_cast<int32_t>(
i);
296 for (
auto var : iter_vars) {
297 if (var->var->name == axis.
name()) {
308 TVM_FFI_ICHECK(index >= 0 &&
static_cast<size_t>(index) <
ndim()) <<
"Invalid index " <<
i;
316 TVM_FFI_ICHECK(index >= 0 &&
static_cast<size_t>(index) <
ndim()) <<
"Invalid index " <<
i;
322 inline std::string
name()
const {
323 if (!
defined())
return "__undef__";
368 namespace refl = tvm::ffi::reflection;
369 refl::ObjectDef<SBijectiveLayoutNode>()
Definition base_expr.h:137
static PrimType Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Iteration Variable, represents an iteration over an integer interval.
Definition var.h:194
Definition data_layout.h:349
ffi::Array< PrimExpr > index_forward_rule
Describes how source axes can be mapped to the destination axes, e.g., [i0 / 16, i1,...
Definition data_layout.h:354
ffi::Array< PrimExpr > shape_forward_rule
Describes how source shapes can be mapped to the destination shapes.
Definition data_layout.h:358
static void RegisterReflection()
Definition data_layout.h:367
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.SBijectiveLayout", SBijectiveLayoutNode, ffi::Object)
SLayout dst_layout
The destination layout.
Definition data_layout.h:365
SLayout src_layout
The source layout.
Definition data_layout.h:363
ffi::Array< PrimExpr > index_backward_rule
Describes how destination axes can be mapped to the source axes.
Definition data_layout.h:356
ffi::Array< PrimExpr > shape_backward_rule
Describes how destination shapes can be mapped to the source shapes.
Definition data_layout.h:360
Bijective function mapping for data layout transformation. Given two SLayout, SBijectiveLayout build ...
Definition data_layout.h:386
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(SBijectiveLayout, ffi::ObjectRef, SBijectiveLayoutNode)
SBijectiveLayout(SLayout src_layout, SLayout dst_layout)
The constructor.
ffi::Array< PrimExpr > BackwardIndex(const ffi::Array< PrimExpr > &dst_index) const
ffi::Array< PrimExpr > BackwardShape(const ffi::Array< PrimExpr > &dst_shape) const
ffi::Array< PrimExpr > ForwardIndex(const ffi::Array< PrimExpr > &index) const
ffi::Array< PrimExpr > ForwardShape(const ffi::Array< PrimExpr > &shape) const
Definition data_layout.h:45
static const SLayoutAxis & Get(const char name)
bool IsPrimal() const
Definition data_layout.h:55
static const SLayoutAxis & Get(const std::string &name)
const SLayoutAxis & ToSubordinate() const
Definition data_layout.h:72
friend std::ostream & operator<<(std::ostream &os, const SLayoutAxis &l)
Definition data_layout.h:76
std::string name() const
Definition data_layout.h:56
static const SLayoutAxis & Get(const tirx::IterVar &itvar)
bool operator==(const SLayoutAxis &rhs) const
Definition data_layout.h:74
const SLayoutAxis & ToDual() const
Definition data_layout.h:60
const SLayoutAxis & ToPrimal() const
Definition data_layout.h:69
SLayout is to describe how data is organized within an N-dimention tensor. It is composed of upper ca...
Definition data_layout.h:101
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.SLayout", SLayoutNode, ffi::Object)
ffi::String name
string representation of layout, "" for scalar.
Definition data_layout.h:104
static void RegisterReflection()
Definition data_layout.h:113
ffi::Array< tirx::IterVar > axes
specify each axis of the layout, in which the variable name is the name of the axis....
Definition data_layout.h:111
Managed reference to SLayoutNode.
Definition data_layout.h:126
static IterVar PackIterVar(ffi::Array< IterVar > iters)
Packs the Given Array of IterVars into a Single IterVar. Each IterVar in the Array should represent e...
int32_t IndexOf(const std::string &axis) const
return the index of the input axis. If it is not found in the layout or the layout is undefined,...
Definition data_layout.h:251
friend std::ostream & operator<<(std::ostream &os, const SLayout &l)
allow output string of layout to ostream
Definition data_layout.h:340
int32_t IndexOf(const tirx::IterVar &iter) const
return the index of the input axis. If it is not found in the layout or the layout is undefined,...
Definition data_layout.h:276
size_t ndim() const
Definition data_layout.h:199
SLayout(const tvm::ffi::String &name)
construct from a string
Definition data_layout.h:131
int32_t IndexOf(const SLayoutAxis &axis) const
return the index of the input axis. If it is not found in the layout or the layout is undefined,...
Definition data_layout.h:267
SLayout Split(const SLayoutAxis &axis, size_t target_pos, int32_t factor) const
Split axis by size and put the sub-axis to position target_pos.
std::string name() const
Definition data_layout.h:322
bool Equals(const SLayout &rhs) const
Whether the two layouts are equal.
Definition data_layout.h:332
SLayout(const char *name)
construct from a string
Definition data_layout.h:134
SLayoutNode * operator->()
access the internal node container
Definition data_layout.h:152
size_t ndim_primal() const
Definition data_layout.h:205
SLayout(const std::string &name, PrimType index_ty=PrimType::Int(32))
construct from a string.
SLayout(const ffi::Array< tirx::IterVar > &axes)
SLayout SubLayout(size_t pos, size_t len) const
Returns a sub-layout which is the portion of the object that starts at dimension pos and spans len di...
bool Contains(const SLayoutAxis &axis) const
Whether the layout contains an axis.
Definition data_layout.h:292
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(SLayout, ffi::ObjectRef, SLayoutNode)
static const SLayout & Undef()
Return an undefined layout.
Definition data_layout.h:158
const SLayoutAxis & operator[](int32_t i) const
Definition data_layout.h:305
SLayout ExpandPrimal(const SLayout &dst_layout)
Returns a new layout where the dims have been expanded to match the primal dimensions.
Definition data_layout.h:224
static ffi::Array< IterVar > UnpackIterVar(IterVar packed_iter)
Unpacks a Packed IterVar into its constituents.
IterVar PackedAxisAt(int32_t i) const
Definition data_layout.h:313
int32_t FactorOf(const SLayoutAxis &axis) const
Get the factor size of the subordinate axis.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Common operators defined for Expr.