tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 class ScheduleRule;
38 
41  public:
43  virtual ~ScheduleRuleNode() = default;
44 
46 
52  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
53 
61  const tir::BlockRV& block) = 0;
62 
67  virtual ScheduleRule Clone() const = 0;
68 
69  static constexpr const char* _type_key = "meta_schedule.ScheduleRule";
71 };
72 
78  public:
90  using FApply =
107  TVM_DLL static ScheduleRule ApplyCustomRule();
109  TVM_DLL static bool IsApplyCustomRule(const ScheduleRule& rule);
121  TVM_DLL static ScheduleRule AutoInline(bool into_producer, //
122  bool into_consumer, //
123  bool inline_const_tensor, //
124  bool disallow_if_then_else, //
125  bool require_injective, //
126  bool require_ordered, //
127  Optional<Array<String>> disallow_op);
128 
136  TVM_DLL static ScheduleRule InlineConstantScalars();
137 
157  TVM_DLL static ScheduleRule MultiLevelTiling(String structure, //
158  Optional<Array<String>> tile_binds, //
159  Optional<Integer> max_innermost_factor, //
160  Optional<Array<Integer>> vector_load_lens, //
161  Optional<Map<String, ObjectRef>> reuse_read, //
162  Optional<Map<String, ObjectRef>> reuse_write,
164 
182  TVM_DLL static ScheduleRule MultiLevelTilingWithIntrin(
183  String intrin_name, String structure, Optional<Array<String>> tile_binds,
184  Optional<Integer> max_innermost_factor, Optional<Array<Integer>> vector_load_lens,
186 
207  TVM_DLL static ScheduleRule MultiLevelTilingTensorCore(
208  Array<Map<String, String>> intrin_groups, String structure,
209  Optional<Array<String>> tile_binds, Optional<Integer> max_innermost_factor,
210  Optional<Array<Integer>> vector_load_lens, Optional<Map<String, ObjectRef>> reuse_read,
211  Optional<Map<String, ObjectRef>> reuse_write, bool use_software_pipeline);
212 
224  TVM_DLL static ScheduleRule MultiLevelTilingWideVector(
225  String structure, Integer vector_length_in_bits, Optional<Integer> max_innermost_factor,
227 
236  TVM_DLL static ScheduleRule AddRFactor(int max_jobs_per_core, //
237  Optional<Integer> max_innermost_factor);
244  TVM_DLL static ScheduleRule CrossThreadReduction(Array<Integer> thread_extents);
249  TVM_DLL static ScheduleRule RandomComputeLocation();
263  TVM_DLL static ScheduleRule ParallelizeVectorizeUnroll(int max_jobs_per_core, //
264  int max_vectorize_extent, //
265  Array<Integer> unroll_max_steps, //
266  bool unroll_explicit);
275  TVM_DLL static ScheduleRule AutoBind(int max_threadblocks, Array<Integer> thread_extents,
276  int max_threads_per_block = -1);
285  TVM_DLL static ScheduleRule PyScheduleRule(
286  FInitializeWithTuneContext f_initialize_with_tune_context, //
287  FApply f_apply, //
288  FClone f_clone, //
289  FAsString f_as_string);
290 
292  TVM_DLL static Array<ScheduleRule, void> DefaultLLVM();
294  TVM_DLL static Array<ScheduleRule, void> DefaultX86(const String& type);
296  TVM_DLL static Array<ScheduleRule, void> DefaultCUDA();
298  TVM_DLL static Array<ScheduleRule, void> DefaultCUDATensorCore();
300  TVM_DLL static Array<ScheduleRule, void> DefaultHexagon();
302  TVM_DLL static Array<ScheduleRule, void> DefaultMicro();
304  TVM_DLL static Array<ScheduleRule, void> DefaultARM(const String& type);
305 
307 };
308 
311  public:
316 
325 
327  // `f_initialize_with_tune_context` is not visited
328  // `f_apply` is not visited
329  // `f_as_string` is not visited
330  // `f_clone` is not visited
331  }
332 
333  void InitializeWithTuneContext(const TuneContext& context) final;
334  Array<tir::Schedule> Apply(const tir::Schedule& sch, const tir::BlockRV& block) final;
335  ScheduleRule Clone() const final;
336 
337  static constexpr const char* _type_key = "meta_schedule.PyScheduleRule";
339 };
340 
341 } // namespace meta_schedule
342 } // namespace tvm
343 
344 #endif // TVM_META_SCHEDULE_SCHEDULE_RULE_H_
Rules to modify a block in a schedule.
Definition: schedule_rule.h:40
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
virtual ScheduleRule Clone() const =0
Deep clone the schedule rule.
Runtime Optional container types.
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: schedule_rule.h:318
Runtime String container types.
runtime::TypedPackedFunc< Array< tir::Schedule >(const tir::Schedule &, const tir::BlockRV &)> FApply
The function type of Apply method.
Definition: schedule_rule.h:91
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:322
static constexpr const char * _type_key
Definition: schedule_rule.h:69
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:320
Managed reference to ScheduleNode.
Definition: schedule.h:813
Managed reference to TuneContextNode.
Definition: tune_context.h:95
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:326
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: schedule_rule.h:83
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
The schedule rule with customized methods on the python-side.
Definition: schedule_rule.h:310
Managed reference to ScheduleRuleNode.
Definition: schedule_rule.h:77
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
runtime::TypedPackedFunc< String()> FAsString
Get the schedule rule as string with name.
Definition: schedule_rule.h:96
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
FClone f_clone
The packed function to the Clone function.
Definition: schedule_rule.h:324
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:1271
Runtime Map container types.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
constexpr runtime::NullOptType NullOpt
Definition: optional.h:160
Reflection and serialization of compiler IR/AST nodes.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: schedule_rule.h:45
runtime::TypedPackedFunc< ScheduleRule()> FClone
The function type of Clone method.
Definition: schedule_rule.h:101
virtual ~ScheduleRuleNode()=default
Virtual destructor.
Managed reference to BlockRVNode.
Definition: schedule.h:62
Type-erased function used across TVM API.
Container of constant int that adds more constructors.
Definition: expr.h:622