From 9456f95accdcee20a30bde73ddadf49d70e3b11a Mon Sep 17 00:00:00 2001 From: Luke Hutton Date: Thu, 30 Jun 2022 13:40:09 +0100 Subject: [PATCH] [microNPU] Fix offloading incompatible average pool (#11469) Fixes offloading a few corner cases of average pooling. Specifically not offloading nn.avg_pool2d when: * The attribute count_include_pad=True * Padding exceeds the dimensions [3, 3, 4, 4] * The pool size is greater than [8, 8] when the pool uses padding Change-Id: I7be546e28ebe1f17482f3ed3cee56996a71bfcd1 --- python/tvm/relay/op/contrib/ethosu.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/tvm/relay/op/contrib/ethosu.py b/python/tvm/relay/op/contrib/ethosu.py index 806bf6dce2e8..4c3dcc2fc45a 100644 --- a/python/tvm/relay/op/contrib/ethosu.py +++ b/python/tvm/relay/op/contrib/ethosu.py @@ -613,7 +613,7 @@ class AvgPool2DParams: composite_name = "ethos-u.avgpool2d" # The hardware only supports padding upto the numbers as follows - padding_bounds = [127, 127, 128, 128] + padding_bounds = [3, 3, 4, 4] def __init__(self, func_body: Call): clip = None @@ -632,6 +632,7 @@ def __init__(self, func_body: Call): self.pool_shape = attrs.pool_size self.strides = attrs.strides self.padding = attrs.padding + self.count_include_pad = attrs.count_include_pad self.activation = clip self.pooling_type = "AVG" @@ -648,10 +649,17 @@ def is_valid(self): return False if not check_batch_size(self.ifm): return False + if self.count_include_pad: + return False if not check_padding(self.padding, self.padding_bounds): return False if not check_pool_shape(self.pool_shape): return False + # Averge pool with padding only supports 1 <= pool_shape <= 8 + if list(self.padding) != [0, 0, 0, 0] and ( + self.pool_shape[0] > 8 or self.pool_shape[1] > 8 + ): + return False return True