merrymercy commented on a change in pull request #6190: URL: https://github.com/apache/incubator-tvm/pull/6190#discussion_r468359834
########## File path: python/tvm/auto_scheduler/feature.py ########## @@ -0,0 +1,242 @@ +# 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. + +"""" +Python API for Feature extraction. The extracted features vector are used by cost models. + +We extract one feature vector per BufferStoreNode statement in a TIR Stmt, +so we call this feature as "Per Store" feature. +The cost model also does prediction for each BufferStoreNode statement and aggregates +the predicted score of each BufferStoreNode as the score of a TIR Stmt. + +The feature specification is defined by `src/auto_scheduler/feature.cc::FeatureSet` +""" + +from typing import List, Tuple, Union, Optional +import struct + +import numpy as np + +from .loop_state import State, StateObject +from .measure import MeasureInput, MeasureResult +from . import _ffi_api + +# The maximum number of extracted buffers for one statement +DEFAULT_MAX_N_BUFS = 5 + +# The length of the feature vector +DEFAULT_FEATURE_VEC_LEN = 164 + +# The size of int and float in bytes +SIZE_OF_INT = 4 +SIZE_OF_FLOAT = 4 + +def unpack_feature(byte_arr: bytearray) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: + """Unpack the flatten feature (in byte array format) from c++ + + Parameters + ---------- + byte_arr: bytearray + The two-dimensional feature vector in serialized byte array format + + Returns + ------- + features: np.ndarray + Feature vectors + normalized_throughputs: np.ndarray + Normalized throughputs + task_ids: np.ndarray + Task ids + """ + + # The format for n records is: + # { + # int n; + # int[n+2] sizes Review comment: The `int sizes[n + 1]` proposed by you is not a valid declaration in C. I think the old comment is better. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
