|
| 1 | +# Copyright 2026 Arm Limited and/or its affiliates. |
| 2 | +# |
| 3 | +# This source code is licensed under the BSD-style license found in the |
| 4 | +# LICENSE file in the root directory of this source tree. |
| 5 | + |
| 6 | +from typing import Tuple |
| 7 | + |
| 8 | +import torch |
| 9 | + |
| 10 | +from executorch.backends.arm.test import common |
| 11 | +from executorch.backends.arm.test.tester.arm_tester import ArmTester |
| 12 | +from executorch.backends.arm.test.tester.test_pipeline import EthosU55PipelineINT |
| 13 | + |
| 14 | + |
| 15 | +input_t1 = Tuple[torch.Tensor] |
| 16 | + |
| 17 | +test_data_suite_u55 = { |
| 18 | + "both_axes": lambda: (torch.rand(1, 2, 4, 3), (1, 1, 1, 1)), |
| 19 | + "width_only": lambda: (torch.rand(1, 2, 4, 3), (1, 1, 0, 0)), |
| 20 | + "height_only": lambda: (torch.rand(1, 2, 4, 3), (0, 0, 1, 1)), |
| 21 | + "asymmetric": lambda: (torch.rand(1, 2, 5, 4), (1, 2, 3, 1)), |
| 22 | + "maximum_legal": lambda: (torch.rand(1, 2, 4, 3), (2, 2, 3, 3)), |
| 23 | + "batched": lambda: (torch.rand(2, 2, 4, 3), (1, 1, 1, 1)), |
| 24 | +} |
| 25 | + |
| 26 | + |
| 27 | +class ReflectionPad2d(torch.nn.Module): |
| 28 | + def __init__(self, padding): |
| 29 | + super().__init__() |
| 30 | + self.padding = padding |
| 31 | + |
| 32 | + def forward(self, x): |
| 33 | + return torch.nn.functional.pad(x, self.padding, mode="reflect") |
| 34 | + |
| 35 | + |
| 36 | +@common.parametrize("test_data", test_data_suite_u55) |
| 37 | +@common.XfailIfNoCorstone300 |
| 38 | +def test_reflection_pad2d_u55_INT(test_data): |
| 39 | + data, padding = test_data() |
| 40 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 41 | + ReflectionPad2d(padding), |
| 42 | + (data,), |
| 43 | + aten_ops=[], |
| 44 | + exir_ops=[], |
| 45 | + ) |
| 46 | + pipeline.run() |
| 47 | + |
| 48 | + |
| 49 | +@common.XfailIfNoCorstone300 |
| 50 | +def test_reflection_pad2d_u55_INT_a16w8(): |
| 51 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 52 | + ReflectionPad2d((1, 1, 1, 1)), |
| 53 | + (torch.rand(1, 2, 4, 3),), |
| 54 | + aten_ops=[], |
| 55 | + exir_ops=[], |
| 56 | + a16w8_quantization=True, |
| 57 | + ) |
| 58 | + pipeline.run() |
| 59 | + |
| 60 | + |
| 61 | +@common.XfailIfNoCorstone300 |
| 62 | +def test_reflection_pad2d_u55_INT_rank3(): |
| 63 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 64 | + ReflectionPad2d((1, 1, 1, 1)), |
| 65 | + (torch.rand(2, 4, 3),), |
| 66 | + aten_ops=[], |
| 67 | + exir_ops=[], |
| 68 | + ) |
| 69 | + pipeline.run() |
| 70 | + |
| 71 | + |
| 72 | +def test_reflection_pad2d_u55_INT_symbolic_width_not_delegated(): |
| 73 | + width = torch.export.Dim("width", min=3, max=8) |
| 74 | + tester = ArmTester( |
| 75 | + ReflectionPad2d((1, 1, 1, 1)), |
| 76 | + (torch.rand(1, 2, 4, 5),), |
| 77 | + common.get_u55_compile_spec(), |
| 78 | + dynamic_shapes={"x": {3: width}}, |
| 79 | + ) |
| 80 | + tester.quantize().export().to_edge().partition() |
| 81 | + |
| 82 | + targets = { |
| 83 | + node.target |
| 84 | + for node in tester.stages[tester.cur].artifact.exported_program().graph.nodes |
| 85 | + } |
| 86 | + assert torch.ops.aten.scalar_tensor.default in targets |
| 87 | + assert torch.ops.higher_order.executorch_call_delegate not in targets |
0 commit comments