25 #ifndef TVM_TIR_DATA_LAYOUT_H_
26 #define TVM_TIR_DATA_LAYOUT_H_
52 inline bool IsPrimal()
const {
return name_ >=
'A' && name_ <=
'Z'; }
53 inline std::string
name()
const {
return std::string(1, name_); }
58 if (name_ >=
'A' && name_ <=
'Z') {
111 v->Visit(
"name", &
name);
112 v->Visit(
"axes", &
axes);
189 for (
auto x : operator->()->axes) {
205 std::string new_src_layout_str =
"";
206 for (
auto dst_axis : dst_layout->
axes) {
209 new_src_layout_str += dst_axis->var->name_hint;
214 new_src_layout_str += this->
name();
215 new_src_layout =
Layout(new_src_layout_str);
216 return new_src_layout;
227 if (!this->
defined())
return -1;
229 for (
size_t i = 0; i < axes.size(); ++i) {
260 ICHECK(
defined()) <<
"Try to access axis from an undefined layout.";
261 int32_t index = i < 0 ? static_cast<int32_t>(
ndim() + i) : i;
262 ICHECK(index >= 0 &&
static_cast<size_t>(index) <
ndim()) <<
"Invalid index " << i;
268 inline std::string
name()
const {
269 if (!
defined())
return "__undef__";
322 static constexpr
const char*
_type_key =
"tir.BijectiveLayout";
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:43
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:219
Base class of all object reference.
Definition: object.h:519
bool defined() const
Definition: object.h:552
Object * get_mutable() const
Definition: object.h:607
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
Definition: data_layout.h:295
Array< PrimExpr > shape_backward_rule
Describes how destination shapes can be mapped to the source shapes.
Definition: data_layout.h:306
Layout src_layout
The source layout.
Definition: data_layout.h:309
Layout dst_layout
The destination layout.
Definition: data_layout.h:311
void VisitAttrs(AttrVisitor *v)
Definition: data_layout.h:313
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:300
Array< PrimExpr > index_backward_rule
Describes how destination axes can be mapped to the source axes.
Definition: data_layout.h:302
Array< PrimExpr > shape_forward_rule
Describes how source shapes can be mapped to the destination shapes.
Definition: data_layout.h:304
TVM_DECLARE_FINAL_OBJECT_INFO(BijectiveLayoutNode, Object)
static constexpr const char * _type_key
Definition: data_layout.h:322
Bijective function mapping for data layout transformation. Given two Layout, BijectiveLayout build an...
Definition: data_layout.h:332
BijectiveLayout(Layout src_layout, Layout dst_layout)
The constructor.
Array< PrimExpr > ForwardShape(const Array< PrimExpr > &shape) const
TVM_DEFINE_OBJECT_REF_METHODS(BijectiveLayout, ObjectRef, BijectiveLayoutNode)
Array< PrimExpr > BackwardShape(const Array< PrimExpr > &dst_shape) const
Array< PrimExpr > BackwardIndex(const Array< PrimExpr > &dst_index) const
Array< PrimExpr > ForwardIndex(const Array< PrimExpr > &index) const
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:315
Definition: data_layout.h:42
std::string name() const
Definition: data_layout.h:53
static const LayoutAxis & Get(const char name)
const LayoutAxis & ToPrimal() const
Definition: data_layout.h:66
bool IsPrimal() const
Definition: data_layout.h:52
static const LayoutAxis & Get(const tir::IterVar &itvar)
const LayoutAxis & ToSubordinate() const
Definition: data_layout.h:69
const LayoutAxis & ToDual() const
Definition: data_layout.h:57
friend std::ostream & operator<<(std::ostream &os, const LayoutAxis &l)
Definition: data_layout.h:73
static const LayoutAxis & Get(const std::string &name)
bool operator==(const LayoutAxis &rhs) const
Definition: data_layout.h:71
Layout is to describe how data is organized within an N-dimention tensor. It is composed of upper cas...
Definition: data_layout.h:98
void VisitAttrs(AttrVisitor *v)
Definition: data_layout.h:110
Array< tir::IterVar > axes
specify each axis of the layout, in which the variable name is the name of the axis....
Definition: data_layout.h:108
TVM_DECLARE_FINAL_OBJECT_INFO(LayoutNode, Object)
static constexpr const char * _type_key
Definition: data_layout.h:115
String name
string representation of layout, "" for scalar.
Definition: data_layout.h:101
Managed reference to LayoutNode.
Definition: data_layout.h:123
Layout(const char *name)
construct from a string
Definition: data_layout.h:131
static const Layout & Undef()
Return an undefined layout.
Definition: data_layout.h:155
LayoutNode * operator->()
access the internal node container
Definition: data_layout.h:149
size_t ndim_primal() const
Definition: data_layout.h:186
bool Equals(const Layout &rhs) const
Whether the two layouts are equal.
Definition: data_layout.h:278
TVM_DEFINE_OBJECT_REF_METHODS(Layout, ObjectRef, LayoutNode)
friend std::ostream & operator<<(std::ostream &os, const Layout &l)
allow output string of layout to ostream
Definition: data_layout.h:286
Layout 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...
int32_t IndexOf(const LayoutAxis &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:226
size_t ndim() const
Definition: data_layout.h:180
Layout ExpandPrimal(const Layout &dst_layout)
Returns a new layout where the dims have been expanded to match the primal dimensions.
Definition: data_layout.h:202
std::string name() const
Definition: data_layout.h:268
bool Contains(const LayoutAxis &axis) const
Whether the layout contains an axis.
Definition: data_layout.h:249
const LayoutAxis & operator[](int32_t i) const
Definition: data_layout.h:259
int32_t FactorOf(const LayoutAxis &axis) const
Get the factor size of the subordinate axis.
Layout(const tvm::String &name)
construct from a string
Definition: data_layout.h:128
Layout(const std::string &name, DataType dtype=DataType::Int(32))
construct from a string.
Layout(const Array< tir::IterVar > &axes)
Layout Split(const LayoutAxis &axis, size_t target_pos, int32_t factor) const
Split axis by size and put the sub-axis to position target_pos.
String name_hint
The hint to the variable name.
Definition: var.h:54
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
const Op & undef()
Returns an initialized but arbitrary value.
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Common operators defined for Expr.