|
| 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 pytest |
| 8 | + |
| 9 | +import torch |
| 10 | + |
| 11 | +from executorch.backends.arm.test import common |
| 12 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 13 | + EthosU55PipelineBI, |
| 14 | + EthosU85PipelineBI, |
| 15 | + TosaPipelineBI, |
| 16 | + TosaPipelineMI, |
| 17 | +) |
| 18 | + |
| 19 | +input_t = Tuple[torch.Tensor] # Input x |
| 20 | +aten_op = "torch.ops.aten.acosh.default" |
| 21 | + |
| 22 | + |
| 23 | +test_data_suite = { |
| 24 | + # Valid input cases |
| 25 | + "ones": lambda: torch.ones(1, 7, 10, 12), |
| 26 | + "just_above_one": lambda: torch.tensor([1.0001, 1.01, 1.1, 2.0]), |
| 27 | + "rand_valid": lambda: torch.rand(10, 10) * 10 + 1, # [1, 11) |
| 28 | + "ramp_valid": lambda: torch.linspace(1.0, 20.0, steps=160), |
| 29 | + "large": lambda: torch.tensor([10.0, 100.0, 1000.0, 1e6]), |
| 30 | + "mixed_valid": lambda: torch.tensor([1.0, 2.0, 10.0, 100.0]), |
| 31 | +} |
| 32 | + |
| 33 | +test_data_suite_xfails = { |
| 34 | + # Invalid input cases (should return nan or error) |
| 35 | + "zeros": lambda: torch.zeros(1, 5, 3, 2), |
| 36 | + "neg_ones": lambda: -torch.ones(10, 10, 10), |
| 37 | + "rand_invalid": lambda: torch.rand(10, 10), # [0, 1) |
| 38 | + "ramp_invalid": lambda: torch.linspace(-10.0, 0.99, steps=160), |
| 39 | + "near_zero": lambda: torch.tensor([-1e-6, 0.0, 1e-6]), |
| 40 | + "large_negative": lambda: torch.tensor([-100.0, -10.0, 0.0]), |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +class Acosh(torch.nn.Module): |
| 45 | + |
| 46 | + def forward(self, x: torch.Tensor): |
| 47 | + return torch.acosh(x) |
| 48 | + |
| 49 | + |
| 50 | +@common.parametrize("test_data", test_data_suite) |
| 51 | +def test_acosh_tosa_MI(test_data: Tuple): |
| 52 | + pipeline = TosaPipelineMI[input_t]( |
| 53 | + Acosh(), |
| 54 | + (test_data(),), |
| 55 | + aten_op, |
| 56 | + exir_op=[], |
| 57 | + ) |
| 58 | + pipeline.run() |
| 59 | + |
| 60 | + |
| 61 | +@common.parametrize("test_data", test_data_suite) |
| 62 | +def test_acosh_tosa_BI(test_data: Tuple): |
| 63 | + pipeline = TosaPipelineBI[input_t]( |
| 64 | + Acosh(), |
| 65 | + (test_data(),), |
| 66 | + aten_op=[], |
| 67 | + ) |
| 68 | + pipeline.run() |
| 69 | + |
| 70 | + |
| 71 | +@common.parametrize("test_data", test_data_suite) |
| 72 | +@common.XfailIfNoCorstone300 |
| 73 | +def test_acosh_u55_BI(test_data: Tuple): |
| 74 | + pipeline = EthosU55PipelineBI[input_t]( |
| 75 | + Acosh(), |
| 76 | + (test_data(),), |
| 77 | + aten_ops=[], |
| 78 | + ) |
| 79 | + pipeline.run() |
| 80 | + |
| 81 | + |
| 82 | +@common.parametrize("test_data", test_data_suite_xfails) |
| 83 | +@pytest.mark.xfail(reason="Invalid inputs are currently not handled") |
| 84 | +def test_acosh_u55_BI_xfail(test_data: Tuple): |
| 85 | + pipeline = EthosU55PipelineBI[input_t]( |
| 86 | + Acosh(), |
| 87 | + (test_data(),), |
| 88 | + aten_ops=[], |
| 89 | + run_on_fvp=False, |
| 90 | + ) |
| 91 | + pipeline.run() |
| 92 | + |
| 93 | + |
| 94 | +@common.parametrize("test_data", test_data_suite) |
| 95 | +@common.XfailIfNoCorstone320 |
| 96 | +def test_acosh_u85_BI(test_data: Tuple): |
| 97 | + pipeline = EthosU85PipelineBI[input_t]( |
| 98 | + Acosh(), |
| 99 | + (test_data(),), |
| 100 | + aten_ops=[], |
| 101 | + ) |
| 102 | + pipeline.run() |
| 103 | + |
| 104 | + |
| 105 | +@common.parametrize("test_data", test_data_suite_xfails) |
| 106 | +@pytest.mark.xfail(reason="Invalid inputs are currently not handled") |
| 107 | +def test_acosh_u85_BI_xfail(test_data: Tuple): |
| 108 | + pipeline = EthosU55PipelineBI[input_t]( |
| 109 | + Acosh(), |
| 110 | + (test_data(),), |
| 111 | + aten_ops=[], |
| 112 | + run_on_fvp=False, |
| 113 | + ) |
| 114 | + pipeline.run() |
0 commit comments