|
| 1 | +# Copyright 2025 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 | + |
| 7 | +from typing import Dict, Tuple |
| 8 | + |
| 9 | +import torch |
| 10 | +from executorch.backends.arm.test import common |
| 11 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 12 | + EthosU55PipelineBI, |
| 13 | + EthosU85PipelineBI, |
| 14 | + TosaPipelineBI, |
| 15 | + TosaPipelineMI, |
| 16 | +) |
| 17 | + |
| 18 | +input_t1 = Tuple[torch.Tensor] |
| 19 | + |
| 20 | + |
| 21 | +class Neg(torch.nn.Module): |
| 22 | + |
| 23 | + aten_op = "torch.ops.aten.neg.default" |
| 24 | + exir_op = "executorch_exir_dialects_edge__ops_aten_neg_default" |
| 25 | + |
| 26 | + test_data: Dict[str, input_t1] = { |
| 27 | + "rank_1_ramp": (torch.arange(-16, 16, 0.2),), |
| 28 | + "rank_2_rand_uniform": (torch.rand(10, 10) - 0.5,), |
| 29 | + "rank_3_all_ones": (torch.ones(10, 10, 10),), |
| 30 | + "rank_4_all_zeros": (torch.zeros(1, 10, 10, 10),), |
| 31 | + "rank_4_randn_pos": (torch.randn(1, 4, 4, 4) + 10,), |
| 32 | + "rank_4_randn_neg": (torch.randn(1, 4, 4, 4) - 10,), |
| 33 | + } |
| 34 | + |
| 35 | + def forward(self, x: torch.Tensor): |
| 36 | + return torch.neg(x) |
| 37 | + |
| 38 | + |
| 39 | +@common.parametrize("test_data", Neg.test_data) |
| 40 | +def test_neg_tosa_MI(test_data: input_t1): |
| 41 | + pipeline = TosaPipelineMI[input_t1](Neg(), test_data, Neg.aten_op, Neg.exir_op) |
| 42 | + pipeline.run() |
| 43 | + |
| 44 | + |
| 45 | +@common.parametrize("test_data", Neg.test_data) |
| 46 | +def test_neg_tosa_BI(test_data: input_t1): |
| 47 | + pipeline = TosaPipelineBI[input_t1](Neg(), test_data, Neg.aten_op, Neg.exir_op) |
| 48 | + pipeline.run() |
| 49 | + |
| 50 | + |
| 51 | +@common.parametrize("test_data", Neg.test_data) |
| 52 | +@common.XfailIfNoCorstone300 |
| 53 | +def test_neg_u55_BI(test_data: input_t1): |
| 54 | + pipeline = EthosU55PipelineBI[input_t1]( |
| 55 | + Neg(), test_data, Neg.aten_op, Neg.exir_op, run_on_fvp=True |
| 56 | + ) |
| 57 | + pipeline.run() |
| 58 | + |
| 59 | + |
| 60 | +@common.parametrize("test_data", Neg.test_data) |
| 61 | +@common.XfailIfNoCorstone320 |
| 62 | +def test_neg_u85_BI(test_data: input_t1): |
| 63 | + pipeline = EthosU85PipelineBI[input_t1]( |
| 64 | + Neg(), test_data, Neg.aten_op, Neg.exir_op, run_on_fvp=True |
| 65 | + ) |
| 66 | + pipeline.run() |
0 commit comments