tvm
function.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_RELAY_FUNCTION_H_
25 #define TVM_RELAY_FUNCTION_H_
26 
27 #include <tvm/ir/function.h>
28 #include <tvm/relay/expr.h>
29 
30 #include <string>
31 
32 namespace tvm {
33 namespace relay {
34 
39 class FunctionNode : public BaseFuncNode {
40  public:
60 
62  v->Visit("params", &params);
63  v->Visit("body", &body);
64  v->Visit("ret_type", &ret_type);
65  v->Visit("type_params", &type_params);
66  v->Visit("attrs", &attrs);
67  v->Visit("span", &span);
68  v->Visit("_checked_type_", &checked_type_);
69  }
70 
71  bool SEqualReduce(const FunctionNode* other, SEqualReducer equal) const {
72  // Important to make def equal first.
73  equal->MarkGraphNode();
74  return equal.DefEqual(params, other->params) &&
75  equal.DefEqual(type_params, other->type_params) && equal(ret_type, other->ret_type) &&
76  equal(attrs, other->attrs) && equal(body, other->body);
77  }
78 
79  void SHashReduce(SHashReducer hash_reduce) const {
80  hash_reduce->MarkGraphNode();
81  hash_reduce.DefHash(params);
82  hash_reduce.DefHash(type_params);
83  hash_reduce(ret_type);
84  hash_reduce(attrs);
85  hash_reduce(body);
86  }
87 
94  TVM_DLL FuncType func_type_annotation() const;
95 
96  static constexpr const char* _type_key = "relay.Function";
98 };
99 
104 class Function : public BaseFunc {
105  public:
116  tvm::DictAttrs attrs = NullValue<DictAttrs>(), Span span = Span());
117 
120 };
121 
125 namespace attr {
127 constexpr const char* kPrimitive = "Primitive";
132 constexpr const char* kCompiler = "Compiler";
134 constexpr const char* kClosure = "Closure";
136 constexpr const char* kParams = "__params__";
138 constexpr const char* kExternalSymbol = "ExternalSymbol";
140 constexpr const char* kSkipOptimization = "SkipOptimization";
142 constexpr const char* kComposite = "Composite";
144 constexpr const char* kInline = "Inline";
146 constexpr const char* kPartitionedFromPattern = "PartitionedFromPattern";
148 constexpr const char* kReshapeOnly = "relay.reshape_only";
149 } // namespace attr
150 
151 } // namespace relay
152 } // namespace tvm
153 #endif // TVM_RELAY_FUNCTION_H_
tvm::Span Span
Definition: base.h:65
FuncType func_type_annotation() const
Return the derived function annotation of this expression.
DictAttrs attrs
Additional attributes storing the meta-data.
Definition: function.h:80
Function nodes.
bool DefEqual(const ObjectRef &lhs, const ObjectRef &rhs)
Reduce condition to comparison of two definitions, where free vars can be mapped. ...
Definition: structural_equal.h:165
static constexpr const char * _type_key
Definition: function.h:96
constexpr const char * kPrimitive
Mark the function as a primitive function.
Definition: function.h:127
Managed reference to FunctionNode.
Definition: function.h:104
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:102
constexpr const char * kParams
Store a Var to parameter/Constant mapping on a Function.
Definition: function.h:136
Relay expression language.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:101
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
void VisitAttrs(tvm::AttrVisitor *v)
Definition: function.h:61
Managed reference to DictAttrsNode.
Definition: attrs.h:227
TVM_DECLARE_FINAL_OBJECT_INFO(FunctionNode, BaseFuncNode)
virtual void MarkGraphNode()=0
Mark current comparison as graph node equal comparison.
constexpr const char * kSkipOptimization
Mark if the function should be avoided being optimized.
Definition: function.h:140
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
Definition: span.h:115
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:52
virtual void MarkGraphNode()=0
Mark current comparison as graph node in hashing. Graph node hash will depends on the graph structure...
Type checked_type_
Stores the result of type inference(type checking).
Definition: expr.h:150
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
Relay Function container.
Definition: function.h:39
constexpr const char * kPartitionedFromPattern
Indicate the function was created by the Pattern Partitioning Pass.
Definition: function.h:146
Managed reference to RelayExprNode.
Definition: expr.h:177
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:706
tvm::Array< Var > params
Function parameters.
Definition: function.h:42
constexpr const char * kReshapeOnly
Mark the function as only composed of reshape operations.
Definition: function.h:148
#define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName)
Define CopyOnWrite function in an ObjectRef.
Definition: object.h:778
Managed reference to FuncTypeNode.
Definition: type.h:461
constexpr const char * kComposite
Treat the function as a composite operator.
Definition: function.h:142
constexpr const char * kInline
Mark the function to be inlined.
Definition: function.h:144
constexpr const char * kExternalSymbol
Store the unique external symbol for external compilers.
Definition: function.h:138
Base node of all functions.
Definition: function.h:77
constexpr const char * kCompiler
Indicate the compiler that should be used for building this function. When this is unset or set to "d...
Definition: function.h:132
Managed reference to BaseFuncNode.
Definition: function.h:143
Managed reference to TypeNode.
Definition: type.h:93
constexpr const char * kClosure
Indicate if the function is a closure.
Definition: function.h:134
tvm::Array< TypeVar > type_params
Type parameters of the function. Enables the function to vary its type based on these. This corresponds to template paramaters in c++&#39;s terminology.
Definition: function.h:59
void SHashReduce(SHashReducer hash_reduce) const
Definition: function.h:79
Expr body
The expression which represents the computation of the function, the expression may reference the par...
Definition: function.h:49
bool SEqualReduce(const FunctionNode *other, SEqualReducer equal) const
Definition: function.h:71
Type ret_type
User annotated return type of the function.
Definition: function.h:51
void DefHash(const ObjectRef &key) const
Push hash of key to the current sequence of hash values.
Definition: structural_hash.h:178