19 #ifndef TVM_RELAX_STRUCT_INFO_H_
20 #define TVM_RELAX_STRUCT_INFO_H_
22 #include <tvm/ffi/reflection/registry.h>
40 refl::ObjectDef<ObjectStructInfoNode>();
43 static constexpr
const char*
_type_key =
"relax.ObjectStructInfo";
71 refl::ObjectDef<PrimStructInfoNode>()
76 static constexpr
const char*
_type_key =
"relax.PrimStructInfo";
113 refl::ObjectDef<ShapeStructInfoNode>()
118 static constexpr
const char*
_type_key =
"relax.ShapeStructInfo";
174 if (!
shape.defined())
return {};
175 ShapeStructInfo shape_sinfo = Downcast<ShapeStructInfo>(this->shape.value()->struct_info_);
176 return shape_sinfo->values;
181 refl::ObjectDef<TensorStructInfoNode>()
188 static constexpr
const char*
_type_key =
"relax.TensorStructInfo";
236 static constexpr
const char*
_type_key =
"relax.TupleStructInfo";
303 refl::ObjectDef<FuncStructInfoNode>()
310 static constexpr
const char*
_type_key =
"relax.FuncStructInfo";
371 template <
typename T>
373 using TNode =
typename T::ContainerType;
374 if (
const TNode* ptr = expr->struct_info_.as<TNode>()) {
375 return GetRef<T>(ptr);
388 template <
typename T>
390 ICHECK(expr->struct_info_.defined())
391 <<
"The struct_info is not populated, check if you have normalized the expr";
392 return expr->struct_info_.as<T>();
403 ICHECK(ptr) <<
"The struct_info is not populated, check if you have normalized the expr";
404 return GetRef<StructInfo>(ptr);
415 return ptr !=
nullptr && ptr->
fields.size() == 0;
The utility for constructing Relax binding blocks.
Reference to PrimExprNode.
Definition: expr.h:129
Managed reference to RelaxExprNode.
Definition: expr.h:446
Definition: source_map.h:113
Please refer to TypedEnvFunc<R(Args..)>.
Definition: env_func.h:102
Definition: block_builder.h:264
Structure information about function.
Definition: struct_info.h:270
TVM_DECLARE_FINAL_OBJECT_INFO(FuncStructInfoNode, StructInfoNode)
bool IsOpaque() const
Definition: struct_info.h:299
static constexpr const char * _type_key
Definition: struct_info.h:310
StructInfo ret
The struct info of the function's return value.
Definition: struct_info.h:281
Optional< StructInfoDeriveFunc > derive_func
Derivation function of opaque functions that may take any number of parameters.
Definition: struct_info.h:287
bool purity
Whether the function is pure.
Definition: struct_info.h:293
static void RegisterReflection()
Definition: struct_info.h:301
Optional< Array< StructInfo > > params
The parameter struct info of the function.
Definition: struct_info.h:277
Managed reference to FuncStructInfoNode.
Definition: struct_info.h:318
FuncStructInfo(Array< StructInfo > params, StructInfo ret, bool purity=true, Span span=Span())
Constructor from parameter struct info and return value struct info.
static FuncStructInfo OpaqueFunc(StructInfoDeriveFunc derive_func, bool purity=false, Span span=Span())
Constructing an opaque function struct info using derive_func.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(FuncStructInfo, StructInfo, FuncStructInfoNode)
static FuncStructInfo OpaqueFunc(StructInfo ret=ObjectStructInfo(), bool purity=false, Span span=Span())
Construct an opaque function using from return struct info.
Opaque object.
Definition: struct_info.h:36
TVM_DECLARE_FINAL_OBJECT_INFO(ObjectStructInfoNode, StructInfoNode)
static constexpr const char * _type_key
Definition: struct_info.h:43
static void RegisterReflection()
Definition: struct_info.h:38
Managed reference to ObjectStructInfoNode.
Definition: struct_info.h:51
ObjectStructInfo(Span span=Span())
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ObjectStructInfo, StructInfo, ObjectStructInfoNode)
Primitive value.
Definition: struct_info.h:61
Optional< PrimExpr > value
Underlying primitive value, if known.
Definition: struct_info.h:64
static constexpr const char * _type_key
Definition: struct_info.h:76
DataType dtype
Underlying data type of the primitive value.
Definition: struct_info.h:67
TVM_DECLARE_FINAL_OBJECT_INFO(PrimStructInfoNode, StructInfoNode)
static void RegisterReflection()
Definition: struct_info.h:69
Managed reference to PrimStructInfoNode.
Definition: struct_info.h:84
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(PrimStructInfo, StructInfo, PrimStructInfoNode)
PrimStructInfo(DataType dtype, Span span=Span())
PrimStructInfo(PrimExpr value, Span span=Span())
StructInfo of shape value.
Definition: struct_info.h:98
static void RegisterReflection()
Definition: struct_info.h:111
Optional< Array< PrimExpr > > values
optionally stores the symbolic value patterns of the shape
Definition: struct_info.h:101
bool IsUnknownNdim() const
Definition: struct_info.h:109
int ndim
The number of dimension of the shape, can be unknown.
Definition: struct_info.h:106
TVM_DECLARE_FINAL_OBJECT_INFO(ShapeStructInfoNode, StructInfoNode)
static constexpr const char * _type_key
Definition: struct_info.h:118
Managed reference to ShapeStructInfoNode.
Definition: struct_info.h:126
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ShapeStructInfo, StructInfo, ShapeStructInfoNode)
ShapeStructInfo(Array< PrimExpr > values, Span span=Span())
Construction with known symbolic shape patterns.
ShapeStructInfo(int ndim, Span span=Span())
Construction with known unknown symbolic shape patterns.
Base type of all structure information.
Definition: expr.h:110
Managed reference to StructInfoNode.
Definition: expr.h:135
StructInfo of Tensor.
Definition: struct_info.h:147
Optional< VDevice > vdevice
The virtual device, indicates where the tensor is expected to be executed.
Definition: struct_info.h:157
TVM_DECLARE_FINAL_OBJECT_INFO(TensorStructInfoNode, StructInfoNode)
Optional< Array< PrimExpr > > GetShape() const
Definition: struct_info.h:173
DataType dtype
The content data type, use void to denote the dtype is unknown.
Definition: struct_info.h:159
static constexpr const char * _type_key
Definition: struct_info.h:188
static void RegisterReflection()
Definition: struct_info.h:179
int ndim
The number of dimension of the tensor, can be unknown.
Definition: struct_info.h:164
bool IsUnknownDtype() const
Definition: struct_info.h:170
Optional< Expr > shape
optionally store the shape expression of the tensor.
Definition: struct_info.h:153
bool IsUnknownNdim() const
Definition: struct_info.h:167
Managed reference to TensorStructInfoNode.
Definition: struct_info.h:196
TensorStructInfo(Expr shape, DataType dtype, Optional< VDevice > vdevice=std::nullopt, Span span=Span())
Construction with a known shape expression.
TensorStructInfo(DataType dtype, int ndim, Optional< VDevice > vdevice=std::nullopt, Span span=Span())
Construction with an unknown shape expression.
TVM_DEFINE_OBJECT_REF_METHODS(TensorStructInfo, StructInfo, TensorStructInfoNode)
StructInfo of Tuple.
Definition: struct_info.h:226
static constexpr const char * _type_key
Definition: struct_info.h:236
static void RegisterReflection()
Definition: struct_info.h:231
TVM_DECLARE_FINAL_OBJECT_INFO(TupleStructInfoNode, StructInfoNode)
Array< StructInfo > fields
The struct info of tuple fields.
Definition: struct_info.h:229
Managed reference to TupleStructInfoNode.
Definition: struct_info.h:244
TupleStructInfo(Array< StructInfo > fields, Span span=Span())
Constructor.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TupleStructInfo, StructInfo, TupleStructInfoNode)
Runtime primitive data type.
Definition: data_type.h:47
bool is_void() const
Definition: data_type.h:209
Serializable global function used in IR.
Definition: repr_printer.h:91
const T * GetStructInfoAs(const Expr &expr)
Get the structure info of a given expr and try to cast it as const T*.
Definition: struct_info.h:389
Optional< T > MatchStructInfo(const Expr &expr)
Match and check if expr have StructInfo T and return it.
Definition: struct_info.h:372
void UpdateStructInfo(Expr expr, StructInfo struct_info)
Update the struct info of an Expr.
StructInfo GetStructInfo(const Expr &expr)
Get the underlying structure info of expr.
Definition: struct_info.h:401
bool HasVoidStructInfo(const Expr &expr)
Whether the expr has void struct info.
Definition: struct_info.h:413
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:1945
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
Definitions and helper macros for IR/AST nodes.
A map from source names to source code.