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 {
37using namespace tvm::prim;
38namespace meta_schedule {
39
40class TaskScheduler;
41
43class MeasureCallbackNode : public ffi::Object {
44 public:
46 virtual ~MeasureCallbackNode() = default;
47
48 static void RegisterReflection() {
49 namespace refl = tvm::ffi::reflection;
50 refl::ObjectDef<MeasureCallbackNode>();
51 }
52
61 virtual void Apply(const TaskScheduler& task_scheduler, //
62 int task_id, //
63 const ffi::Array<MeasureCandidate>& measure_candidates, //
64 const ffi::Array<BuilderResult>& builder_results, //
65 const ffi::Array<RunnerResult>& runner_results) = 0;
66
67 static constexpr const bool _type_mutable = true;
68 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.MeasureCallback", MeasureCallbackNode,
69 ffi::Object);
70};
71
74 public:
84 using FApply = ffi::TypedFunction<void(const TaskScheduler& task_scheduler, //
85 int task_id, //
86 const ffi::Array<MeasureCandidate>& measure_candidates, //
87 const ffi::Array<BuilderResult>& builds, //
88 const ffi::Array<RunnerResult>& results)>;
91
92 static void RegisterReflection() {
93 // `f_apply` is not registered
94 namespace refl = tvm::ffi::reflection;
95 refl::ObjectDef<PyMeasureCallbackNode>();
96 }
97
99 int task_id, //
100 const ffi::Array<MeasureCandidate>& measure_candidates, //
101 const ffi::Array<BuilderResult>& builds, //
102 const ffi::Array<RunnerResult>& results);
103 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyMeasureCallback", PyMeasureCallbackNode,
105};
106
138
139} // namespace meta_schedule
140} // namespace s_tir
141} // namespace tvm
142
143#endif // TVM_S_TIR_META_SCHEDULE_MEASURE_CALLBACK_H_
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Rules to apply after measure results is available.
Definition measure_callback.h:43
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 constexpr const bool _type_mutable
Definition measure_callback.h:67
virtual ~MeasureCallbackNode()=default
Virtual destructor.
static void RegisterReflection()
Definition measure_callback.h:48
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.MeasureCallback", MeasureCallbackNode, ffi::Object)
Managed reference to MeasureCallbackNode.
Definition measure_callback.h:111
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.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(MeasureCallback, ffi::ObjectRef, MeasureCallbackNode)
static MeasureCallback PyMeasureCallback(PyMeasureCallbackNode::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:73
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:88
static void RegisterReflection()
Definition measure_callback.h:92
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyMeasureCallback", PyMeasureCallbackNode, MeasureCallbackNode)
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.
FApply f_apply
The packed function to the Apply function.
Definition measure_callback.h:90
Managed reference to TaskSchedulerNode.
Definition task_scheduler.h:264
TIR expressions.
Definition builtin.h:25
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40