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



##########
File path: python/tvm/relay/op/contrib/ethosu.py
##########
@@ -331,6 +332,133 @@ def qnn_depthwise_conv2d_pattern() -> 
tvm.relay.dataflow_pattern.DFPattern:
     return clip_or_req
 
 
+class MaxPool2DParams:
+    """
+    This class will parse a call to a ethosu.maxpool2d composite function
+    and extract the parameter information.
+    """
+
+    composite_name = "ethosu.maxpool2d"
+    # The hardware only supports padding upto the numbers as follows
+    padding_bounds = [127, 127, 128, 128]
+
+    def __init__(self, func_body: Call):
+        clip = None
+        if str(func_body.op) == "clip":
+            clip = func_body
+            pool_op = clip.args[0]
+        else:
+            pool_op = func_body
+
+        attrs = pool_op.attrs
+        self.ifm = TensorParams(pool_op.args[MaxPoolArgs.ifm.value], 
attrs.layout)
+        self.ofm = TensorParams(pool_op, attrs.layout)
+        self.pool_shape = [int(i) for i in attrs.pool_size]
+        self.strides = attrs.strides
+        self.padding = attrs.padding
+        self.activation = clip
+        self.pooling_type = "MAX"
+
+    def is_valid(self):
+        """
+        This function checks whether MaxPool2D has compatible attributes with 
the NPU
+        """
+        tensor_params = [self.ifm, self.ofm]
+        if not check_valid_dtypes(tensor_params):
+            return False
+        if self.ifm.dtype != self.ofm.dtype:
+            return False
+        if not check_strides(self.strides):
+            return False
+        if not check_batch_size(self.ifm):
+            return False
+        if not check_padding(self.padding, self.padding_bounds):
+            return False
+        # Check pool size
+        if (
+            len(self.pool_shape) != 2
+            or self.pool_shape[1] > 256
+            or self.pool_shape[0] * self.pool_shape[1] > 256 * 256
+        ):
+            return False
+        return True

Review comment:
       Just to illustrate this a bit further, following the same pattern would 
be:
   ```python
   if len(self.pool_shape) != 2:
     return False
   if self.pool_shape[1] > 256:
     return False
   if self.pool_shape[0] * self.pool_shape[1] > 256 * 256:
     return False
   ```
   
   Which I think is way uglier than either solution, but leads me to believe 
these are just a bunch of "final checks" which can come within a final return 
rather than a large `if` condition.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to