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/tirx/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  }
52 };
53 
54 class ShapeType : public Type {
55  public:
56  TVM_DLL ShapeType(int ndim, Span span = Span());
57 
59 };
60 
66 class TensorTypeNode : public TypeNode {
67  public:
72  int ndim;
75 
76  static void RegisterReflection() {
77  namespace refl = tvm::ffi::reflection;
78  refl::ObjectDef<TensorTypeNode>()
79  .def_ro("ndim", &TensorTypeNode::ndim)
80  .def_ro("dtype", &TensorTypeNode::dtype);
81  }
82 
83  inline bool IsUnknownNdim() const { return ndim == kUnknownNDim; }
84 
85  inline bool IsUnknownDtype() const { return dtype.is_void(); }
87 };
88 
93 class TensorType : public Type {
94  public:
101  TVM_DLL TensorType(int ndim, DataType dtype, Span span = Span());
102 
106  TVM_DLL static TensorType CreateUnknownNDim(DataType dtype, Span span = Span());
107 
109 };
110 
113 
114 class ObjectTypeNode : public TypeNode {
115  public:
116  static void RegisterReflection() {
117  namespace refl = tvm::ffi::reflection;
118  refl::ObjectDef<ObjectTypeNode>();
119  }
121 };
122 
123 class ObjectType : public Type {
124  public:
125  TVM_DLL ObjectType(Span span = Span());
126 
128 };
129 
130 class PackedFuncTypeNode : public TypeNode {
131  public:
132  static void RegisterReflection() {
133  namespace refl = tvm::ffi::reflection;
134  refl::ObjectDef<PackedFuncTypeNode>();
135  }
137 };
138 
139 class PackedFuncType : public Type {
140  public:
141  TVM_DLL PackedFuncType(Span span = Span());
142 
144 };
145 
146 } // namespace relax
147 } // namespace tvm
148 #endif // TVM_RELAX_TYPE_H_
Helpers for attribute objects.
Definition: source_map.h:111
Type is the base type of all types.
Definition: type.h:74
Managed reference to TypeNode.
Definition: type.h:99
Definition: type.h:114
static void RegisterReflection()
Definition: type.h:116
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.ObjectType", ObjectTypeNode, TypeNode)
Definition: type.h:123
ObjectType(Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ObjectType, Type, ObjectTypeNode)
Definition: type.h:130
static void RegisterReflection()
Definition: type.h:132
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.PackedFuncType", PackedFuncTypeNode, TypeNode)
Definition: type.h:139
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PackedFuncType, Type, PackedFuncTypeNode)
PackedFuncType(Span span=Span())
Definition: type.h:42
int ndim
size of the shape.
Definition: type.h:45
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.ShapeType", ShapeTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:47
Definition: type.h:54
ShapeType(int ndim, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeType, Type, ShapeTypeNode)
Dynamic version of TensorType.
Definition: type.h:66
bool IsUnknownDtype() const
Definition: type.h:85
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.DynTensorType", TensorTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:76
bool IsUnknownNdim() const
Definition: type.h:83
int ndim
The number of dimensions of the tensor, use -1 to denote tensor with unknown number of dimensions.
Definition: type.h:72
DataType dtype
The content data type, use void to denote the dtype is unknown.
Definition: type.h:74
Managed reference to TensorTypeNode.
Definition: type.h:93
TensorType(int ndim, DataType dtype, Span span=Span())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(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:213
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:112
TensorTypeNode TensorTypeNode
Definition: type.h:111
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
TIR expressions.