tvm
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/ffi/function.h>
28 #include <tvm/ffi/reflection/registry.h>
29 #include <tvm/ir/attrs.h>
30 #include <tvm/ir/env_func.h>
31 #include <tvm/ir/type.h>
32 #include <tvm/tir/expr.h>
33 
34 #include <string>
35 
36 namespace tvm {
37 namespace relax {
38 
40 static constexpr int kUnknownNDim = -1;
41 
42 class ShapeTypeNode : public TypeNode {
43  public:
45  int ndim;
46 
47  static void RegisterReflection() {
48  namespace refl = tvm::ffi::reflection;
49  refl::ObjectDef<ShapeTypeNode>().def_ro("ndim", &ShapeTypeNode::ndim);
50  }
51 
52  static constexpr const char* _type_key = "relax.ShapeType";
54 };
55 
56 class ShapeType : public Type {
57  public:
58  // TODO(relax-team): remove the default value later.
59  TVM_DLL ShapeType(int ndim = kUnknownNDim, Span span = Span());
60 
62 };
63 
69 class TensorTypeNode : public TypeNode {
70  public:
75  int ndim;
78 
79  static void RegisterReflection() {
80  namespace refl = tvm::ffi::reflection;
81  refl::ObjectDef<TensorTypeNode>()
82  .def_ro("ndim", &TensorTypeNode::ndim)
83  .def_ro("dtype", &TensorTypeNode::dtype);
84  }
85 
86  inline bool IsUnknownNdim() const { return ndim == kUnknownNDim; }
87 
88  inline bool IsUnknownDtype() const { return dtype.is_void(); }
89 
90  static constexpr const char* _type_key = "relax.DynTensorType";
92 };
93 
98 class TensorType : public Type {
99  public:
106  TVM_DLL TensorType(int ndim, DataType dtype, Span span = Span());
107 
111  TVM_DLL static TensorType CreateUnknownNDim(DataType dtype, Span span = Span());
112 
114 };
115 
118 
119 class ObjectTypeNode : public TypeNode {
120  public:
121  static void RegisterReflection() {
122  namespace refl = tvm::ffi::reflection;
123  refl::ObjectDef<ObjectTypeNode>();
124  }
125 
126  static constexpr const char* _type_key = "relax.ObjectType";
128 };
129 
130 class ObjectType : public Type {
131  public:
132  TVM_DLL ObjectType(Span span = Span());
133 
135 };
136 
137 class PackedFuncTypeNode : public TypeNode {
138  public:
139  static void RegisterReflection() {
140  namespace refl = tvm::ffi::reflection;
141  refl::ObjectDef<PackedFuncTypeNode>();
142  }
143 
144  static constexpr const char* _type_key = "relax.PackedFuncType";
146 };
147 
148 class PackedFuncType : public Type {
149  public:
150  TVM_DLL PackedFuncType(Span span = Span());
151 
153 };
154 
155 } // namespace relax
156 } // namespace tvm
157 #endif // TVM_RELAX_TYPE_H_
Helpers for attribute objects.
Definition: source_map.h:113
Type is the base type of all types.
Definition: type.h:75
Managed reference to TypeNode.
Definition: type.h:101
Definition: type.h:119
TVM_DECLARE_FINAL_OBJECT_INFO(ObjectTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:121
static constexpr const char * _type_key
Definition: type.h:126
Definition: type.h:130
ObjectType(Span span=Span())
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ObjectType, Type, ObjectTypeNode)
Definition: type.h:137
static constexpr const char * _type_key
Definition: type.h:144
TVM_DECLARE_FINAL_OBJECT_INFO(PackedFuncTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:139
Definition: type.h:148
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(PackedFuncType, Type, PackedFuncTypeNode)
PackedFuncType(Span span=Span())
Definition: type.h:42
int ndim
size of the shape.
Definition: type.h:45
TVM_DECLARE_FINAL_OBJECT_INFO(ShapeTypeNode, TypeNode)
static constexpr const char * _type_key
Definition: type.h:52
static void RegisterReflection()
Definition: type.h:47
Definition: type.h:56
ShapeType(int ndim=kUnknownNDim, Span span=Span())
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ShapeType, Type, ShapeTypeNode)
Dynamic version of TensorType.
Definition: type.h:69
static constexpr const char * _type_key
Definition: type.h:90
TVM_DECLARE_FINAL_OBJECT_INFO(TensorTypeNode, TypeNode)
bool IsUnknownDtype() const
Definition: type.h:88
static void RegisterReflection()
Definition: type.h:79
bool IsUnknownNdim() const
Definition: type.h:86
int ndim
The number of dimensions of the tensor, use -1 to denote tensor with unknown number of dimensions.
Definition: type.h:75
DataType dtype
The content data type, use void to denote the dtype is unknown.
Definition: type.h:77
Managed reference to TensorTypeNode.
Definition: type.h:98
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:47
bool is_void() const
Definition: data_type.h:209
Serializable global function used in IR.
IR/AST nodes for the unified type system in TVM.
Definition: repr_printer.h:91
TensorType TensorType
Definition: type.h:117
TensorTypeNode TensorTypeNode
Definition: type.h:116
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
TIR expressions.