|
| 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 | + |
| 19 | +class Sqrt(torch.nn.Module): |
| 20 | + input_t = Tuple[torch.Tensor] |
| 21 | + aten_op_MI = "torch.ops.aten.sqrt.default" |
| 22 | + exir_op_MI = "executorch_exir_dialects_edge__ops_aten_pow_Tensor_Tensor" |
| 23 | + |
| 24 | + aten_op_BI = "torch.ops.aten.pow.Tensor_Scalar" |
| 25 | + exir_op_BI = "executorch_exir_dialects_edge__ops_aten_pow_Tensor_Scalar" |
| 26 | + |
| 27 | + def __init__(self): |
| 28 | + super().__init__() |
| 29 | + |
| 30 | + def forward(self, x): |
| 31 | + return torch.sqrt(x) |
| 32 | + |
| 33 | + test_data: Dict[str, input_t] = { |
| 34 | + "sqrt_tensor_rank1_ones": (torch.ones(10),), |
| 35 | + "sqrt_tensor_rank2_random": (torch.rand(5, 10),), |
| 36 | + "sqrt_tensor_rank3_ones": (torch.ones(2, 3, 4),), |
| 37 | + "sqrt_tensor_rank4_random": (torch.rand(1, 3, 8, 8),), |
| 38 | + "sqrt_tensor_rank4_multibatch": (torch.rand(2, 3, 4, 4),), |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | +fvp_xfails = { |
| 43 | + "sqrt_tensor_rank4_multibatch": "MLETORCH-517 : Multiple batches not supported", |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +@common.parametrize("test_data", Sqrt.test_data) |
| 48 | +def test_sqrt_tosa_MI(test_data: Sqrt.input_t): |
| 49 | + pipeline = TosaPipelineMI[Sqrt.input_t]( |
| 50 | + Sqrt(), test_data, Sqrt.aten_op_MI, Sqrt.exir_op_MI |
| 51 | + ) |
| 52 | + pipeline.run() |
| 53 | + |
| 54 | + |
| 55 | +@common.parametrize("test_data", Sqrt.test_data) |
| 56 | +def test_sqrt_tosa_BI(test_data: Sqrt.input_t): |
| 57 | + pipeline = TosaPipelineBI[Sqrt.input_t]( |
| 58 | + Sqrt(), test_data, Sqrt.aten_op_BI, Sqrt.exir_op_BI |
| 59 | + ) |
| 60 | + pipeline.run() |
| 61 | + |
| 62 | + |
| 63 | +@common.parametrize("test_data", Sqrt.test_data, fvp_xfails) |
| 64 | +@common.XfailIfNoCorstone300 |
| 65 | +def test_sqrt_u55_BI(test_data: Sqrt.input_t): |
| 66 | + pipeline = EthosU55PipelineBI[Sqrt.input_t]( |
| 67 | + Sqrt(), test_data, Sqrt.aten_op_BI, Sqrt.exir_op_BI, run_on_fvp=True |
| 68 | + ) |
| 69 | + pipeline.run() |
| 70 | + |
| 71 | + |
| 72 | +@common.parametrize("test_data", Sqrt.test_data, fvp_xfails) |
| 73 | +@common.XfailIfNoCorstone320 |
| 74 | +def test_sqrt_u85_BI(test_data: Sqrt.input_t): |
| 75 | + pipeline = EthosU85PipelineBI[Sqrt.input_t]( |
| 76 | + Sqrt(), test_data, Sqrt.aten_op_BI, Sqrt.exir_op_BI, run_on_fvp=True |
| 77 | + ) |
| 78 | + pipeline.run() |
0 commit comments