tvm
schedule_rule.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 
20 #ifndef TVM_META_SCHEDULE_SCHEDULE_RULE_H_
21 #define TVM_META_SCHEDULE_SCHEDULE_RULE_H_
22 
23 #include <tvm/ir/expr.h>
24 #include <tvm/node/reflection.h>
29 #include <tvm/runtime/object.h>
32 
33 namespace tvm {
34 namespace meta_schedule {
35 
36 class TuneContext;
37 
40  public:
42  virtual ~ScheduleRuleNode() = default;
43 
45 
51  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
52 
60  const tir::BlockRV& block) = 0;
61 
62  static constexpr const char* _type_key = "meta_schedule.ScheduleRule";
64 };
65 
68  public:
80  using FApply =
87 
94 
96  // `f_initialize_with_tune_context` is not visited
97  // `f_apply` is not visited
98  // `f_as_string` is not visited
99  }
100 
101  void InitializeWithTuneContext(const TuneContext& context) final;
102  Array<tir::Schedule> Apply(const tir::Schedule& sch, const tir::BlockRV& block) final;
103 
104  static constexpr const char* _type_key = "meta_schedule.PyScheduleRule";
106 };
107 
113  public:
125  TVM_DLL static ScheduleRule AutoInline(bool into_producer, //
126  bool into_consumer, //
127  bool inline_const_tensor, //
128  bool disallow_if_then_else, //
129  bool require_injective, //
130  bool require_ordered, //
131  Optional<Array<String>> disallow_op);
147  TVM_DLL static ScheduleRule MultiLevelTiling(String structure, //
148  Optional<Array<String>> tile_binds, //
149  Optional<Integer> max_innermost_factor, //
150  Optional<Array<Integer>> vector_load_lens, //
151  Optional<Map<String, ObjectRef>> reuse_read, //
152  Optional<Map<String, ObjectRef>> reuse_write);
153 
171  TVM_DLL static ScheduleRule MultiLevelTilingWithIntrin(
172  String intrin_name, String structure, Optional<Array<String>> tile_binds,
173  Optional<Integer> max_innermost_factor, Optional<Array<Integer>> vector_load_lens,
175 
184  TVM_DLL static ScheduleRule AddRFactor(int max_jobs_per_core, //
185  Optional<Integer> max_innermost_factor);
192  TVM_DLL static ScheduleRule CrossThreadReduction(Array<Integer> thread_extents);
197  TVM_DLL static ScheduleRule RandomComputeLocation();
211  TVM_DLL static ScheduleRule ParallelizeVectorizeUnroll(int max_jobs_per_core, //
212  int max_vectorize_extent, //
213  Array<Integer> unroll_max_steps, //
214  bool unroll_explicit);
221  TVM_DLL static ScheduleRule AutoBind(int max_threadblocks, Array<Integer> thread_extents);
229  TVM_DLL static ScheduleRule PyScheduleRule(
230  PyScheduleRuleNode::FInitializeWithTuneContext f_initialize_with_tune_context, //
231  PyScheduleRuleNode::FApply f_apply, //
232  PyScheduleRuleNode::FAsString f_as_string);
234 };
235 
236 } // namespace meta_schedule
237 } // namespace tvm
238 
239 #endif // TVM_META_SCHEDULE_SCHEDULE_RULE_H_
Rules to modify a block in a schedule.
Definition: schedule_rule.h:39
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
Runtime Optional container types.
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: schedule_rule.h:89
Runtime String container types.
Base expr nodes in TVM.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
FAsString f_as_string
The packed function to the AsString function.
Definition: schedule_rule.h:93
static constexpr const char * _type_key
Definition: schedule_rule.h:62
base class of all object containers.
Definition: object.h:167
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:744
FApply f_apply
The packed function to the Apply function.
Definition: schedule_rule.h:91
Managed reference to ScheduleNode.
Definition: schedule.h:618
Managed reference to TuneContextNode.
Definition: tune_context.h:129
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
TVM_DECLARE_BASE_OBJECT_INFO(ScheduleRuleNode, Object)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: schedule_rule.h:95
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
The schedule rule with customized methods on the python-side.
Definition: schedule_rule.h:67
Managed reference to ScheduleRuleNode.
Definition: schedule_rule.h:112
Reference to string objects.
Definition: string.h:124
Base class of all object reference.
Definition: object.h:511
virtual runtime::Array< tir::Schedule > Apply(const tir::Schedule &sch, const tir::BlockRV &block)=0
Apply a schedule rule to the specific block in the given schedule.
A managed object in the TVM runtime.
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1268
Runtime Map container types.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reflection and serialization of compiler IR/AST nodes.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: schedule_rule.h:44
virtual ~ScheduleRuleNode()=default
Virtual destructor.
Managed reference to BlockRVNode.
Definition: schedule.h:62
Type-erased function used across TVM API.