aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/cascade_builder.py
diff options
context:
space:
mode:
authorJohan Alfvén <johan.alfven@arm.com>2022-10-21 11:21:38 +0200
committerJohan Alfvén <johan.alfven@arm.com>2022-10-25 15:31:08 +0200
commit0f2e59f8bff0ca68794db1406e1264531da1d3a5 (patch)
treeef3c4420dd5fe47c9cd5cc1cd6bb79082962b923 /ethosu/vela/cascade_builder.py
parent2a285fca30d13f6577ef3e8154aea24713d728a5 (diff)
downloadethos-u-vela-0f2e59f8bff0ca68794db1406e1264531da1d3a5.tar.gz
MLBEDSW-7028: Fix compiler assert for elementwise op
- Refactored erroneously if statement that allowed illegal swapping between ifm1 and ifm2 for elementwise operators. Signed-off-by: Johan Alfven <johan.alfven@arm.com> Change-Id: Iec571f710824432edac9104d960f199f33a1b241
Diffstat (limited to 'ethosu/vela/cascade_builder.py')
-rw-r--r--ethosu/vela/cascade_builder.py29
1 files changed, 9 insertions, 20 deletions
diff --git a/ethosu/vela/cascade_builder.py b/ethosu/vela/cascade_builder.py
index b042ba73..5573ff7b 100644
--- a/ethosu/vela/cascade_builder.py
+++ b/ethosu/vela/cascade_builder.py
@@ -16,7 +16,6 @@
#
# Description:
# Groups Operators in a schedule together to form Cascades.
-from .high_level_command_to_npu_op import ifm_ifm2_correct_order
from .live_range import ofm_can_reuse_ifm
from .numeric_util import round_up
from .operation import NpuBlockType
@@ -98,7 +97,7 @@ class CascadeBuilder:
and cost.stripe.height < sched_op.ofm.shape.height
and sched_op.parent_op.read_offsets[0] is None
and sched_op.parent_op.read_offsets[1] is None
- and self.elementwise_cascading_correct_order(sched_op)
+ and self.elementwise_cascadable(sched_op)
and not sched_op.parent_op.type.is_resize_op()
and not sched_op.parent_op.type == Op.Conv2DBackpropInputSwitchedBias
and sched_op.parent_op.attrs.get("padding", None) != Padding.TILE
@@ -127,31 +126,21 @@ class CascadeBuilder:
return ifm_size + ifm2_size + ofm_size + self.non_local_mem_usage.get(sched_op, 0)
@staticmethod
- def elementwise_cascading_conformity(sched_op):
- """Check the inputs of the op to see if it's a candidate for cascading."""
+ def elementwise_cascadable(sched_op):
+ """Check if the elementwise can be cascaded."""
if sched_op.parent_op.type.is_binary_elementwise_op():
- # We cannot rule out cascadability if at least one IFM is constant
ifm = sched_op.parent_op.ifm
ifm2 = sched_op.parent_op.ifm2
- ifm_const = ifm.ops != [] and ifm.ops[0].type == Op.Const
- ifm2_const = ifm2.ops != [] and ifm2.ops[0].type == Op.Const
- return ifm_const or ifm2_const
- else:
- # Either one IFM is not variable or it is not a binary elementwise op - we cannot rule out cascadability
- return True
+ ofm = sched_op.parent_op.ofm
- @staticmethod
- def elementwise_cascading_correct_order(sched_op):
- """Check the inputs of the op to see ifm and ifm2 has correct order."""
+ # IFM must be non-constant/non-scalar/non-broadcast
+ ifm_cascadable = not (ifm.is_const or ifm.is_scalar or ifm.is_broadcast(ofm))
- if sched_op.parent_op.type.is_binary_elementwise_op():
- ifm2 = sched_op.parent_op.ifm2
- ifm2_const = ifm2.ops != [] and ifm2.ops[0].type == Op.Const
+ # IFM2 must be constant or scalar
+ ifm2_cascadable = ifm2.is_const or ifm2.is_scalar
- # ifm_ifm2_correct_order needs full shape
- correct_order = ifm_ifm2_correct_order(sched_op.ifm.shape, sched_op.ifm2.shape)
- return ifm2_const and correct_order
+ return ifm_cascadable and ifm2_cascadable
else:
return True