24#ifndef TVM_RELAX_TYPE_H_
25#define TVM_RELAX_TYPE_H_
27#include <tvm/ffi/function.h>
28#include <tvm/ffi/reflection/registry.h>
47static constexpr int kUnknownNDim = -1;
61 namespace refl = tvm::ffi::reflection;
62 refl::ObjectDef<PackedFuncTypeNode>();
105 ffi::Optional<ffi::Array<PrimExpr>>
values;
116 namespace refl = tvm::ffi::reflection;
117 refl::ObjectDef<ShapeTypeNode>()
161 ffi::Optional<tvm::PrimType>
dtype{std::nullopt};
175 ffi::Optional<ffi::Array<PrimExpr>>
GetShape()
const {
176 if (!
shape.has_value())
return {};
177 const Expr& shape_expr = this->shape.value();
178 if (shape_expr->ty.as<
MissingType>().has_value())
return {};
179 if (
const auto* shape_ty = shape_expr->ty.as<
ShapeTypeNode>()) {
180 return shape_ty->values;
186 namespace refl = tvm::ffi::reflection;
187 refl::ObjectDef<TensorTypeNode>()
202 explicit TensorType(ffi::ObjectPtr<TensorTypeNode> data) :
Type(ffi::UnsafeInit{}) {
203 TVM_FFI_ICHECK(data !=
nullptr);
204 data_ = std::move(data);
216 TVM_DLL
TensorType(
Expr shape, ffi::Optional<tvm::PrimType> dtype = std::nullopt,
226 TVM_DLL
TensorType(ffi::Optional<tvm::PrimType> dtype,
int ndim,
278 namespace refl = tvm::ffi::reflection;
279 refl::ObjectDef<FuncTypeNode>()
294 explicit FuncType(ffi::ObjectPtr<FuncTypeNode> data) :
Type(ffi::UnsafeInit{}) {
295 TVM_FFI_ICHECK(data !=
nullptr);
296 data_ = std::move(data);
308 TVM_DLL
FuncType(ffi::Array<Type> params,
Type ret,
bool purity =
true,
351 if (!expr.defined()) {
354 using TNode =
typename T::ContainerType;
355 if (
const TNode* ptr = expr->ty.as<TNode>()) {
356 return ffi::GetRef<T>(ptr);
371 TVM_FFI_ICHECK(!expr->ty.as<
MissingType>().has_value())
372 <<
"The type is not populated, check if you have normalized the expr";
373 return expr->ty.as<T>();
383 TVM_FFI_ICHECK(!expr->ty.as<
MissingType>().has_value())
384 <<
"The type is not populated, check if you have normalized the expr";
396 return ptr !=
nullptr && ptr->
fields.size() == 0;
Helpers for attribute objects.
The top type, which admits any value.
Definition type.h:43
Managed reference to AnyTypeNode.
Definition type.h:53
Managed reference to CallNode.
Definition expr.h:972
Base type of all the expressions.
Definition base_expr.h:324
Managed reference to ExprNode.
Definition base_expr.h:359
Non-nullable source-location metadata.
Definition location.h:91
Managed reference to the MissingTypeNode singleton.
Definition base_expr.h:105
The type of tuple values.
Definition type.h:146
ffi::Array< Type > fields
The type of each field in the tuple.
Definition type.h:149
Managed reference to TupleTypeNode.
Definition type.h:164
Type is the base type of all types.
Definition base_expr.h:54
Managed reference to TypeNode.
Definition base_expr.h:80
static TVM_TIRX_DLL Type Missing()
Construct a MissingType for type information not yet populated.
Please refer to TypedEnvFunc<R(Args..)>.
Definition env_func.h:107
Reference to the shared immutable unknown location.
Definition location.h:105
Definition block_builder.h:257
Function type information.
Definition type.h:246
Type ret
The type of the function's return value.
Definition type.h:257
bool IsOpaque() const
Definition type.h:275
bool purity
Whether the function is pure.
Definition type.h:269
ffi::Optional< ffi::Array< Type > > params
The parameter type of the function.
Definition type.h:253
static void RegisterReflection()
Definition type.h:277
ffi::Optional< TypeDeriveFunc > derive_func
Derivation function of opaque functions that may take any number of parameters.
Definition type.h:263
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.FuncType", FuncTypeNode, TypeNode)
Managed reference to FuncTypeNode.
Definition type.h:292
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FuncType, Type, FuncTypeNode)
static FuncType OpaqueFunc(TypeDeriveFunc derive_func, bool purity=false, Location loc=UnknownLoc())
Constructing an opaque function type using derive_func.
FuncType(ffi::Array< Type > params, Type ret, bool purity=true, Location loc=UnknownLoc())
Constructor from parameter type and return value type.
FuncType(ffi::ObjectPtr< FuncTypeNode > data)
Definition type.h:294
static FuncType OpaqueFunc(Type ret=AnyType(), bool purity=false, Location loc=UnknownLoc())
Construct an opaque function using from return type.
static void RegisterReflection()
Definition type.h:60
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.PackedFuncType", PackedFuncTypeNode, TypeNode)
PackedFuncType(Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PackedFuncType, Type, PackedFuncTypeNode)
Base type of all Relax type information.
Definition type.h:102
int ndim
The number of dimension of the shape, can be unknown.
Definition type.h:110
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.ShapeType", ShapeTypeNode, TypeNode)
ffi::Optional< ffi::Array< PrimExpr > > values
optionally stores the symbolic value patterns of the shape
Definition type.h:105
static void RegisterReflection()
Definition type.h:115
bool IsUnknownNdim() const
Definition type.h:113
Managed reference to ShapeTypeNode.
Definition type.h:128
ShapeType(int ndim, Location loc=UnknownLoc())
Construction with known unknown symbolic shape patterns.
ShapeType(ffi::Array< PrimExpr > values, Location loc=UnknownLoc())
Construction with known symbolic shape patterns.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeType, Type, ShapeTypeNode)
Type of Tensor.
Definition type.h:149
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.TensorType", TensorTypeNode, TypeNode)
bool IsUnknownDtype() const
Definition type.h:172
ffi::Optional< ffi::Array< PrimExpr > > GetShape() const
Definition type.h:175
ffi::Optional< VDevice > vdevice
The virtual device, indicates where the tensor is expected to be executed.
Definition type.h:159
ffi::Optional< tvm::PrimType > dtype
The content dtype, or nullopt if the dtype is unknown.
Definition type.h:161
static void RegisterReflection()
Definition type.h:185
bool IsUnknownNdim() const
Definition type.h:169
ffi::Optional< Expr > shape
optionally store the shape expression of the tensor.
Definition type.h:155
int ndim
The number of dimension of the tensor, can be unknown.
Definition type.h:166
Managed reference to TensorTypeNode.
Definition type.h:200
TensorType(ffi::Optional< tvm::PrimType > dtype, int ndim, ffi::Optional< VDevice > vdevice=std::nullopt, Location loc=UnknownLoc())
Construction with an unknown shape expression.
TensorType(Expr shape, ffi::Optional< tvm::PrimType > dtype=std::nullopt, ffi::Optional< VDevice > vdevice=std::nullopt, Location loc=UnknownLoc())
Construction with a known shape expression.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorType, Type, TensorTypeNode)
TensorType(ffi::ObjectPtr< TensorTypeNode > data)
Definition type.h:202
Serializable global function used in IR.
IR/AST nodes for TVM types shared across IR variants.
bool HasVoidType(const Expr &expr)
Whether the expr has void type.
Definition type.h:394
void UpdateType(Expr expr, Type ty)
Update the type of an Expr.
Type GetType(const Expr &expr)
Get the underlying Relax type of expr.
Definition type.h:382
const T * GetTypeAs(const Expr &expr)
Get the type of a given expr and try to cast it as const T*.
Definition type.h:370
ffi::Optional< T > MatchType(const Expr &expr)
Match and check if expr has Relax type T and return it.
Definition type.h:350
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
Global information used by Relax.