|
| 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 | +from typing import Tuple |
| 6 | + |
| 7 | +import torch |
| 8 | +from executorch.backends.arm.test import common |
| 9 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 10 | + EthosU55PipelineINT, |
| 11 | + EthosU85PipelineINT, |
| 12 | + TosaPipelineFP, |
| 13 | + TosaPipelineINT, |
| 14 | + VgfPipeline, |
| 15 | +) |
| 16 | + |
| 17 | +aten_op = "torch.ops.aten.cosh.default" |
| 18 | +exir_op = "executorch_exir_dialects_edge__ops_aten__cosh_default" |
| 19 | + |
| 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), |
| 25 | + "zeros_4D": torch.zeros(1, 10, 32, 7), |
| 26 | + "zeros_alt_shape": torch.zeros(10, 3, 5), |
| 27 | + "ones": torch.ones(15, 10, 7), |
| 28 | + "ones_4D": torch.ones(1, 3, 32, 16), |
| 29 | + "rand": torch.rand(10, 10) - 0.5, |
| 30 | + "rand_alt_shape": torch.rand(10, 3, 5) - 0.5, |
| 31 | + "rand_4D": torch.rand(1, 6, 5, 7) - 0.5, |
| 32 | + "randn_pos": torch.randn(10) + 10, |
| 33 | + "randn_neg": torch.randn(10) - 10, |
| 34 | + "ramp": torch.arange(-16, 16, 0.2), |
| 35 | + "large": 100 * torch.ones(1, 1), |
| 36 | + "small": 0.000001 * torch.ones(1, 1), |
| 37 | + "small_rand": torch.rand(100) * 0.01, |
| 38 | + "biggest": torch.tensor([700.0, 710.0, 750.0]), |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +class Cosh(torch.nn.Module): |
| 43 | + def forward(self, x: torch.Tensor): |
| 44 | + return torch.cosh(x) |
| 45 | + |
| 46 | + |
| 47 | +@common.parametrize("test_data", test_data_suite) |
| 48 | +def test_cosh_tosa_FP(test_data: Tuple): |
| 49 | + pipeline = TosaPipelineFP[input_t1]( |
| 50 | + Cosh(), |
| 51 | + (test_data,), |
| 52 | + aten_op, |
| 53 | + exir_op, |
| 54 | + ) |
| 55 | + pipeline.run() |
| 56 | + |
| 57 | + |
| 58 | +@common.parametrize("test_data", test_data_suite) |
| 59 | +def test_cosh_tosa_INT(test_data: Tuple): |
| 60 | + pipeline = TosaPipelineINT[input_t1]( |
| 61 | + Cosh(), (test_data,), aten_op=aten_op, exir_op=exir_op |
| 62 | + ) |
| 63 | + pipeline.run() |
| 64 | + |
| 65 | + |
| 66 | +@common.XfailIfNoCorstone300 |
| 67 | +@common.parametrize("test_data", test_data_suite) |
| 68 | +def test_cosh_u55_INT(test_data: Tuple): |
| 69 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 70 | + Cosh(), (test_data,), aten_ops=aten_op, exir_ops=exir_op |
| 71 | + ) |
| 72 | + pipeline.run() |
| 73 | + |
| 74 | + |
| 75 | +@common.XfailIfNoCorstone320 |
| 76 | +@common.parametrize("test_data", test_data_suite) |
| 77 | +def test_cosh_u85_INT(test_data: Tuple): |
| 78 | + pipeline = EthosU85PipelineINT[input_t1]( |
| 79 | + Cosh(), (test_data,), aten_ops=aten_op, exir_ops=exir_op |
| 80 | + ) |
| 81 | + pipeline.run() |
| 82 | + |
| 83 | + |
| 84 | +@common.parametrize("test_data", test_data_suite) |
| 85 | +@common.SkipIfNoModelConverter |
| 86 | +def test_cosh_vgf_FP(test_data: Tuple): |
| 87 | + pipeline = VgfPipeline[input_t1]( |
| 88 | + Cosh(), |
| 89 | + (test_data,), |
| 90 | + [], |
| 91 | + [], |
| 92 | + tosa_version="TOSA-1.0+FP", |
| 93 | + ) |
| 94 | + pipeline.run() |
| 95 | + |
| 96 | + |
| 97 | +@common.parametrize("test_data", test_data_suite) |
| 98 | +@common.SkipIfNoModelConverter |
| 99 | +def test_cosh_vgf_INT(test_data: Tuple): |
| 100 | + pipeline = VgfPipeline[input_t1]( |
| 101 | + Cosh(), |
| 102 | + (test_data,), |
| 103 | + [], |
| 104 | + [], |
| 105 | + tosa_version="TOSA-1.0+INT", |
| 106 | + ) |
| 107 | + pipeline.run() |
0 commit comments