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 ffi::Array<MeasureCandidate>& measure_candidates, //
60  const ffi::Array<BuilderResult>& builder_results, //
61  const ffi::Array<RunnerResult>& runner_results) = 0;
62 
63  static constexpr const bool _type_mutable = true;
64  TVM_FFI_DECLARE_OBJECT_INFO("meta_schedule.MeasureCallback", MeasureCallbackNode, Object);
65 };
66 
69  public:
79  using FApply = ffi::TypedFunction<void(const TaskScheduler& task_scheduler, //
80  int task_id, //
81  const ffi::Array<MeasureCandidate>& measure_candidates, //
82  const ffi::Array<BuilderResult>& builds, //
83  const ffi::Array<RunnerResult>& results)>;
88  using FAsString = ffi::TypedFunction<ffi::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 ffi::Array<MeasureCandidate>& measure_candidates, //
103  const ffi::Array<BuilderResult>& builds, //
104  const ffi::Array<RunnerResult>& results);
105  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("meta_schedule.PyMeasureCallback", PyMeasureCallbackNode,
107 };
108 
113 class MeasureCallback : public runtime::ObjectRef {
114  public:
119  TVM_DLL static MeasureCallback AddToDatabase();
139  TVM_DLL static ffi::Array<MeasureCallback, void> Default();
141 };
142 
143 } // namespace meta_schedule
144 } // namespace tvm
145 
146 #endif // TVM_META_SCHEDULE_MEASURE_CALLBACK_H_
Rules to apply after measure results is available.
Definition: measure_callback.h:40
static void RegisterReflection()
Definition: measure_callback.h:45
virtual void Apply(const TaskScheduler &task_scheduler, int task_id, const ffi::Array< MeasureCandidate > &measure_candidates, const ffi::Array< BuilderResult > &builder_results, const ffi::Array< RunnerResult > &runner_results)=0
Apply a measure callback rule with given arguments.
TVM_FFI_DECLARE_OBJECT_INFO("meta_schedule.MeasureCallback", MeasureCallbackNode, Object)
static constexpr const bool _type_mutable
Definition: measure_callback.h:63
virtual ~MeasureCallbackNode()=default
Virtual destructor.
Managed reference to MeasureCallbackNode.
Definition: measure_callback.h:113
static MeasureCallback PyMeasureCallback(PyMeasureCallbackNode::FApply f_apply, PyMeasureCallbackNode::FAsString f_as_string)
Create a measure callback with customized methods on the python-side.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(MeasureCallback, ObjectRef, MeasureCallbackNode)
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.
static MeasureCallback UpdateCostModel()
Create a measure callback that updates the cost model with measurement result.
static ffi::Array< MeasureCallback, void > Default()
The default list of measure callbacks.
The measure callback with customized methods on the python-side.
Definition: measure_callback.h:68
ffi::TypedFunction< ffi::String()> FAsString
Get the measure callback function as string with name.
Definition: measure_callback.h:88
ffi::TypedFunction< void(const TaskScheduler &task_scheduler, int task_id, const ffi::Array< MeasureCandidate > &measure_candidates, const ffi::Array< BuilderResult > &builds, const ffi::Array< RunnerResult > &results)> FApply
Apply a measure callback to the given schedule.
Definition: measure_callback.h:83
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("meta_schedule.PyMeasureCallback", PyMeasureCallbackNode, MeasureCallbackNode)
FApply f_apply
The packed function to the Apply function.
Definition: measure_callback.h:91
FAsString f_as_string
The packed function to the AsString function.
Definition: measure_callback.h:93
void Apply(const TaskScheduler &task_scheduler, int task_id, const ffi::Array< MeasureCandidate > &measure_candidates, const ffi::Array< BuilderResult > &builds, const ffi::Array< RunnerResult > &results)
Apply a measure callback rule with given arguments.
static void RegisterReflection()
Definition: measure_callback.h:95
Managed reference to TaskSchedulerNode.
Definition: task_scheduler.h:261
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
A managed object in the TVM runtime.