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 
25 
26 namespace tvm {
27 namespace meta_schedule {
28 
29 // Forward declaration
30 class TuneContext;
31 
34  public:
39 
41  v->Visit("sch", &sch);
42  v->Visit("args_info", &args_info);
43  }
44 
45  static constexpr const char* _type_key = "meta_schedule.MeasureCandidate";
47 };
48 
54  public:
62 };
63 
101  public:
103  virtual ~SearchStrategyNode() = default;
104 
110  virtual void InitializeWithTuneContext(const TuneContext& tune_context) = 0;
111 
119  virtual void PreTuning(const Array<tir::Schedule>& design_spaces) = 0;
120 
126  virtual void PostTuning() = 0;
127 
132  virtual Optional<Array<MeasureCandidate>> GenerateMeasureCandidates() = 0;
133 
138  virtual void NotifyRunnerResults(const Array<RunnerResult>& results) = 0;
139 
140  static constexpr const char* _type_key = "meta_schedule.SearchStrategy";
142 };
143 
146  public:
169 
180 
182  // `f_initialize_with_tune_context` is not visited
183  // `f_pre_tuning` is not visited
184  // `f_post_tuning` is not visited
185  // `f_generate_measure_candidates` is not visited
186  // `f_notify_runner_results` is not visited
187  }
188 
189  void InitializeWithTuneContext(const TuneContext& context) final {
190  ICHECK(f_initialize_with_tune_context != nullptr)
191  << "PySearchStrategy's InitializeWithTuneContext method not implemented!";
192  this->f_initialize_with_tune_context(context);
193  }
194 
195  void PreTuning(const Array<tir::Schedule>& design_spaces) final {
196  ICHECK(f_pre_tuning != nullptr) << "PySearchStrategy's PreTuning method not implemented!";
197  this->f_pre_tuning(design_spaces);
198  }
199 
200  void PostTuning() final {
201  ICHECK(f_post_tuning != nullptr) << "PySearchStrategy's PostTuning method not implemented!";
202  this->f_post_tuning();
203  }
204 
206  ICHECK(f_generate_measure_candidates != nullptr)
207  << "PySearchStrategy's GenerateMeasureCandidates method not implemented!";
208  return this->f_generate_measure_candidates();
209  }
210 
211  void NotifyRunnerResults(const Array<RunnerResult>& results) final {
212  ICHECK(f_notify_runner_results != nullptr)
213  << "PySearchStrategy's NotifyRunnerResults method not implemented!";
214  this->f_notify_runner_results(results);
215  }
216 
217  static constexpr const char* _type_key = "meta_schedule.PySearchStrategy";
219 };
220 
226  public:
236  TVM_DLL static SearchStrategy PySearchStrategy(
237  PySearchStrategyNode::FInitializeWithTuneContext f_initialize_with_tune_context, //
238  PySearchStrategyNode::FPreTuning f_pre_tuning, //
239  PySearchStrategyNode::FPostTuning f_post_tuning, //
240  PySearchStrategyNode::FGenerateMeasureCandidates f_generate_measure_candidates, //
241  PySearchStrategyNode::FNotifyRunnerResults f_notify_runner_results);
242 
248  TVM_DLL static SearchStrategy ReplayTrace(int num_trials_per_iter, int num_trials_total);
249 
251 };
252 
253 } // namespace meta_schedule
254 } // namespace tvm
255 
256 #endif // TVM_META_SCHEDULE_SEARCH_STRATEGY_H_
FNotifyRunnerResults f_notify_runner_results
The packed function to the NotifyRunnerResults method.
Definition: search_strategy.h:179
void VisitAttrs(tvm::AttrVisitor *v)
Definition: search_strategy.h:181
TVM_DECLARE_FINAL_OBJECT_INFO(MeasureCandidateNode, Object)
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext method.
Definition: search_strategy.h:171
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
Managed reference to SearchStrategyNode.
Definition: search_strategy.h:225
void VisitAttrs(tvm::AttrVisitor *v)
Definition: search_strategy.h:40
base class of all object containers.
Definition: object.h:165
Array< ArgInfo > args_info
The argument information, e.g., (shape, dtype) for tensors.
Definition: search_strategy.h:38
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:737
FPreTuning f_pre_tuning
The packed function to the PreTuning method.
Definition: search_strategy.h:173
Managed reference to ScheduleNode.
Definition: schedule.h:461
Managed reference to TuneContextNode.
Definition: tune_context.h:76
The schedule (with input shapes) to be measured.
Definition: search_strategy.h:33
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
void PostTuning() final
Post-tuning for the search strategy.
Definition: search_strategy.h:200
void PreTuning(const Array< tir::Schedule > &design_spaces) final
Pre-tuning for the search strategy.
Definition: search_strategy.h:195
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
tir::Schedule sch
The schedule for measurement.
Definition: search_strategy.h:36
static constexpr const char * _type_key
Definition: search_strategy.h:45
Optional< Array< MeasureCandidate > > GenerateMeasureCandidates() final
Generate measure candidates from design spaces for measurement.
Definition: search_strategy.h:205
Base class of all object reference.
Definition: object.h:504
Managed reference to MeasureCandidateNode.
Definition: search_strategy.h:53
void NotifyRunnerResults(const Array< RunnerResult > &results) final
Update the search strategy with measurement results.
Definition: search_strategy.h:211
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:145
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the search strategy with tuning context.
Definition: search_strategy.h:189
FGenerateMeasureCandidates f_generate_measure_candidates
The packed function to the GenerateMeasureCandidates method.
Definition: search_strategy.h:177
#define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
helper macro to declare a base object type that can be inherited.
Definition: object.h:641
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:721
The search strategy for measure candidates generation.
Definition: search_strategy.h:100
FPostTuning f_post_tuning
The packed function to the PostTuning method.
Definition: search_strategy.h:175