tvm
search_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 #ifndef TVM_META_SCHEDULE_SEARCH_STRATEGY_H_
20 #define TVM_META_SCHEDULE_SEARCH_STRATEGY_H_
21 
27 #include <tvm/node/reflection.h>
30 #include <tvm/runtime/object.h>
33 
34 namespace tvm {
35 namespace meta_schedule {
36 
37 // Forward declaration
38 class TuneContext;
39 
77  public:
79  virtual ~SearchStrategyNode() = default;
80 
86  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
87 
97  virtual void PreTuning(const Array<tir::Schedule>& design_spaces,
98  const Optional<Database>& database,
99  const Optional<CostModel>& cost_model) = 0;
100 
106  virtual void PostTuning() = 0;
107 
113 
119  virtual void NotifyRunnerResults(const Array<MeasureCandidate>& measure_candidates,
120  const Array<RunnerResult>& results) = 0;
121 
122  static constexpr const char* _type_key = "meta_schedule.SearchStrategy";
124 };
125 
128  public:
151  using FNotifyRunnerResults =
153 
163  FNotifyRunnerResults f_notify_runner_results;
164 
166  // `f_initialize_with_tune_context` is not visited
167  // `f_pre_tuning` is not visited
168  // `f_post_tuning` is not visited
169  // `f_generate_measure_candidates` is not visited
170  // `f_notify_runner_results` is not visited
171  }
172 
173  void InitializeWithTuneContext(const TuneContext& context) final;
174  void PreTuning(const Array<tir::Schedule>& design_spaces, const Optional<Database>& database,
175  const Optional<CostModel>& cost_model) final;
176  void PostTuning() final;
178  void NotifyRunnerResults(const Array<MeasureCandidate>& measure_candidates,
179  const Array<RunnerResult>& results);
180 
181  static constexpr const char* _type_key = "meta_schedule.PySearchStrategy";
183 };
184 
190  public:
200  TVM_DLL static SearchStrategy PySearchStrategy(
201  PySearchStrategyNode::FInitializeWithTuneContext f_initialize_with_tune_context, //
202  PySearchStrategyNode::FPreTuning f_pre_tuning, //
203  PySearchStrategyNode::FPostTuning f_post_tuning, //
204  PySearchStrategyNode::FGenerateMeasureCandidates f_generate_measure_candidates, //
205  PySearchStrategyNode::FNotifyRunnerResults f_notify_runner_results);
206 
213  TVM_DLL static SearchStrategy ReplayTrace(int num_trials_per_iter, int max_trials_per_task,
214  int max_fail_count);
215 
221  TVM_DLL static SearchStrategy ReplayFunc(int num_trials_per_iter, int max_trials_per_task);
222 
235  TVM_DLL static SearchStrategy EvolutionarySearch(int num_trials_per_iter, //
236  int max_trials_per_task, //
237  int population_size, //
238  double init_measured_ratio, //
239  int init_min_unmeasured, //
240  int genetic_num_iters, //
241  double genetic_mutate_prob, //
242  int genetic_max_fail_count, //
243  double eps_greedy);
244 
246 };
247 
248 } // namespace meta_schedule
249 } // namespace tvm
250 
251 #endif // TVM_META_SCHEDULE_SEARCH_STRATEGY_H_
virtual ~SearchStrategyNode()=default
Virtual destructor.
FNotifyRunnerResults f_notify_runner_results
The packed function to the NotifyRunnerResults method.
Definition: search_strategy.h:163
void VisitAttrs(tvm::AttrVisitor *v)
Definition: search_strategy.h:165
Runtime Optional container types.
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext method.
Definition: search_strategy.h:155
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
virtual void NotifyRunnerResults(const Array< MeasureCandidate > &measure_candidates, const Array< RunnerResult > &results)=0
Update the search strategy with measurement results.
virtual void PreTuning(const Array< tir::Schedule > &design_spaces, const Optional< Database > &database, const Optional< CostModel > &cost_model)=0
Pre-tuning for the search strategy.
Managed reference to SearchStrategyNode.
Definition: search_strategy.h:189
base class of all object containers.
Definition: object.h:167
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:744
FPreTuning f_pre_tuning
The packed function to the PreTuning method.
Definition: search_strategy.h:157
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
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the search strategy with tuning context.
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
TVM_DECLARE_BASE_OBJECT_INFO(SearchStrategyNode, Object)
virtual Optional< Array< MeasureCandidate > > GenerateMeasureCandidates()=0
Generate measure candidates from design spaces for measurement.
Base class of all object reference.
Definition: object.h:511
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
virtual void PostTuning()=0
Post-tuning for the search strategy.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
The python side customizable class for measure candidate generation.
Definition: search_strategy.h:127
FGenerateMeasureCandidates f_generate_measure_candidates
The packed function to the GenerateMeasureCandidates method.
Definition: search_strategy.h:161
Reflection and serialization of compiler IR/AST nodes.
static constexpr const char * _type_key
Definition: search_strategy.h:122
The search strategy for measure candidates generation.
Definition: search_strategy.h:76
Type-erased function used across TVM API.
FPostTuning f_post_tuning
The packed function to the PostTuning method.
Definition: search_strategy.h:159