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 
28 #include <tvm/node/reflection.h>
31 #include <tvm/runtime/object.h>
33 
34 namespace tvm {
35 namespace meta_schedule {
36 
37 class TaskScheduler;
38 
41  public:
43  virtual ~MeasureCallbackNode() = default;
44 
46 
55  virtual void Apply(const TaskScheduler& task_scheduler, //
56  int task_id, //
57  const Array<MeasureCandidate>& measure_candidates, //
58  const Array<BuilderResult>& builder_results, //
59  const Array<RunnerResult>& runner_results) = 0;
60 
61  static constexpr const char* _type_key = "meta_schedule.MeasureCallback";
63 };
64 
67  public:
77  using FApply =
78  runtime::TypedPackedFunc<void(const TaskScheduler& task_scheduler, //
79  int task_id, //
80  const Array<MeasureCandidate>& measure_candidates, //
81  const Array<BuilderResult>& builds, //
82  const Array<RunnerResult>& results)>;
88 
93 
95  // `f_apply` is not visited
96  // `f_as_string` is not visited
97  }
98 
99  void Apply(const TaskScheduler& task_scheduler, //
100  int task_id, //
101  const Array<MeasureCandidate>& measure_candidates, //
102  const Array<BuilderResult>& builds, //
103  const Array<RunnerResult>& results);
104 
105  static constexpr const char* _type_key = "meta_schedule.PyMeasureCallback";
107 };
108 
114  public:
119  TVM_DLL static MeasureCallback AddToDatabase();
141 };
142 
143 } // namespace meta_schedule
144 } // namespace tvm
145 
146 #endif // TVM_META_SCHEDULE_MEASURE_CALLBACK_H_
Runtime Array container types.
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
Rules to apply after measure results is available.
Definition: measure_callback.h:40
TVM_DECLARE_BASE_OBJECT_INFO(MeasureCallbackNode, Object)
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:61
void VisitAttrs(tvm::AttrVisitor *v)
Definition: measure_callback.h:45
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.
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:66
static constexpr const char * _type_key
Definition: measure_callback.h:105
TVM_DECLARE_FINAL_OBJECT_INFO(PyMeasureCallbackNode, MeasureCallbackNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: measure_callback.h:94
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.
FApply f_apply
The packed function to the Apply function.
Definition: measure_callback.h:90
FAsString f_as_string
The packed function to the AsString function.
Definition: measure_callback.h:92
Managed reference to TaskSchedulerNode.
Definition: task_scheduler.h:262
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.
Type-erased function used across TVM API.
Reflection and serialization of compiler IR/AST nodes.
Runtime String container types.