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>
47 static constexpr
int kUnknownNDim = -1;
55 namespace refl = tvm::ffi::reflection;
56 refl::ObjectDef<PackedFuncTypeNode>();
98 namespace refl = tvm::ffi::reflection;
99 refl::ObjectDef<AnyTypeNode>();
125 ffi::Optional<ffi::Array<PrimExpr>>
values;
136 namespace refl = tvm::ffi::reflection;
137 refl::ObjectDef<ShapeTypeNode>()
181 ffi::Optional<tvm::PrimType>
dtype{std::nullopt};
195 ffi::Optional<ffi::Array<PrimExpr>>
GetShape()
const {
196 if (!
shape.has_value())
return {};
197 const Expr& shape_expr = this->shape.value();
198 if (shape_expr->ty.IsMissing())
return {};
199 if (
const auto* shape_ty = shape_expr->ty.as<
ShapeTypeNode>()) {
200 return shape_ty->values;
206 namespace refl = tvm::ffi::reflection;
207 refl::ObjectDef<TensorTypeNode>()
222 explicit TensorType(ffi::ObjectPtr<TensorTypeNode> data) :
Type(ffi::UnsafeInit{}) {
223 TVM_FFI_ICHECK(data !=
nullptr);
224 data_ = std::move(data);
237 ffi::Optional<VDevice> vdevice = std::nullopt,
Span span =
Span());
246 TVM_DLL
TensorType(ffi::Optional<tvm::PrimType> dtype,
int ndim,
247 ffi::Optional<VDevice> vdevice = std::nullopt,
Span span =
Span());
298 namespace refl = tvm::ffi::reflection;
299 refl::ObjectDef<FuncTypeNode>()
314 explicit FuncType(ffi::ObjectPtr<FuncTypeNode> data) :
Type(ffi::UnsafeInit{}) {
315 TVM_FFI_ICHECK(data !=
nullptr);
316 data_ = std::move(data);
367 template <
typename T>
369 if (!expr.defined()) {
372 using TNode =
typename T::ContainerType;
373 if (
const TNode* ptr = expr->ty.as<TNode>()) {
374 return ffi::GetRef<T>(ptr);
387 template <
typename T>
389 TVM_FFI_ICHECK(!expr->ty.IsMissing())
390 <<
"The type is not populated, check if you have normalized the expr";
391 return expr->ty.as<T>();
401 TVM_FFI_ICHECK(!expr->ty.IsMissing())
402 <<
"The type is not populated, check if you have normalized the expr";
414 return ptr !=
nullptr && ptr->
fields.size() == 0;
Helpers for attribute objects.
Managed reference to CallNode.
Definition: expr.h:348
Base type of all the expressions.
Definition: base_expr.h:276
Managed reference to ExprNode.
Definition: base_expr.h:311
Definition: source_map.h:111
The type of tuple values.
Definition: type.h:90
ffi::Array< Type > fields
The type of each field in the tuple.
Definition: type.h:93
Managed reference to TupleTypeNode.
Definition: type.h:108
Type is the base type of all types.
Definition: base_expr.h:52
Managed reference to TypeNode.
Definition: base_expr.h:77
static Type Missing()
Sentinel for a type that has not been populated yet.
Please refer to TypedEnvFunc<R(Args..)>.
Definition: env_func.h:105
Base type of all Relax type information.
Definition: type.h:95
static void RegisterReflection()
Definition: type.h:97
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.AnyType", AnyTypeNode, TypeNode)
Managed reference to AnyTypeNode.
Definition: type.h:108
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AnyType, Type, AnyTypeNode)
AnyType(Span span=Span())
Definition: block_builder.h:257
Function type information.
Definition: type.h:266
Type ret
The type of the function's return value.
Definition: type.h:277
bool IsOpaque() const
Definition: type.h:295
bool purity
Whether the function is pure.
Definition: type.h:289
ffi::Optional< ffi::Array< Type > > params
The parameter type of the function.
Definition: type.h:273
static void RegisterReflection()
Definition: type.h:297
ffi::Optional< TypeDeriveFunc > derive_func
Derivation function of opaque functions that may take any number of parameters.
Definition: type.h:283
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.FuncType", FuncTypeNode, TypeNode)
Managed reference to FuncTypeNode.
Definition: type.h:312
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FuncType, Type, FuncTypeNode)
static FuncType OpaqueFunc(Type ret=AnyType(), bool purity=false, Span span=Span())
Construct an opaque function using from return type.
static FuncType OpaqueFunc(TypeDeriveFunc derive_func, bool purity=false, Span span=Span())
Constructing an opaque function type using derive_func.
FuncType(ffi::ObjectPtr< FuncTypeNode > data)
Definition: type.h:314
FuncType(ffi::Array< Type > params, Type ret, bool purity=true, Span span=Span())
Constructor from parameter type and return value type.
static void RegisterReflection()
Definition: type.h:54
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.PackedFuncType", PackedFuncTypeNode, TypeNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PackedFuncType, Type, PackedFuncTypeNode)
PackedFuncType(Span span=Span())
Type of shape value.
Definition: type.h:122
int ndim
The number of dimension of the shape, can be unknown.
Definition: type.h:130
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:125
static void RegisterReflection()
Definition: type.h:135
bool IsUnknownNdim() const
Definition: type.h:133
Managed reference to ShapeTypeNode.
Definition: type.h:148
ShapeType(int ndim, Span span=Span())
Construction with known unknown symbolic shape patterns.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeType, Type, ShapeTypeNode)
ShapeType(ffi::Array< PrimExpr > values, Span span=Span())
Construction with known symbolic shape patterns.
Type of Tensor.
Definition: type.h:169
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.TensorType", TensorTypeNode, TypeNode)
bool IsUnknownDtype() const
Definition: type.h:192
ffi::Optional< VDevice > vdevice
The virtual device, indicates where the tensor is expected to be executed.
Definition: type.h:179
ffi::Optional< ffi::Array< PrimExpr > > GetShape() const
Definition: type.h:195
ffi::Optional< tvm::PrimType > dtype
The content dtype, or nullopt if the dtype is unknown.
Definition: type.h:181
static void RegisterReflection()
Definition: type.h:205
bool IsUnknownNdim() const
Definition: type.h:189
ffi::Optional< Expr > shape
optionally store the shape expression of the tensor.
Definition: type.h:175
int ndim
The number of dimension of the tensor, can be unknown.
Definition: type.h:186
Managed reference to TensorTypeNode.
Definition: type.h:220
TensorType(ffi::Optional< tvm::PrimType > dtype, int ndim, ffi::Optional< VDevice > vdevice=std::nullopt, Span span=Span())
Construction with an unknown shape expression.
TensorType(Expr shape, ffi::Optional< tvm::PrimType > dtype=std::nullopt, ffi::Optional< VDevice > vdevice=std::nullopt, Span span=Span())
Construction with a known shape expression.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorType, Type, TensorTypeNode)
TensorType(ffi::ObjectPtr< TensorTypeNode > data)
Definition: type.h:222
Serializable global function used in IR.
GlobalInfo are globally static object that are referred by the IR itself.
IR/AST nodes for TVM types shared across IR variants.
bool HasVoidType(const Expr &expr)
Whether the expr has void type.
Definition: type.h:412
const T * GetTypeAs(const Expr &expr)
Get the type of a given expr and try to cast it as const T*.
Definition: type.h:388
void UpdateType(Expr expr, Type ty)
Update the type of an Expr.
tvm::ExprNode ExprNode
Definition: type.h:42
Type GetType(const Expr &expr)
Get the underlying Relax type of expr.
Definition: type.h:400
tvm::Expr Expr
Definition: type.h:41
ffi::Optional< T > MatchType(const Expr &expr)
Match and check if expr has Relax type T and return it.
Definition: type.h:368
Tensor shape(const Tensor &src, PrimType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:2010
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.