tvm
Loading...
Searching...
No Matches
cost_model.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_COST_MODEL_H_
21#define TVM_S_TIR_META_SCHEDULE_COST_MODEL_H_
22
23#include <tvm/base.h>
24#include <tvm/ffi/container/array.h>
25#include <tvm/ffi/function.h>
26#include <tvm/ffi/reflection/registry.h>
27#include <tvm/ffi/string.h>
28#include <tvm/ir/prim/expr.h>
29#include <tvm/runtime/base.h>
34
35#include <vector>
36
37namespace tvm {
38namespace s_tir {
39namespace meta_schedule {
40
41class TuneContext;
42
44class CostModelObj : public ffi::Object {
45 public:
47 virtual ~CostModelObj() = default;
48
53 virtual void Load(const ffi::String& path) = 0;
54
59 virtual void Save(const ffi::String& path) = 0;
60
67 virtual void Update(const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates,
68 const ffi::Array<RunnerResult>& results) = 0;
69
76 virtual std::vector<double> Predict(const TuneContext& context,
77 const ffi::Array<MeasureCandidate>& candidates) = 0;
78
79 static constexpr const bool _type_mutable = true;
80 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.CostModel", CostModelObj, ffi::Object);
81};
82
85 public:
90 using FLoad = ffi::TypedFunction<void(ffi::String)>;
95 using FSave = ffi::TypedFunction<void(ffi::String)>;
103 using FUpdate = ffi::TypedFunction<void(const TuneContext&, const ffi::Array<MeasureCandidate>&,
104 const ffi::Array<RunnerResult>&)>;
111 using FPredict = ffi::TypedFunction<void(const TuneContext&, const ffi::Array<MeasureCandidate>&,
112 void* p_addr)>;
121
122 void Load(const ffi::String& path);
123 void Save(const ffi::String& path);
124 void Update(const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates,
125 const ffi::Array<RunnerResult>& results);
126 std::vector<double> Predict(const TuneContext& context,
127 const ffi::Array<MeasureCandidate>& candidates);
128 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyCostModel", PyCostModelObj,
130};
131
136class CostModel : public ffi::ObjectRef {
137 public:
138 explicit CostModel(ffi::UnsafeInit tag, ffi::ObjectPtr<CostModelObj> data) : ffi::ObjectRef(tag) {
139 data_ = std::move(data);
140 }
141
151 PyCostModelObj::FSave f_save, //
152 PyCostModelObj::FUpdate f_update, //
153 PyCostModelObj::FPredict f_predict);
155};
156
157} // namespace meta_schedule
158} // namespace s_tir
159} // namespace tvm
160
161#endif // TVM_S_TIR_META_SCHEDULE_COST_MODEL_H_
TIR expressions.
Cost model.
Definition cost_model.h:44
virtual void Load(const ffi::String &path)=0
Load the cost model from given file location.
virtual void Update(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates, const ffi::Array< RunnerResult > &results)=0
Update the cost model given running results.
virtual ~CostModelObj()=default
Virtual destructor.
static constexpr const bool _type_mutable
Definition cost_model.h:79
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.CostModel", CostModelObj, ffi::Object)
virtual std::vector< double > Predict(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates)=0
Predict the normalized score (the larger the better) of given measure candidates.
virtual void Save(const ffi::String &path)=0
Save the cost model to given file location.
Managed reference to CostModelObj.
Definition cost_model.h:136
static CostModel PyCostModel(PyCostModelObj::FLoad f_load, PyCostModelObj::FSave f_save, PyCostModelObj::FUpdate f_update, PyCostModelObj::FPredict f_predict)
Create a cost model with customized methods on the python-side.
CostModel(ffi::UnsafeInit tag, ffi::ObjectPtr< CostModelObj > data)
Definition cost_model.h:138
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(CostModel, ffi::ObjectRef, CostModelObj)
The cost model with customized methods on the python-side.
Definition cost_model.h:84
ffi::TypedFunction< void(ffi::String)> FLoad
Load the cost model from given file location.
Definition cost_model.h:90
std::vector< double > Predict(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates)
Predict the normalized score (the larger the better) of given measure candidates.
ffi::TypedFunction< void(ffi::String)> FSave
Save the cost model to given file location.
Definition cost_model.h:95
FSave f_save
The packed function to the Save function.
Definition cost_model.h:116
void Save(const ffi::String &path)
Save the cost model to given file location.
ffi::TypedFunction< void(const TuneContext &, const ffi::Array< MeasureCandidate > &, void *p_addr)> FPredict
Predict the running results of given measure candidates.
Definition cost_model.h:112
ffi::TypedFunction< void(const TuneContext &, const ffi::Array< MeasureCandidate > &, const ffi::Array< RunnerResult > &)> FUpdate
Update the cost model given running results.
Definition cost_model.h:104
FUpdate f_update
The packed function to the Update function.
Definition cost_model.h:118
FLoad f_load
The packed function to the Load function.
Definition cost_model.h:114
FPredict f_predict
The packed function to the Predict function.
Definition cost_model.h:120
void Load(const ffi::String &path)
Load the cost model from given file location.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyCostModel", PyCostModelObj, CostModelObj)
void Update(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates, const ffi::Array< RunnerResult > &results)
Update the cost model given running results.
Managed reference to TuneContextObj.
Definition tune_context.h:100
Parent compiler symbol visibility.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41