tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
type.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_RELAX_TYPE_H_
25 #define TVM_RELAX_TYPE_H_
26 
27 #include <tvm/ir/attrs.h>
28 #include <tvm/ir/env_func.h>
29 #include <tvm/ir/type.h>
30 #include <tvm/runtime/registry.h>
31 #include <tvm/tir/expr.h>
32 
33 #include <string>
34 
35 namespace tvm {
36 namespace relax {
37 
39 static constexpr int kUnknownNDim = -1;
40 
41 class ShapeTypeNode : public TypeNode {
42  public:
44  int ndim;
45 
47  v->Visit("ndim", &ndim);
48  v->Visit("span", &span);
49  }
50 
51  bool SEqualReduce(const ShapeTypeNode* other, SEqualReducer equal) const {
52  return equal(ndim, other->ndim);
53  }
54 
55  void SHashReduce(SHashReducer hash_reduce) const { hash_reduce(ndim); }
56 
57  static constexpr const char* _type_key = "relax.ShapeType";
59 };
60 
61 class ShapeType : public Type {
62  public:
63  // TODO(relax-team): remove the default value later.
64  TVM_DLL ShapeType(int ndim = kUnknownNDim, Span span = Span());
65 
67 };
68 
74 class TensorTypeNode : public TypeNode {
75  public:
80  int ndim;
83 
85  v->Visit("ndim", &ndim);
86  v->Visit("dtype", &dtype);
87  v->Visit("span", &span);
88  }
89 
90  bool SEqualReduce(const TensorTypeNode* other, SEqualReducer equal) const {
91  return equal(ndim, other->ndim) && equal(dtype, other->dtype);
92  }
93 
94  void SHashReduce(SHashReducer hash_reduce) const {
95  hash_reduce(ndim);
96  hash_reduce(dtype);
97  }
98 
99  inline bool IsUnknownNdim() const { return ndim == kUnknownNDim; }
100 
101  inline bool IsUnknownDtype() const { return dtype.is_void(); }
102 
103  static constexpr const char* _type_key = "relax.DynTensorType";
105 };
106 
111 class TensorType : public Type {
112  public:
119  TVM_DLL TensorType(int ndim, DataType dtype, Span span = Span());
120 
124  TVM_DLL static TensorType CreateUnknownNDim(DataType dtype, Span span = Span());
125 
127 };
128 
131 
132 class ObjectTypeNode : public TypeNode {
133  public:
134  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("span", &span); }
135 
136  bool SEqualReduce(const ObjectTypeNode* other, SEqualReducer equal) const { return true; }
137 
138  void SHashReduce(SHashReducer hash_reduce) const { hash_reduce(0); }
139 
140  static constexpr const char* _type_key = "relax.ObjectType";
142 };
143 
144 class ObjectType : public Type {
145  public:
146  TVM_DLL ObjectType(Span span = Span());
147 
149 };
150 
151 class PackedFuncTypeNode : public TypeNode {
152  public:
153  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("span", &span); }
154 
155  bool SEqualReduce(const PackedFuncTypeNode* other, SEqualReducer equal) const { return true; }
156 
157  void SHashReduce(SHashReducer hash_reduce) const { hash_reduce(0); }
158 
159  static constexpr const char* _type_key = "relax.PackedFuncType";
161 };
162 
163 class PackedFuncType : public Type {
164  public:
165  TVM_DLL PackedFuncType(Span span = Span());
166 
168 };
169 
170 } // namespace relax
171 } // namespace tvm
172 #endif // TVM_RELAX_TYPE_H_
Helpers for attribute objects.
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
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:135
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:121
Definition: source_map.h:120
Type is the base type of all types.
Definition: type.h:74
Span span
Span that points to the original source code. Reserved debug information.
Definition: type.h:80
Managed reference to TypeNode.
Definition: type.h:93
Definition: type.h:132
bool SEqualReduce(const ObjectTypeNode *other, SEqualReducer equal) const
Definition: type.h:136
void SHashReduce(SHashReducer hash_reduce) const
Definition: type.h:138
TVM_DECLARE_FINAL_OBJECT_INFO(ObjectTypeNode, TypeNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: type.h:134
static constexpr const char * _type_key
Definition: type.h:140
Definition: type.h:144
ObjectType(Span span=Span())
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ObjectType, Type, ObjectTypeNode)
Definition: type.h:151
void SHashReduce(SHashReducer hash_reduce) const
Definition: type.h:157
bool SEqualReduce(const PackedFuncTypeNode *other, SEqualReducer equal) const
Definition: type.h:155
static constexpr const char * _type_key
Definition: type.h:159
TVM_DECLARE_FINAL_OBJECT_INFO(PackedFuncTypeNode, TypeNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: type.h:153
Definition: type.h:163
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(PackedFuncType, Type, PackedFuncTypeNode)
PackedFuncType(Span span=Span())
Definition: type.h:41
int ndim
size of the shape.
Definition: type.h:44
void SHashReduce(SHashReducer hash_reduce) const
Definition: type.h:55
TVM_DECLARE_FINAL_OBJECT_INFO(ShapeTypeNode, TypeNode)
static constexpr const char * _type_key
Definition: type.h:57
void VisitAttrs(tvm::AttrVisitor *v)
Definition: type.h:46
bool SEqualReduce(const ShapeTypeNode *other, SEqualReducer equal) const
Definition: type.h:51
Definition: type.h:61
ShapeType(int ndim=kUnknownNDim, Span span=Span())
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ShapeType, Type, ShapeTypeNode)
Dynamic version of TensorType.
Definition: type.h:74
static constexpr const char * _type_key
Definition: type.h:103
void SHashReduce(SHashReducer hash_reduce) const
Definition: type.h:94
TVM_DECLARE_FINAL_OBJECT_INFO(TensorTypeNode, TypeNode)
bool IsUnknownDtype() const
Definition: type.h:101
bool SEqualReduce(const TensorTypeNode *other, SEqualReducer equal) const
Definition: type.h:90
void VisitAttrs(tvm::AttrVisitor *v)
Definition: type.h:84
bool IsUnknownNdim() const
Definition: type.h:99
int ndim
The number of dimensions of the tensor, use -1 to denote tensor with unknown number of dimensions.
Definition: type.h:80
DataType dtype
The content data type, use void to denote the dtype is unknown.
Definition: type.h:82
Managed reference to TensorTypeNode.
Definition: type.h:111
TensorType(int ndim, DataType dtype, Span span=Span())
Constructor.
TVM_DEFINE_OBJECT_REF_METHODS(TensorType, Type, TensorTypeNode)
static TensorType CreateUnknownNDim(DataType dtype, Span span=Span())
Create a TensorType with unknown ndim.
Runtime primitive data type.
Definition: data_type.h:43
bool is_void() const
Definition: data_type.h:164
Serializable global function used in IR.
IR/AST nodes for the unified type system in TVM.
TensorType TensorType
Definition: type.h:130
TensorTypeNode TensorTypeNode
Definition: type.h:129
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
This file defines the TVM global function registry.
TIR expressions.