tvm
measure_callback.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_MEASURE_CALLBACK_H_
21 #define TVM_META_SCHEDULE_MEASURE_CALLBACK_H_
22 
23 #include <tvm/ffi/container/array.h>
24 #include <tvm/ffi/function.h>
25 #include <tvm/ffi/reflection/registry.h>
26 #include <tvm/ffi/string.h>
32 #include <tvm/runtime/object.h>
33 
34 namespace tvm {
35 namespace meta_schedule {
36 
37 class TaskScheduler;
38 
40 class MeasureCallbackNode : public runtime::Object {
41  public:
43  virtual ~MeasureCallbackNode() = default;
44 
45  static void RegisterReflection() {
46  // No fields to register
47  }
48 
57  virtual void Apply(const TaskScheduler& task_scheduler, //
58  int task_id, //
59  const Array<MeasureCandidate>& measure_candidates, //
60  const Array<BuilderResult>& builder_results, //
61  const Array<RunnerResult>& runner_results) = 0;
62 
63  static constexpr const char* _type_key = "meta_schedule.MeasureCallback";
65 };
66 
69  public:
79  using FApply = ffi::TypedFunction<void(const TaskScheduler& task_scheduler, //
80  int task_id, //
81  const Array<MeasureCandidate>& measure_candidates, //
82  const Array<BuilderResult>& builds, //
83  const Array<RunnerResult>& results)>;
88  using FAsString = ffi::TypedFunction<String()>;
89 
94 
95  static void RegisterReflection() {
96  // `f_apply` is not registered
97  // `f_as_string` is not registered
98  }
99 
100  void Apply(const TaskScheduler& task_scheduler, //
101  int task_id, //
102  const Array<MeasureCandidate>& measure_candidates, //
103  const Array<BuilderResult>& builds, //
104  const Array<RunnerResult>& results);
105 
106  static constexpr const char* _type_key = "meta_schedule.PyMeasureCallback";
108 };
109 
114 class MeasureCallback : public runtime::ObjectRef {
115  public:
120  TVM_DLL static MeasureCallback AddToDatabase();
140  TVM_DLL static Array<MeasureCallback, void> Default();
142 };
143 
144 } // namespace meta_schedule
145 } // namespace tvm
146 
147 #endif // TVM_META_SCHEDULE_MEASURE_CALLBACK_H_
Rules to apply after measure results is available.
Definition: measure_callback.h:40
TVM_DECLARE_BASE_OBJECT_INFO(MeasureCallbackNode, Object)
static void RegisterReflection()
Definition: measure_callback.h:45
virtual void Apply(const TaskScheduler &task_scheduler, int task_id, const Array< MeasureCandidate > &measure_candidates, const Array< BuilderResult > &builder_results, const Array< RunnerResult > &runner_results)=0
Apply a measure callback rule with given arguments.
static constexpr const char * _type_key
Definition: measure_callback.h:63
virtual ~MeasureCallbackNode()=default
Virtual destructor.
Managed reference to MeasureCallbackNode.
Definition: measure_callback.h:114
static MeasureCallback PyMeasureCallback(PyMeasureCallbackNode::FApply f_apply, PyMeasureCallbackNode::FAsString f_as_string)
Create a measure callback with customized methods on the python-side.
static Array< MeasureCallback, void > Default()
The default list of measure callbacks.
static MeasureCallback AddToDatabase()
Create a measure callback that adds the measurement results into the database.
static MeasureCallback RemoveBuildArtifact()
Create a measure callback that removes the build artifacts from the disk.
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(MeasureCallback, ObjectRef, MeasureCallbackNode)
static MeasureCallback UpdateCostModel()
Create a measure callback that updates the cost model with measurement result.
The measure callback with customized methods on the python-side.
Definition: measure_callback.h:68
static constexpr const char * _type_key
Definition: measure_callback.h:106
TVM_DECLARE_FINAL_OBJECT_INFO(PyMeasureCallbackNode, MeasureCallbackNode)
void Apply(const TaskScheduler &task_scheduler, int task_id, const Array< MeasureCandidate > &measure_candidates, const Array< BuilderResult > &builds, const Array< RunnerResult > &results)
Apply a measure callback rule with given arguments.
ffi::TypedFunction< void(const TaskScheduler &task_scheduler, int task_id, const Array< MeasureCandidate > &measure_candidates, const Array< BuilderResult > &builds, const Array< RunnerResult > &results)> FApply
Apply a measure callback to the given schedule.
Definition: measure_callback.h:83
FApply f_apply
The packed function to the Apply function.
Definition: measure_callback.h:91
ffi::TypedFunction< String()> FAsString
Get the measure callback function as string with name.
Definition: measure_callback.h:88
FAsString f_as_string
The packed function to the AsString function.
Definition: measure_callback.h:93
static void RegisterReflection()
Definition: measure_callback.h:95
Managed reference to TaskSchedulerNode.
Definition: task_scheduler.h:262
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
A managed object in the TVM runtime.