d-smirnov commented on a change in pull request #6724:
URL: https://github.com/apache/incubator-tvm/pull/6724#discussion_r518072473
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -289,24 +293,57 @@ def qnn_dense(attrs, args):
return False
if attrs.out_dtype != "int32":
return False
- return True
+
+ return not padding_required([*args, out_type])
@tvm.ir.register_op_attr("nn.max_pool2d", "target.arm_compute_lib")
-def max_pool2d(attrs, args):
+def max_pool2d(attrs, args, out_type):
"""Check if the external ACL codegen for maxpool2d should be used."""
if attrs.layout != "NHWC":
return False
typ = args[0].checked_type
if typ.dtype not in ["float32", "uint8"]:
return False
- return True
+ return not padding_required([*args, out_type])
+
+
+def padding_required(inputs):
Review comment:
>require_padding might be more straightforward?
renamed
Agreed, all the current versions of ACL should use the fix, until migration
to ACL 20.11 (when it became available)
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -289,24 +293,57 @@ def qnn_dense(attrs, args):
return False
if attrs.out_dtype != "int32":
return False
- return True
+
+ return not padding_required([*args, out_type])
@tvm.ir.register_op_attr("nn.max_pool2d", "target.arm_compute_lib")
-def max_pool2d(attrs, args):
+def max_pool2d(attrs, args, out_type):
"""Check if the external ACL codegen for maxpool2d should be used."""
if attrs.layout != "NHWC":
return False
typ = args[0].checked_type
if typ.dtype not in ["float32", "uint8"]:
return False
- return True
+ return not padding_required([*args, out_type])
+
+
+def padding_required(inputs):
+ """Checks whether supplied data will require padding.
+ Most of the operators ACL up to 20.11 uses padded data.
+ """
+
+ def _check(shape, dtype):
+ """NEON has 128bits/16bytes per vector"""
+ if len(shape) == 0:
+ return False
+ return (shape[-1] * np.dtype(dtype).itemsize) % 16 != 0
+
+ def _padding_required():
+ for i in inputs:
+ if isinstance(i, (tvm.relay.expr.Var, tvm.relay.expr.Call)):
+ if _check(i.checked_type.shape, i.checked_type.dtype):
+ return True
+ elif isinstance(i, tvm.relay.expr.Constant):
+ if _check(i.data.shape, i.data.dtype):
+ return True
+ elif isinstance(i, tvm.ir.tensor_type.TensorType):
+ if _check(i.shape, i.dtype):
+ return True
+ else:
+ raise Exception("Not supported")
+
+ return False
+
+ result = _padding_required()
Review comment:
refactored
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]