Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Meta Schedule] Per-Store-Feature #521

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion include/tvm/meta_schedule/feature_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,26 @@ class PyFeatureExtractorNode : public FeatureExtractorNode {
*/
class FeatureExtractor : public runtime::ObjectRef {
public:
/*!
* \brief Create a feature extractor that extracts features from each BufferStore
* \param buffers_per_store The number of buffers in each BufferStore; Pad or truncate if
* necessary.
* \param arith_intensity_curve_num_samples The number of samples used in the arithmetic intensity
* curve.
* \param cache_line_bytes The number of bytes in a cache line.
* \return The feature extractor created.
*/
TVM_DLL static FeatureExtractor PerStoreFeature(int buffers_per_store = 5,
int arith_intensity_curve_num_samples = 10,
int cache_line_bytes = 64);
/*!
* \brief Create a feature extractor with customized methods on the python-side.
* \param f_extract_from The packed function of `ExtractFrom`.
* \param f_as_string The packed function of `AsString`.
* \return The feature extractor created.
*/
TVM_DLL static FeatureExtractor PyFeatureExtractor(
PyFeatureExtractorNode::FExtractFrom f_extract_from, //
PyFeatureExtractorNode::FExtractFrom f_extract_from,
PyFeatureExtractorNode::FAsString f_as_string);
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(FeatureExtractor, ObjectRef, FeatureExtractorNode);
};
Expand Down
1 change: 1 addition & 0 deletions python/tvm/meta_schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
from . import feature_extractor
from . import cost_model
from .tune_context import TuneContext
from .search_strategy import MeasureCandidate
1 change: 1 addition & 0 deletions python/tvm/meta_schedule/feature_extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
measure candidates for use in cost model.
"""
from .feature_extractor import FeatureExtractor, PyFeatureExtractor
from .per_store_feature import PerStoreFeature
71 changes: 71 additions & 0 deletions python/tvm/meta_schedule/feature_extractor/per_store_feature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""We extract one feature vector per BufferStoreNode statement in a TIR Stmt,
so we call this feature as "per-store" feature.
"""
from tvm._ffi import register_object

from .. import _ffi_api
from .feature_extractor import FeatureExtractor


# /*!
# * \brief Create a feature extractor that extracts features from each BufferStore
# * \param buffers_per_store The number of buffers in each BufferStore; Pad or truncate if
# * necessary.
# * \param arith_intensity_curve_num_samples The number of samples used in the arithmetic intensity
# * curve.
# * \param cache_line_bytes The number of bytes in a cache line.
# * \return The feature extractor created.
# */


@register_object("meta_schedule.PerStoreFeature")
class PerStoreFeature(FeatureExtractor):
"""PerStoreFeature extracts one feature vector per BufferStoreNode

Parameters
----------
buffers_per_store : int
The number of buffers in each BufferStore; Pad or truncate if necessary.
arith_intensity_curve_num_samples : int
The number of samples used in the arithmetic intensity curve.
cache_line_bytes : int
The number of bytes in a cache line.
"""

buffers_per_store: int
"""The number of buffers in each BufferStore; Pad or truncate if necessary."""
arith_intensity_curve_num_samples: int # pylint: disable=invalid-name
"""The number of samples used in the arithmetic intensity curve."""
cache_line_bytes: int
"""The number of bytes in a cache line."""
feature_vector_length: int
"""Length of the feature vector."""

def __init__(
self,
buffers_per_store: int = 5,
arith_intensity_curve_num_samples: int = 10,
cache_line_bytes: int = 64,
):
self.__init_handle_by_constructor__(
_ffi_api.FeatureExtractorPerStoreFeature, # type: ignore # pylint: disable=no-member
buffers_per_store,
arith_intensity_curve_num_samples,
cache_line_bytes,
)
Loading