Alexey-Yazev commented on code in PR #13997:
URL: https://github.com/apache/tvm/pull/13997#discussion_r1111577237
##########
src/relay/op/contrib/ethosu/pooling.cc:
##########
@@ -46,14 +46,27 @@ bool EthosuPoolingRel(const Array<Type>& types, int
num_inputs, const Attrs& att
const String operator_name = "ethosu_pooling";
- if (param->pooling_type != "AVG" && param->pooling_type != "MAX") {
+ if (param->pooling_type != "AVG" && param->pooling_type != "MAX" &&
+ param->pooling_type != "SUM") {
reporter->GetDiagCtx().EmitFatal(Diagnostic::Error(reporter->GetSpan())
<< "Invalid operator: expected " <<
operator_name
- << " type 'AVG' or 'MAX' but was " <<
param->pooling_type);
+ << " type 'AVG', 'MAX', or 'SUM' but was "
+ << param->pooling_type);
return false;
}
- CheckDataType(reporter, ifm->dtype, {DataType::UInt(8), DataType::Int(8)},
operator_name, "ifm",
+ auto max_avg_pooling_ifm_dtypes = {DataType::UInt(8), DataType::Int(8)};
+ auto sum_pooling_ifm_dtypes = {DataType::UInt(8), DataType::Int(8),
DataType::Int(16),
Review Comment:
C++ code style says:
> Favor concrete type declaration over auto as long as it is short.
How short should it be?
Is it ok to use
`std::initializer_list<DataType>`
or better
```
using DTypes = std::initializer_list<DataType>;
DTypes sum_pooling_ifm_dtypes
```
?
##########
python/tvm/relay/op/contrib/ethosu.py:
##########
@@ -1375,6 +1375,82 @@ def mean_pattern() ->
tvm.relay.dataflow_pattern.DFPattern:
return pattern
+class SumParams:
+ """
+ This class will parse a call to ethosu.sum composite function
+ and extract the parameter information.
+ """
+
+ composite_name = "ethos-u.sum"
+
+ def __init__(self, func_body: Call):
+ from tvm.relay.backend.contrib.ethosu.util import RequantArgs
+
+ requantize = func_body
+ sum_op = requantize.args[0]
+ attrs = sum_op.attrs
+ cast = sum_op.args[0]
+
+ layout = "NHWC"
+ self.ifm = TensorParams(
+ cast.args[0],
+ layout,
+ requantize.args[RequantArgs.IFM_SCALE.value],
+ requantize.args[RequantArgs.IFM_ZERO_POINT.value],
+ )
+ self.ofm = TensorParams(
+ requantize,
+ layout,
+ requantize.args[RequantArgs.OFM_SCALE.value],
+ requantize.args[RequantArgs.OFM_ZERO_POINT.value],
+ )
+
+ ifm_shape = self.ifm.shape
+ self.height = ifm_shape[0] if len(ifm_shape) in (2, 3) else
ifm_shape[1]
+ self.width = ifm_shape[1] if len(ifm_shape) in (2, 3) else ifm_shape[2]
+ self.keepdims = attrs.keepdims
+
+ self.axis = list(sorted(attrs.axis))
+ if attrs.exclude:
+ self.axis = [i for i in range(len(self.ifm.shape)) if i not in
self.axis]
+
+ def is_valid(self) -> bool:
+ """
+ Checks whether Sum has compatible attributes with HW.
+ """
+
+ ifm_shape_len = len(self.ifm.shape)
+
+ if not check_valid_dtypes([self.ifm], [np.uint8, np.int8, np.int16,
np.int32]):
+ return False
+ if not check_valid_dtypes([self.ofm], [np.int8]):
+ return False
+ if not ifm_shape_len in (3, 4):
+ return False
+ if ifm_shape_len == 3 and self.axis not in [[2]]:
+ return False
+ if ifm_shape_len == 4 and self.axis not in [[3]]:
+ return False
+
+ return True
+
+
+def sum_pattern() -> tvm.relay.dataflow_pattern.DFPattern:
Review Comment:
Yes
--
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]