tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
adt.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 
27 #ifndef TVM_IR_ADT_H_
28 #define TVM_IR_ADT_H_
29 
30 #include <tvm/ir/expr.h>
31 #include <tvm/ir/type.h>
32 #include <tvm/node/node.h>
36 #include <tvm/runtime/object.h>
37 
38 #include <string>
39 
40 namespace tvm {
41 
48  public:
56  mutable int32_t tag = -1;
57 
59 
61  v->Visit("name_hint", &name_hint);
62  v->Visit("inputs", &inputs);
63  v->Visit("belong_to", &belong_to);
64  v->Visit("tag", &tag);
65  v->Visit("span", &span);
66  v->Visit("_checked_type_", &checked_type_);
67  }
68 
69  bool SEqualReduce(const ConstructorNode* other, SEqualReducer equal) const {
70  // Use namehint for now to be consistent with the legacy relay impl
71  // TODO(tvm-team) revisit, need to check the type var.
72  return equal(name_hint, other->name_hint) && equal(inputs, other->inputs);
73  }
74 
75  void SHashReduce(SHashReducer hash_reduce) const {
76  hash_reduce(name_hint);
77  hash_reduce(inputs);
78  }
79 
80  static constexpr const char* _type_key = "relay.Constructor";
82 };
83 
88 class Constructor : public RelayExpr {
89  public:
97 
99 };
100 
102 class TypeDataNode : public TypeNode {
103  public:
115 
117  v->Visit("header", &header);
118  v->Visit("type_vars", &type_vars);
119  v->Visit("constructors", &constructors);
120  v->Visit("span", &span);
121  }
122 
123  bool SEqualReduce(const TypeDataNode* other, SEqualReducer equal) const {
124  return equal.DefEqual(header, other->header) && equal.DefEqual(type_vars, other->type_vars) &&
125  equal(constructors, other->constructors);
126  }
127 
128  void SHashReduce(SHashReducer hash_reduce) const {
129  hash_reduce.DefHash(header);
130  hash_reduce.DefHash(type_vars);
131  hash_reduce(constructors);
132  }
133 
134  static constexpr const char* _type_key = "relay.TypeData";
136 };
137 
149 class TypeData : public Type {
150  public:
157  TVM_DLL TypeData(GlobalTypeVar header, Array<TypeVar> type_vars, Array<Constructor> constructors);
158 
160 };
161 
162 } // namespace tvm
163 #endif // TVM_IR_ADT_H_
bool DefEqual(const ObjectRef &lhs, const ObjectRef &rhs)
Reduce condition to comparison of two definitions, where free vars can be mapped. ...
Definitions and helper macros for IR/AST nodes.
Runtime String container types.
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
Base expr nodes in TVM.
ADT constructor. Constructors compare by pointer equality.
Definition: adt.h:47
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:110
String name_hint
The name (only a hint)
Definition: adt.h:50
void SHashReduce(SHashReducer hash_reduce) const
Definition: adt.h:128
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
bool SEqualReduce(const ConstructorNode *other, SEqualReducer equal) const
Definition: adt.h:69
Managed reference to GlobalTypeVarNode.
Definition: type.h:332
Managed reference to ConstructorNode.
Definition: adt.h:88
Array< Type > inputs
Input to the constructor.
Definition: adt.h:52
Runtime Array container types.
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
static constexpr const char * _type_key
Definition: adt.h:80
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:55
IR/AST nodes for the unified type system in TVM.
Array< TypeVar > type_vars
The type variables (to allow for polymorphism).
Definition: adt.h:112
Array< Constructor > constructors
The constructors.
Definition: adt.h:114
Runtime ADT container types.
Type checked_type_
Stores the result of type inference(type checking).
Definition: expr.h:369
void VisitAttrs(AttrVisitor *v)
Definition: adt.h:116
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Type is the base type of all types.
Definition: type.h:74
TypeData container node.
Definition: adt.h:102
void VisitAttrs(AttrVisitor *v)
Definition: adt.h:60
Reference to string objects.
Definition: string.h:98
Managed reference to RelayExprNode.
Definition: expr.h:433
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
int32_t tag
Index in the table of constructors (set when the type is registered).
Definition: adt.h:56
TVM_DECLARE_FINAL_OBJECT_INFO(ConstructorNode, RelayExprNode)
void SHashReduce(SHashReducer hash_reduce) const
Definition: adt.h:75
tvm::Constructor Constructor
Definition: adt.h:40
ConstructorNode()
Definition: adt.h:58
GlobalTypeVar belong_to
The datatype the constructor will construct.
Definition: adt.h:54
A managed object in the TVM runtime.
GlobalTypeVar header
The header is simply the name of the ADT. We adopt nominal typing for ADT definitions; that is...
Definition: adt.h:110
bool SEqualReduce(const TypeDataNode *other, SEqualReducer equal) const
Definition: adt.h:123
Stores all data for an Algebraic Data Type (ADT).
Definition: adt.h:149
Managed reference to TypeNode.
Definition: type.h:93
tvm::TypeData TypeData
Definition: adt.h:43
Base node of all non-primitive expressions.
Definition: expr.h:361
void DefHash(const ObjectRef &key) const
Push hash of key to the current sequence of hash values.
Definition: structural_hash.h:187