From 2fa1588f9128e077ec02d195356e89eb17452f3f Mon Sep 17 00:00:00 2001 From: Patrik Gustavsson Date: Fri, 13 Nov 2020 09:02:31 +0100 Subject: MLBEDSW-3350 Put softmax on CPU if beta < 0 Put softmax on CPU if beta < 0 Signed-off-by: Patrik Gustavsson Change-Id: I4ec866dd44d14e2737c4cd96474e54bb770bfb3e --- ethosu/vela/supported_operators.py | 8 ++++++++ ethosu/vela/test/test_supported_operators.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/ethosu/vela/supported_operators.py b/ethosu/vela/supported_operators.py index b537b650..46f7a5d3 100644 --- a/ethosu/vela/supported_operators.py +++ b/ethosu/vela/supported_operators.py @@ -212,6 +212,7 @@ class SupportedOperators: # Softmax specific checks: self.specific_constraints[Op.Softmax].append(SupportedOperators.constraint_matching_shapes) self.specific_constraints[Op.Softmax].append(SupportedOperators.constraint_matching_in_out_types) + self.specific_constraints[Op.Softmax].append(SupportedOperators.constraint_beta_value_range) # SplitV specific checks: self.specific_constraints[Op.SplitV].append(SupportedOperators.constraint_splitv_inferred) @@ -559,6 +560,13 @@ class SupportedOperators: valid = ifm_dtype == ofm_dtype return valid, f"Op has ifm_dtype={ifm_dtype} and ofm_dtype={ofm_dtype}" + @staticmethod + def constraint_beta_value_range(op): + "Beta value needs to be positive" + beta = op.attrs.get("beta", 1.0) + valid = beta >= 0 + return valid, f"Op has beta={beta}" + @staticmethod def constraint_filter_type(op): "Kernel filter values for both width and height must be integer types" diff --git a/ethosu/vela/test/test_supported_operators.py b/ethosu/vela/test/test_supported_operators.py index 7e13f42d..62de0d1d 100644 --- a/ethosu/vela/test/test_supported_operators.py +++ b/ethosu/vela/test/test_supported_operators.py @@ -382,6 +382,15 @@ def test_constraint_matching_shapes(): assert support.is_operator_supported(op) +def test_constraint_beta_value_range(): + # beta must be positive + op = testutil.create_op_with_quant_tensors(Op.Softmax, [1, 1, 1, 8], [1, 1, 1, 8]) + op.attrs["beta"] = -1.0 + assert not support.is_operator_supported(op) + op.attrs["beta"] = 0.0 + assert support.is_operator_supported(op) + + def test_constraint_splitv_inferred(): # SplitV requires a maximum of one inferred shape (-1) qp = testutil.default_quant_params() -- cgit v1.2.1