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 2022/08/10 15:41:56 UTC

[GitHub] [tvm] ashutosh-arm commented on a diff in pull request #12353: [CMSIS-NN] Pad fusion with QNN Conv2D

ashutosh-arm commented on code in PR #12353:
URL: https://github.com/apache/tvm/pull/12353#discussion_r942611235


##########
python/tvm/relay/op/contrib/cmsisnn.py:
##########
@@ -122,6 +130,25 @@ def check_qnn_conv2d(pattern):
         conv2d_input = conv2d.args[0]
         conv2d_weight = conv2d.args[1]
 
+        # check if sum of paddings from pad() and conv2d() satisfies CMSIS-NN constraints
+        can_pad_be_fused = True
+        if isinstance(conv2d_input, tvm.relay.expr.Call) and str(conv2d_input.op.name) == "nn.pad":
+            data_layout = conv2d.attrs.data_layout
+            conv2d_padding = conv2d.attrs.padding  # (top, left, bottom, right)
+            pad = conv2d_input
+            pad_width = pad.attrs.pad_width
+            pad_width_w = pad_width[data_layout.find("W")]  # (left, right)
+            pad_width_h = pad_width[data_layout.find("H")]  # (top, bottom)
+            # calculate effective padding post pad fusion
+            pad_top = pad_width_h[0] + conv2d_padding[0]
+            pad_bottom = pad_width_h[1] + conv2d_padding[2]
+            pad_left = pad_width_w[0] + conv2d_padding[1]
+            pad_right = pad_width_w[1] + conv2d_padding[3]
+            # check if difference in the side paddings is 1 along each dimension
+            pad_w_diff = int(pad_right - pad_left)

Review Comment:
   They are IntImm. When they are used in conditional checks, it returns IntImm in place of boolean which is what we'd expect normally. We have seen this in the past too: https://github.com/apache/tvm/blob/22ba659438a317ca59c8201430c662f86e2550fd/python/tvm/relay/op/contrib/cmsisnn.py#L134 



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