|
| 1 | +# Copyright 2025 Arm Limited and/or its affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +from typing import Tuple |
| 8 | + |
| 9 | +import torch |
| 10 | + |
| 11 | +from executorch.backends.arm.test import common, conftest |
| 12 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 13 | + EthosU55PipelineBI, |
| 14 | + EthosU85PipelineBI, |
| 15 | + TosaPipelineBI, |
| 16 | + TosaPipelineMI, |
| 17 | +) |
| 18 | + |
| 19 | +aten_op = "torch.ops.aten.cos.default" |
| 20 | +input_t1 = Tuple[torch.Tensor] # Input x |
| 21 | + |
| 22 | +test_data_suite = { |
| 23 | + # (test_name, test_data) |
| 24 | + "zeros": torch.zeros(10, 10, 10, 10), |
| 25 | + "ones": torch.ones(10, 10, 10), |
| 26 | + "rand": torch.rand(10, 10) - 0.5, |
| 27 | + "randn_pos": torch.randn(10) + 10, |
| 28 | + "randn_neg": torch.randn(10) - 10, |
| 29 | + "ramp": torch.arange(-16, 16, 0.2), |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +class Cos(torch.nn.Module): |
| 34 | + |
| 35 | + def forward(self, x: torch.Tensor): |
| 36 | + return torch.cos(x) |
| 37 | + |
| 38 | + |
| 39 | +@common.parametrize("test_data", test_data_suite) |
| 40 | +def test_cos_tosa_MI(test_data: Tuple): |
| 41 | + pipeline = TosaPipelineMI[input_t1]( |
| 42 | + Cos(), |
| 43 | + (test_data,), |
| 44 | + aten_op, |
| 45 | + exir_op=[], |
| 46 | + ) |
| 47 | + if conftest.get_option("tosa_version") == "1.0": |
| 48 | + pipeline.run() |
| 49 | + |
| 50 | + |
| 51 | +@common.parametrize("test_data", test_data_suite) |
| 52 | +def test_cos_tosa_BI(test_data: Tuple): |
| 53 | + pipeline = TosaPipelineBI[input_t1]( |
| 54 | + Cos(), |
| 55 | + (test_data,), |
| 56 | + aten_op, |
| 57 | + exir_op=[], |
| 58 | + ) |
| 59 | + pipeline.run() |
| 60 | + |
| 61 | + |
| 62 | +@common.parametrize("test_data", test_data_suite) |
| 63 | +def test_cos_tosa_u55_BI(test_data: Tuple): |
| 64 | + pipeline = EthosU55PipelineBI[input_t1]( |
| 65 | + Cos(), |
| 66 | + (test_data,), |
| 67 | + aten_op, |
| 68 | + exir_ops=[], |
| 69 | + run_on_fvp=False, |
| 70 | + ) |
| 71 | + pipeline.run() |
| 72 | + |
| 73 | + |
| 74 | +@common.parametrize("test_data", test_data_suite) |
| 75 | +def test_cos_tosa_u85_BI(test_data: Tuple): |
| 76 | + pipeline = EthosU85PipelineBI[input_t1]( |
| 77 | + Cos(), |
| 78 | + (test_data,), |
| 79 | + aten_op, |
| 80 | + exir_ops=[], |
| 81 | + run_on_fvp=False, |
| 82 | + ) |
| 83 | + pipeline.run() |
0 commit comments