Skip to content

Commit 4cf0207

Browse files
committed
Arm backend: Delegate partial flip ops on U55
Allow the U55 channel and height reverse cases verified through Vela and Corstone-300, while preserving explicit fallback for unsupported flip axes. Authored with Codex. Change-Id: Ic4d9014cf4812165330924899a5f919c7c6a189a Signed-off-by: Per Held <per.held@arm.com>
1 parent ad9902c commit 4cf0207

3 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎backends/arm/operator_support/ethos_u55_support.py‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ class EthosU55NotSupported(OperatorSupportBase):
197197
exir_ops.edge.aten.lt.Scalar,
198198
exir_ops.edge.aten.ne.Tensor,
199199
exir_ops.edge.aten.ne.Scalar,
200-
exir_ops.edge.aten.flip.default, # REVERSE
201200
exir_ops.edge.aten.gather.default, # GATHER
202201
exir_ops.edge.aten.grid_sampler_2d, # GATHER
203202
exir_ops.edge.aten.index.Tensor, # GATHER
@@ -336,6 +335,30 @@ def is_node_supported(
336335
return False
337336

338337

338+
class EthosU55ReverseCheck(OperatorSupportBase):
339+
"""Accept the REVERSE cases proven to run on Ethos-U55."""
340+
341+
def __init__(self, reporter: WhyNoPartitionReporter):
342+
self.reporter = reporter
343+
344+
def is_node_supported(
345+
self, submodules: typing.Mapping[str, torch.nn.Module], node: fx.Node
346+
) -> bool:
347+
del submodules
348+
if node.target == exir_ops.edge.aten.flip.default:
349+
input_rank = len(get_first_fake_tensor(node.all_input_nodes[0]).shape)
350+
dims = typing.cast(typing.Sequence[int], node.args[1])
351+
if input_rank == 4 and len(dims) == 1 and dims[0] % input_rank in (1, 2):
352+
return True
353+
self.reporter.report_reject(
354+
node,
355+
"U55 flip support is limited to rank-4 channel or height reversal.",
356+
)
357+
return False
358+
359+
return True
360+
361+
339362
class EthosU55CastCheck(OperatorSupportBase):
340363
"""Reject unsupported casts on U55.
341364

‎backends/arm/operator_support/tosa_supported_operators.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
EthosU55DtypeSupport,
4242
EthosU55NotSupported,
4343
EthosU55ResizeCheck,
44+
EthosU55ReverseCheck,
4445
)
4546
from executorch.backends.arm.operator_support.tosa_profile_supported_op_lists import (
4647
TOSA_PRO_FP_SupportList,
@@ -365,6 +366,7 @@ def _negative_checks(
365366
if tosa_spec.is_U55_subset:
366367
checks.append(EthosU55NotSupported(reporter))
367368
checks.append(EthosU55ResizeCheck(reporter))
369+
checks.append(EthosU55ReverseCheck(reporter))
368370
checks.append(EthosU55DtypeSupport(reporter))
369371
checks.append(EthosU55CastCheck(reporter))
370372

‎backends/arm/test/ops/test_flip.py‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
get_symmetric_a16w8_quantization_config,
1313
)
1414
from executorch.backends.arm.test import common
15+
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1516
from executorch.backends.arm.test.tester.test_pipeline import (
17+
EthosU55PipelineINT,
1618
EthosU85PipelineINT,
1719
OpNotSupportedPipeline,
1820
TosaPipelineFP,
1921
TosaPipelineINT,
2022
VgfPipeline,
2123
)
24+
from executorch.exir.dialects._ops import ops as exir_ops
2225

2326
aten_op = "torch.ops.aten.flip.default"
2427
exir_op = "executorch_exir_dialects_edge__ops_aten_flip_default"
@@ -60,9 +63,9 @@
6063
),
6164
}
6265

63-
# U55 has no REVERSE, so flip must not be delegated there.
66+
# U55 supports selected REVERSE axes; width-axis flip remains unsupported.
6467
test_data_suite_u55_reject = {
65-
"rank4_dim2": lambda: (torch.rand(2, 3, 4, 5), [2]),
68+
"rank4_dim3": lambda: (torch.rand(1, 3, 4, 5), [3]),
6669
}
6770

6871
# flip over no dims is the identity;
@@ -172,6 +175,30 @@ def test_flip_u55_INT_not_delegated(test_data):
172175
pipeline.run()
173176

174177

178+
@common.XfailIfNoCorstone300
179+
def test_flip_u55_INT_height():
180+
data = torch.rand(1, 3, 4, 5)
181+
pipeline = EthosU55PipelineINT[input_t1](
182+
Flip([2]),
183+
(data,),
184+
aten_ops=[],
185+
exir_ops=[],
186+
)
187+
pipeline.run()
188+
189+
190+
@common.XfailIfNoCorstone300
191+
def test_flip_u55_INT_channel():
192+
data = torch.rand(1, 3, 4, 5)
193+
pipeline = EthosU55PipelineINT[input_t1](
194+
Flip([1]),
195+
(data,),
196+
aten_ops=[],
197+
exir_ops=[],
198+
)
199+
pipeline.run()
200+
201+
175202
@common.parametrize("test_data", test_data_suite_empty)
176203
def test_flip_empty_dims_not_delegated(test_data):
177204
"""Flip over no dims is the identity."""
@@ -224,3 +251,21 @@ def test_flip_vgf_quant(test_data):
224251
quantize=True,
225252
)
226253
pipeline.run()
254+
255+
256+
def test_flip_u55_INT_symbolic_height_not_delegated():
257+
height = torch.export.Dim("height", min=3, max=8)
258+
tester = ArmTester(
259+
Flip([2]),
260+
(torch.rand(1, 3, 4, 5),),
261+
common.get_u55_compile_spec(),
262+
dynamic_shapes={"x": {2: height}},
263+
)
264+
tester.quantize().export().to_edge().partition()
265+
266+
targets = {
267+
node.target
268+
for node in tester.stages[tester.cur].artifact.exported_program().graph.nodes
269+
}
270+
assert exir_ops.edge.aten.flip.default in targets
271+
assert torch.ops.higher_order.executorch_call_delegate not in targets

0 commit comments

Comments
 (0)