tvm
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_META_SCHEDULE_COST_MODEL_H_
21 #define TVM_META_SCHEDULE_COST_MODEL_H_
22 
26 #include <tvm/node/reflection.h>
29 #include <tvm/runtime/object.h>
32 
33 #include <vector>
34 
35 namespace tvm {
36 namespace meta_schedule {
37 
38 class TuneContext;
39 
42  public:
44  virtual ~CostModelNode() = default;
45 
47 
52  virtual void Load(const String& path) = 0;
53 
58  virtual void Save(const String& path) = 0;
59 
66  virtual void Update(const TuneContext& context, const Array<MeasureCandidate>& candidates,
67  const Array<RunnerResult>& results) = 0;
68 
75  virtual std::vector<double> Predict(const TuneContext& context,
76  const Array<MeasureCandidate>& candidates) = 0;
77 
78  static constexpr const char* _type_key = "meta_schedule.CostModel";
80 };
81 
84  public:
103  const Array<RunnerResult>&)>;
111  void* p_addr)>;
117 
128 
130  // `f_load` is not visited
131  // `f_save` is not visited
132  // `f_update` is not visited
133  // `f_predict` is not visited
134  // `f_as_string` is not visited
135  }
136 
137  void Load(const String& path);
138  void Save(const String& path);
139  void Update(const TuneContext& context, const Array<MeasureCandidate>& candidates,
140  const Array<RunnerResult>& results);
141  std::vector<double> Predict(const TuneContext& context,
142  const Array<MeasureCandidate>& candidates);
143 
144  static constexpr const char* _type_key = "meta_schedule.PyCostModel";
146 };
147 
153  public:
163  TVM_DLL static CostModel PyCostModel(PyCostModelNode::FLoad f_load, //
164  PyCostModelNode::FSave f_save, //
165  PyCostModelNode::FUpdate f_update, //
166  PyCostModelNode::FPredict f_predict, //
167  PyCostModelNode::FAsString f_as_string);
169 };
170 
171 } // namespace meta_schedule
172 } // namespace tvm
173 
174 #endif // TVM_META_SCHEDULE_COST_MODEL_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
Cost model.
Definition: cost_model.h:41
virtual void Save(const String &path)=0
Save the cost model to given file location.
virtual void Update(const TuneContext &context, const Array< MeasureCandidate > &candidates, const Array< RunnerResult > &results)=0
Update the cost model given running results.
virtual std::vector< double > Predict(const TuneContext &context, const Array< MeasureCandidate > &candidates)=0
Predict the normalized score (the larger the better) of given measure candidates.
virtual ~CostModelNode()=default
Virtual destructor.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: cost_model.h:46
TVM_DECLARE_BASE_OBJECT_INFO(CostModelNode, Object)
static constexpr const char * _type_key
Definition: cost_model.h:78
virtual void Load(const String &path)=0
Load the cost model from given file location.
Managed reference to CostModelNode.
Definition: cost_model.h:152
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(CostModel, ObjectRef, CostModelNode)
static CostModel PyCostModel(PyCostModelNode::FLoad f_load, PyCostModelNode::FSave f_save, PyCostModelNode::FUpdate f_update, PyCostModelNode::FPredict f_predict, PyCostModelNode::FAsString f_as_string)
Create a feature extractor with customized methods on the python-side.
The cost model with customized methods on the python-side.
Definition: cost_model.h:83
void VisitAttrs(tvm::AttrVisitor *v)
Definition: cost_model.h:129
FPredict f_predict
The packed function to the Predict function.
Definition: cost_model.h:125
void Load(const String &path)
Load the cost model from given file location.
FLoad f_load
The packed function to the Load function.
Definition: cost_model.h:119
void Save(const String &path)
Save the cost model to given file location.
void Update(const TuneContext &context, const Array< MeasureCandidate > &candidates, const Array< RunnerResult > &results)
Update the cost model given running results.
TVM_DECLARE_FINAL_OBJECT_INFO(PyCostModelNode, CostModelNode)
FSave f_save
The packed function to the Save function.
Definition: cost_model.h:121
std::vector< double > Predict(const TuneContext &context, const Array< MeasureCandidate > &candidates)
Predict the normalized score (the larger the better) of given measure candidates.
static constexpr const char * _type_key
Definition: cost_model.h:144
FUpdate f_update
The packed function to the Update function.
Definition: cost_model.h:123
FAsString f_as_string
The packed function to the AsString function.
Definition: cost_model.h:127
Managed reference to TuneContextNode.
Definition: tune_context.h:95
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.