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  }
52 };
53 
54 class ShapeType : public Type {
55  public:
56  // TODO(relax-team): remove the default value later.
57  TVM_DLL ShapeType(int ndim = kUnknownNDim, Span span = Span());
58 
60 };
61 
67 class TensorTypeNode : public TypeNode {
68  public:
73  int ndim;
76 
77  static void RegisterReflection() {
78  namespace refl = tvm::ffi::reflection;
79  refl::ObjectDef<TensorTypeNode>()
80  .def_ro("ndim", &TensorTypeNode::ndim)
81  .def_ro("dtype", &TensorTypeNode::dtype);
82  }
83 
84  inline bool IsUnknownNdim() const { return ndim == kUnknownNDim; }
85 
86  inline bool IsUnknownDtype() const { return dtype.is_void(); }
88 };
89 
94 class TensorType : public Type {
95  public:
102  TVM_DLL TensorType(int ndim, DataType dtype, Span span = Span());
103 
107  TVM_DLL static TensorType CreateUnknownNDim(DataType dtype, Span span = Span());
108 
110 };
111 
114 
115 class ObjectTypeNode : public TypeNode {
116  public:
117  static void RegisterReflection() {
118  namespace refl = tvm::ffi::reflection;
119  refl::ObjectDef<ObjectTypeNode>();
120  }
122 };
123 
124 class ObjectType : public Type {
125  public:
126  TVM_DLL ObjectType(Span span = Span());
127 
129 };
130 
131 class PackedFuncTypeNode : public TypeNode {
132  public:
133  static void RegisterReflection() {
134  namespace refl = tvm::ffi::reflection;
135  refl::ObjectDef<PackedFuncTypeNode>();
136  }
138 };
139 
140 class PackedFuncType : public Type {
141  public:
142  TVM_DLL PackedFuncType(Span span = Span());
143 
145 };
146 
147 } // namespace relax
148 } // namespace tvm
149 #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:75
Managed reference to TypeNode.
Definition: type.h:100
Definition: type.h:115
static void RegisterReflection()
Definition: type.h:117
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.ObjectType", ObjectTypeNode, TypeNode)
Definition: type.h:124
ObjectType(Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ObjectType, Type, ObjectTypeNode)
Definition: type.h:131
static void RegisterReflection()
Definition: type.h:133
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.PackedFuncType", PackedFuncTypeNode, TypeNode)
Definition: type.h:140
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=kUnknownNDim, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeType, Type, ShapeTypeNode)
Dynamic version of TensorType.
Definition: type.h:67
bool IsUnknownDtype() const
Definition: type.h:86
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.DynTensorType", TensorTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:77
bool IsUnknownNdim() const
Definition: type.h:84
int ndim
The number of dimensions of the tensor, use -1 to denote tensor with unknown number of dimensions.
Definition: type.h:73
DataType dtype
The content data type, use void to denote the dtype is unknown.
Definition: type.h:75
Managed reference to TensorTypeNode.
Definition: type.h:94
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: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:113
TensorTypeNode TensorTypeNode
Definition: type.h:112
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
TIR expressions.