tvm
Loading...
Searching...
No Matches
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_S_TIR_META_SCHEDULE_MEASURE_CALLBACK_H_
21#define TVM_S_TIR_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>
27#include <tvm/ir/prim/expr.h>
28#include <tvm/runtime/base.h>
34
35namespace tvm {
36namespace s_tir {
37namespace meta_schedule {
38
39class TaskScheduler;
40
42class MeasureCallbackObj : public ffi::Object {
43 public:
45 virtual ~MeasureCallbackObj() = default;
46
47 static void RegisterReflection() {
48 namespace refl = tvm::ffi::reflection;
49 refl::ObjectDef<MeasureCallbackObj>();
50 }
51
60 virtual void Apply(const TaskScheduler& task_scheduler, //
61 int task_id, //
62 const ffi::Array<MeasureCandidate>& measure_candidates, //
63 const ffi::Array<BuilderResult>& builder_results, //
64 const ffi::Array<RunnerResult>& runner_results) = 0;
65
66 static constexpr const bool _type_mutable = true;
67 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.MeasureCallback", MeasureCallbackObj,
68 ffi::Object);
69};
70
73 public:
83 using FApply = ffi::TypedFunction<void(const TaskScheduler& task_scheduler, //
84 int task_id, //
85 const ffi::Array<MeasureCandidate>& measure_candidates, //
86 const ffi::Array<BuilderResult>& builds, //
87 const ffi::Array<RunnerResult>& results)>;
90
91 static void RegisterReflection() {
92 // `f_apply` is not registered
93 namespace refl = tvm::ffi::reflection;
94 refl::ObjectDef<PyMeasureCallbackObj>();
95 }
96
97 void Apply(const TaskScheduler& task_scheduler, //
98 int task_id, //
99 const ffi::Array<MeasureCandidate>& measure_candidates, //
100 const ffi::Array<BuilderResult>& builds, //
101 const ffi::Array<RunnerResult>& results);
102 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyMeasureCallback", PyMeasureCallbackObj,
104};
105
110class MeasureCallback : public ffi::ObjectRef {
111 public:
112 explicit MeasureCallback(ffi::UnsafeInit tag, ffi::ObjectPtr<MeasureCallbackObj> data)
113 : ffi::ObjectRef(tag) {
114 data_ = std::move(data);
115 }
116
139 TVM_DLL static ffi::Array<MeasureCallback, void> Default();
142};
143
144} // namespace meta_schedule
145} // namespace s_tir
146} // namespace tvm
147
148#endif // TVM_S_TIR_META_SCHEDULE_MEASURE_CALLBACK_H_
Rules to apply after measure results is available.
Definition measure_callback.h:42
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.
static void RegisterReflection()
Definition measure_callback.h:47
static constexpr const bool _type_mutable
Definition measure_callback.h:66
virtual ~MeasureCallbackObj()=default
Virtual destructor.
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.MeasureCallback", MeasureCallbackObj, ffi::Object)
Managed reference to MeasureCallbackObj.
Definition measure_callback.h:110
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.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(MeasureCallback, ffi::ObjectRef, MeasureCallbackObj)
MeasureCallback(ffi::UnsafeInit tag, ffi::ObjectPtr< MeasureCallbackObj > data)
Definition measure_callback.h:112
static ffi::Array< MeasureCallback, void > Default()
The default list of measure callbacks.
static MeasureCallback PyMeasureCallback(PyMeasureCallbackObj::FApply f_apply)
Create a measure callback with customized methods on the python-side.
The measure callback with customized methods on the python-side.
Definition measure_callback.h:72
FApply f_apply
The packed function to the Apply function.
Definition measure_callback.h:89
static void RegisterReflection()
Definition measure_callback.h:91
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.
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:87
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyMeasureCallback", PyMeasureCallbackObj, MeasureCallbackObj)
Managed reference to TaskSchedulerObj.
Definition task_scheduler.h:263
TIR expressions.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23