From c74682cfd27eb2c203ce4486e712916c45da9881 Mon Sep 17 00:00:00 2001 From: Patrik Gustavsson Date: Tue, 17 Aug 2021 14:26:38 +0200 Subject: TOSA: Support for AVGPOOL, MAXPOOL and CONV2D Added support for -AVGPOOL and CONV2D with TFLite correspondence -MAXPOOL -additional support for replacing RESCALE ops with avgpool. No support for breaking down tensors over the size supported by NPU. Signed-off-by: Patrik Gustavsson Change-Id: I1d2aa50ac30a26283b3e6f1fe88cba1544b7c189 --- ethosu/vela/graph_optimiser_util.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ethosu/vela/graph_optimiser_util.py') diff --git a/ethosu/vela/graph_optimiser_util.py b/ethosu/vela/graph_optimiser_util.py index 5e676f18..570c7244 100644 --- a/ethosu/vela/graph_optimiser_util.py +++ b/ethosu/vela/graph_optimiser_util.py @@ -15,6 +15,8 @@ # limitations under the License. # Description: # Common functions and definitions used during the graph optimization. +from typing import Tuple + from .data_type import DataType from .debug_database import DebugDatabase from .errors import VelaError @@ -132,6 +134,21 @@ def check_format_restrictions(tens, arch): tens.needs_linear_format = False +def calc_explicit_padding(input_size, stride, filter_size, pad_before, pad_after) -> Tuple[int, int]: + """ + Based on explicit padding provided in a PAD operation, returns the corresponding hardware padding + that provides equivalent results. + """ + total_padding = needed_total_padding(input_size, stride, filter_size) + + # The bottom/right padding might need downward adjustment depending on stride/input size + total_minus_before = total_padding - pad_before + output_pad_after = pad_after + while output_pad_after > 0 and output_pad_after % stride != total_minus_before % stride: + output_pad_after -= 1 + return pad_before, output_pad_after + + def needed_total_padding(input_size, stride, filter_size): out_size = (input_size + stride - 1) // stride needed_input = (out_size - 1) * stride + filter_size -- cgit v1.2.1