tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
op_strategy.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 
25 #ifndef TVM_RELAY_OP_STRATEGY_H_
26 #define TVM_RELAY_OP_STRATEGY_H_
27 
28 #include <tvm/relay/expr.h>
30 #include <tvm/target/target.h>
31 #include <tvm/te/schedule.h>
32 #include <tvm/te/tensor.h>
33 
34 #include <string>
35 
36 namespace tvm {
37 namespace relay {
38 
42 class OpImplementationNode : public Object {
43  public:
51  int plevel;
52 
54  v->Visit("name", &name);
55  v->Visit("plevel", &plevel);
56  }
57 
58  static constexpr const char* _type_key = "relay.OpImplementation";
60 };
61 
65 class OpImplementation : public ObjectRef {
66  public:
74  TVM_DLL Array<te::Tensor> Compute(const Attrs& attrs, const Array<te::Tensor>& inputs,
75  const Type& out_type);
83  TVM_DLL te::Schedule Schedule(const Attrs& attrs, const Array<te::Tensor>& outs,
84  const Target& target);
85 
87 };
88 
92 class OpSpecializationNode : public Object {
93  public:
99 
101  v->Visit("condition", &condition);
102  v->Visit("implementations", &implementations);
103  }
104 
105  static constexpr const char* _type_key = "relay.OpSpecialization";
107 };
108 
112 class OpSpecialization : public ObjectRef {
113  public:
121  TVM_DLL void AddImplementation(FTVMCompute fcompute, FTVMSchedule fschedule, String name,
122  int plevel);
123 
125 };
126 
130 class OpStrategyNode : public Object {
131  public:
134 
135  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("specializations", &specializations); }
136 
137  static constexpr const char* _type_key = "relay.OpStrategy";
139 };
140 
144 class OpStrategy : public ObjectRef {
145  public:
153  TVM_DLL void AddImplementation(FTVMCompute fcompute, FTVMSchedule fschedule, String name,
154  int plevel);
155 
157 };
158 
159 } // namespace relay
160 } // namespace tvm
161 #endif // TVM_RELAY_OP_STRATEGY_H_
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
Managed reference to BaseAttrsNode.
Definition: attrs.h:190
Base node of all non-primitive expressions.
Definition: expr.h:361
Managed reference class to TargetNode.
Definition: target.h:192
Managed reference to TypeNode.
Definition: type.h:93
Operator implementation that includes compute and schedule function.
Definition: op_strategy.h:42
void VisitAttrs(tvm::AttrVisitor *v)
Definition: op_strategy.h:53
FTVMSchedule fschedule
Schedule function.
Definition: op_strategy.h:47
static constexpr const char * _type_key
Definition: op_strategy.h:58
String name
Name of the implementation.
Definition: op_strategy.h:49
TVM_DECLARE_FINAL_OBJECT_INFO(OpImplementationNode, Object)
FTVMCompute fcompute
Compute function.
Definition: op_strategy.h:45
int plevel
Priority level.
Definition: op_strategy.h:51
Operator implementation class.
Definition: op_strategy.h:65
Array< te::Tensor > Compute(const Attrs &attrs, const Array< te::Tensor > &inputs, const Type &out_type)
Invoke the operator compute function.
te::Schedule Schedule(const Attrs &attrs, const Array< te::Tensor > &outs, const Target &target)
Build the computation schedule.
TVM_DEFINE_OBJECT_REF_METHODS(OpImplementation, ObjectRef, OpImplementationNode)
Specialized implementations for operators under certain conditions.
Definition: op_strategy.h:92
void VisitAttrs(tvm::AttrVisitor *v)
Definition: op_strategy.h:100
TVM_DECLARE_FINAL_OBJECT_INFO(OpSpecializationNode, ExprNode)
Array< OpImplementation > implementations
List of implementations.
Definition: op_strategy.h:95
te::SpecializedCondition condition
Condition to enable the specialization. Could be undefined to represent generic case.
Definition: op_strategy.h:98
static constexpr const char * _type_key
Definition: op_strategy.h:105
Operator specialization class.
Definition: op_strategy.h:112
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(OpSpecialization, ObjectRef, OpSpecializationNode)
void AddImplementation(FTVMCompute fcompute, FTVMSchedule fschedule, String name, int plevel)
Add an implementation.
Operator strategy to choose implementation.
Definition: op_strategy.h:130
Array< OpSpecialization > specializations
List of operator specializations.
Definition: op_strategy.h:133
TVM_DECLARE_FINAL_OBJECT_INFO(OpStrategyNode, ExprNode)
static constexpr const char * _type_key
Definition: op_strategy.h:137
void VisitAttrs(tvm::AttrVisitor *v)
Definition: op_strategy.h:135
Operator strategy class.
Definition: op_strategy.h:144
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(OpStrategy, ObjectRef, OpStrategyNode)
void AddImplementation(FTVMCompute fcompute, FTVMSchedule fschedule, String name, int plevel)
Add an implementation.
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:517
base class of all object containers.
Definition: object.h:169
Reference to string objects.
Definition: string.h:98
Global schedule container For operations and all the operations they depend on. The schedule per Oper...
Definition: schedule.h:318
Specialized condition to enable op specialization.
Definition: schedule.h:952
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Relay expression language.
The Expr and related elements in DataFlow construction.
Compilation target object.
Define a schedule.
Dataflow tensor object.