tvm
Loading...
Searching...
No Matches
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_S_TIR_META_SCHEDULE_FEATURE_EXTRACTOR_H_
21#define TVM_S_TIR_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>
27#include <tvm/ir/prim/expr.h>
28#include <tvm/runtime/tensor.h>
30
31namespace tvm {
32namespace s_tir {
33namespace meta_schedule {
34
35class TuneContext;
36
38class FeatureExtractorObj : public ffi::Object {
39 public:
41 virtual ~FeatureExtractorObj() = default;
42
43 static void RegisterReflection() {
44 namespace refl = tvm::ffi::reflection;
45 refl::ObjectDef<FeatureExtractorObj>();
46 }
47
54 virtual ffi::Array<tvm::ffi::Tensor> ExtractFrom(
55 const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates) = 0;
56 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.FeatureExtractor", FeatureExtractorObj,
57 ffi::Object);
58};
59
62 public:
69 using FExtractFrom = ffi::TypedFunction<ffi::Array<tvm::ffi::Tensor>(
70 const TuneContext& context, const ffi::Array<MeasureCandidate>& candidates)>;
73
74 static void RegisterReflection() {
75 // `f_extract_from` is not registered
76 namespace refl = tvm::ffi::reflection;
77 refl::ObjectDef<PyFeatureExtractorObj>();
78 }
79
80 ffi::Array<tvm::ffi::Tensor> ExtractFrom(const TuneContext& context,
81 const ffi::Array<MeasureCandidate>& candidates) final;
82 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyFeatureExtractor", PyFeatureExtractorObj,
84};
85
90class FeatureExtractor : public ffi::ObjectRef {
91 public:
92 explicit FeatureExtractor(ffi::UnsafeInit tag, ffi::ObjectPtr<FeatureExtractorObj> data)
93 : ffi::ObjectRef(tag) {
94 data_ = std::move(data);
95 }
96
107 TVM_DLL static FeatureExtractor PerStoreFeature(int tensors_per_store = 5,
108 int arith_intensity_curve_num_samples = 10,
109 int cache_line_bytes = 64,
110 bool extract_workload = false);
120};
121
122} // namespace meta_schedule
123} // namespace s_tir
124} // namespace tvm
125
126#endif // TVM_S_TIR_META_SCHEDULE_FEATURE_EXTRACTOR_H_
Extractor for features from measure candidates for use in cost model.
Definition feature_extractor.h:38
virtual ffi::Array< tvm::ffi::Tensor > ExtractFrom(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates)=0
Extract features from the given measure candidate.
virtual ~FeatureExtractorObj()=default
Virtual destructor.
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.FeatureExtractor", FeatureExtractorObj, ffi::Object)
static void RegisterReflection()
Definition feature_extractor.h:43
Managed reference to FeatureExtractorObj.
Definition feature_extractor.h:90
FeatureExtractor(ffi::UnsafeInit tag, ffi::ObjectPtr< FeatureExtractorObj > data)
Definition feature_extractor.h:92
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FeatureExtractor, ffi::ObjectRef, FeatureExtractorObj)
static FeatureExtractor PyFeatureExtractor(PyFeatureExtractorObj::FExtractFrom f_extract_from)
Create a feature extractor with customized methods on the python-side.
static FeatureExtractor PerStoreFeature(int tensors_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 TensorStore.
The feature extractor with customized methods on the python-side.
Definition feature_extractor.h:61
FExtractFrom f_extract_from
The packed function to the ExtractFrom function.
Definition feature_extractor.h:72
ffi::TypedFunction< ffi::Array< tvm::ffi::Tensor >(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates)> FExtractFrom
Extract features from the given measure candidate.
Definition feature_extractor.h:70
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyFeatureExtractor", PyFeatureExtractorObj, FeatureExtractorObj)
ffi::Array< tvm::ffi::Tensor > ExtractFrom(const TuneContext &context, const ffi::Array< MeasureCandidate > &candidates) final
Extract features from the given measure candidate.
static void RegisterReflection()
Definition feature_extractor.h:74
Managed reference to TuneContextObj.
Definition tune_context.h:99
TIR expressions.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
Device-independent tensor allocation, copies, views and serialization.