You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/10/28 17:12:48 UTC

[GitHub] [tvm] NicolaLancellotti commented on a change in pull request #9384: Arm(R) Ethos(TM)-U NPU Pooling operators support

NicolaLancellotti commented on a change in pull request #9384:
URL: https://github.com/apache/tvm/pull/9384#discussion_r738595291



##########
File path: python/tvm/relay/backend/contrib/ethosu/te/pooling.py
##########
@@ -0,0 +1,134 @@
+# 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.
+# pylint: disable=invalid-name,unused-argument
+"""Tensor Expressions for poolings"""
+from typing import Tuple
+
+from tvm import te
+from .dma import dma_ofm_compute, dma_ifm_compute
+
+
+def pooling_compute(
+    ifm: te.Tensor,
+    lut: te.Tensor,
+    pooling_type: str,
+    ifm_scale: float,
+    ifm_zero_point: int,
+    ofm_scale: float,
+    ofm_zero_point: int,
+    pool_shape: Tuple[int, int],
+    ofm_channels: int,
+    strides: Tuple[int, int],
+    padding: Tuple[int, int, int, int],
+    activation: str,
+    clip_min: int,
+    clip_max: int,
+    upscale: str,
+    ifm_layout: str,
+    ofm_layout: str,
+) -> te.Tensor:
+    """A compute operator representing the capabilities of pooling for the NPU.
+
+    Parameters
+    ----------
+    ifm : te.Tensor
+        The Input Feature Map tensor (IFM).
+    lut : te.Tensor
+        The look-up table values to use if activation = "LUT".
+    pooling_type: str
+        The type of the pooling. "AVG" - average pool,   "MAX" - max pool.
+    ifm_scale : float
+        The quantization scale for the Input Feature Map tensor.
+    ifm_zero_point : int
+        The quantization zero point for the Input Feature Map tensor.
+    ofm_scale : float
+        The quantization scale for the Output Feature Map tensor.
+    ofm_zero_point : int
+        The quantization zero point for the Output Feature Map tensor.
+    pool_shape : Tuple[int, int]
+        The 2 dimensional pool shape as (pool_shape_height, pool_shape_width).
+    ofm_channels : int
+        The number of OFM channels
+    strides : Tuple[int, int]
+        The 2 dimensional strides as (stride_height, stride_width).
+    padding : Tuple[int, int, int, int]
+        The 4 dimensional padding as (pad_top, pad_left, pad_bottom, pad_right).
+    activation : str
+        The activation function to use.
+            "NONE" - no activation function.
+            "CLIP" - clip the output between clip_min and clip_max.
+            "TANH" - tanh activation function.
+            "SIGMOID" - sigmoid activation function.
+            "LUT" - use a look-up table to perform the activation function.
+    clip_min : int
+        The minimum clipping value if activation = "CLIP".
+    clip_max : int
+        The maximum clipping value if activation = "CLIP".
+    upscale : str
+        The 2x2 upscaling mode to apply to the Input Feature Map tensor.
+            "NONE" - no upscaling.
+            "NEAREST" - upscale using nearest neighbour.
+            "ZEROS" - upscale using zeros.
+    ifm_layout : str
+        The layout of the Input Feature Map tensor. Can be "NHWC" or "NHCWB16".
+    ofm_layout : str
+        The layout of the Output Feature Map tensor. Can be "NHWC" or "NHCWB16".
+
+    Returns
+    -------
+    te.Tensor
+        The OFM tensor.
+    """
+    assert ifm.shape[0] == 1, f"Only batch size 1 is supported"

Review comment:
       No, these asserts are not reachable.

##########
File path: python/tvm/relay/backend/contrib/ethosu/util.py
##########
@@ -75,6 +75,15 @@ class ClipArgs(Enum):
     A_MAX = 2
 
 
+class MaxPoolArgs(Enum):
+    """
+    This is a helper enums to access the correct index
+    of max pool arguments
+    """
+
+    ifm = 0
+
+

Review comment:
       I agree, I'll remove it.

##########
File path: python/tvm/relay/backend/contrib/ethosu/util.py
##########
@@ -75,6 +75,15 @@ class ClipArgs(Enum):
     A_MAX = 2
 
 
+class MaxPoolArgs(Enum):
+    """
+    This is a helper enums to access the correct index
+    of max pool arguments
+    """
+
+    ifm = 0
+
+

Review comment:
       The same as above.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org