tvm
feature_extractor.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_FEATURE_EXTRACTOR_H_
21 #define TVM_META_SCHEDULE_FEATURE_EXTRACTOR_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>
28 #include <tvm/runtime/object.h>
29 #include <tvm/runtime/tensor.h>
30 
31 namespace tvm {
32 namespace meta_schedule {
33 
34 class TuneContext;
35 
37 class FeatureExtractorNode : public runtime::Object {
38  public:
40  virtual ~FeatureExtractorNode() = default;
41 
42  static void RegisterReflection() {
43  namespace refl = tvm::ffi::reflection;
44  refl::ObjectDef<FeatureExtractorNode>();
45  }
46 
53  virtual ffi::Array<tvm::runtime::Tensor> ExtractFrom(
54  const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates) = 0;
55  TVM_FFI_DECLARE_OBJECT_INFO("meta_schedule.FeatureExtractor", FeatureExtractorNode, Object);
56 };
57 
60  public:
67  using FExtractFrom = ffi::TypedFunction<ffi::Array<tvm::runtime::Tensor>(
68  const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates)>;
73  using FAsString = ffi::TypedFunction<ffi::String()>;
74 
79 
80  static void RegisterReflection() {
81  // `f_extract_from` is not registered
82  // `f_as_string` is not registered
83  namespace refl = tvm::ffi::reflection;
84  refl::ObjectDef<PyFeatureExtractorNode>();
85  }
86 
87  ffi::Array<tvm::runtime::Tensor> ExtractFrom(
88  const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates) final;
89  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("meta_schedule.PyFeatureExtractor", PyFeatureExtractorNode,
91 };
92 
97 class FeatureExtractor : public runtime::ObjectRef {
98  public:
109  TVM_DLL static FeatureExtractor PerStoreFeature(int buffers_per_store = 5,
110  int arith_intensity_curve_num_samples = 10,
111  int cache_line_bytes = 64,
112  bool extract_workload = false);
123 };
124 
125 } // namespace meta_schedule
126 } // namespace tvm
127 
128 #endif // TVM_META_SCHEDULE_FEATURE_EXTRACTOR_H_
Extractor for features from measure candidates for use in cost model.
Definition: feature_extractor.h:37
virtual ffi::Array< tvm::runtime::Tensor > ExtractFrom(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates)=0
Extract features from the given measure candidate.
virtual ~FeatureExtractorNode()=default
Virtual destructor.
static void RegisterReflection()
Definition: feature_extractor.h:42
TVM_FFI_DECLARE_OBJECT_INFO("meta_schedule.FeatureExtractor", FeatureExtractorNode, Object)
Managed reference to FeatureExtractorNode.
Definition: feature_extractor.h:97
static FeatureExtractor PerStoreFeature(int buffers_per_store=5, int arith_intensity_curve_num_samples=10, int cache_line_bytes=64, bool extract_workload=false)
Create a feature extractor that extracts features from each BufferStore.
static FeatureExtractor PyFeatureExtractor(PyFeatureExtractorNode::FExtractFrom f_extract_from, PyFeatureExtractorNode::FAsString f_as_string)
Create a feature extractor with customized methods on the python-side.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FeatureExtractor, ObjectRef, FeatureExtractorNode)
The feature extractor with customized methods on the python-side.
Definition: feature_extractor.h:59
FAsString f_as_string
The packed function to the AsString function.
Definition: feature_extractor.h:78
ffi::TypedFunction< ffi::Array< tvm::runtime::Tensor >(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates)> FExtractFrom
Extract features from the given measure candidate.
Definition: feature_extractor.h:68
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("meta_schedule.PyFeatureExtractor", PyFeatureExtractorNode, FeatureExtractorNode)
ffi::TypedFunction< ffi::String()> FAsString
Get the feature extractor as string with name.
Definition: feature_extractor.h:73
static void RegisterReflection()
Definition: feature_extractor.h:80
FExtractFrom f_extract_from
The packed function to the ExtractFrom function.
Definition: feature_extractor.h:76
ffi::Array< tvm::runtime::Tensor > ExtractFrom(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates) final
Extract features from the given measure candidate.
Managed reference to TuneContextNode.
Definition: tune_context.h:98
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
A managed object in the TVM runtime.
A device-independent managed Tensor abstraction.