|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# Copyright 2025 Arm Limited and/or its affiliates. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | + |
| 9 | +from typing import Optional, Tuple |
| 10 | + |
| 11 | +import torch |
| 12 | +from executorch.backends.arm.test import common |
| 13 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 14 | + EthosU55PipelineBI, |
| 15 | + EthosU85PipelineBI, |
| 16 | + TosaPipelineBI, |
| 17 | + TosaPipelineMI, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +input_t = Tuple[torch.Tensor] |
| 22 | + |
| 23 | + |
| 24 | +class Silu(torch.nn.Module): |
| 25 | + def forward( |
| 26 | + self, |
| 27 | + _input: torch.Tensor, |
| 28 | + _inplace: Optional[bool] = False, |
| 29 | + ): |
| 30 | + return torch.nn.SiLU(inplace=_inplace)(_input) |
| 31 | + |
| 32 | + test_data: list[input_t] = { |
| 33 | + "op_silu_rank1_ones": (torch.ones(5),), |
| 34 | + "op_silu_rank1_negative_ones": (torch.ones(5) * (-1),), |
| 35 | + "op_silu_rank1_rand": (torch.rand(5) * 5,), |
| 36 | + "op_silu_rank4_ones": (torch.ones(1, 10, 25, 20),), |
| 37 | + "op_silu_rank4_negative_ones": ((-1) * torch.ones(1, 10, 25, 20),), |
| 38 | + "op_silu_rank4_large_rand": (200 * torch.rand(1, 10, 25, 20),), |
| 39 | + "op_silu_rank4_negative_large_rand": ((-200) * torch.rand(1, 10, 25, 20),), |
| 40 | + "op_silu_rank4_large_randn": (200 * torch.randn(1, 10, 25, 20) + 1,), |
| 41 | + } |
| 42 | + |
| 43 | + aten_op_MI = "torch.ops.aten.silu.default" |
| 44 | + aten_op_inplace_MI = "torch.ops.aten.silu_.default" |
| 45 | + aten_op_BI = ["torch.ops.aten.sigmoid.default", "torch.ops.aten.mul.Tensor"] |
| 46 | + |
| 47 | + |
| 48 | +@common.parametrize("test_data", Silu.test_data) |
| 49 | +def test_silu_tosa_MI(test_data: input_t): |
| 50 | + silu_data = (test_data[0], False) |
| 51 | + pipeline = TosaPipelineMI[input_t](Silu(), silu_data, Silu.aten_op_MI) |
| 52 | + pipeline.run() |
| 53 | + |
| 54 | + |
| 55 | +@common.parametrize("test_data", Silu.test_data) |
| 56 | +def test_silu_tosa_MI_inplace(test_data: input_t): |
| 57 | + silu_data = (test_data[0], True) |
| 58 | + pipeline = TosaPipelineMI[input_t](Silu(), silu_data, Silu.aten_op_inplace_MI) |
| 59 | + pipeline.run() |
| 60 | + |
| 61 | + |
| 62 | +@common.parametrize("test_data", Silu.test_data) |
| 63 | +def test_silu_tosa_BI(test_data: input_t): |
| 64 | + silu_data = (test_data[0], False) |
| 65 | + pipeline = TosaPipelineBI[input_t](Silu(), silu_data, Silu.aten_op_BI) |
| 66 | + pipeline.run() |
| 67 | + |
| 68 | + |
| 69 | +@common.parametrize("test_data", Silu.test_data) |
| 70 | +def test_silu_tosa_BI_inplace(test_data: input_t): |
| 71 | + silu_data = (test_data[0], True) |
| 72 | + pipeline = TosaPipelineBI[input_t](Silu(), silu_data, Silu.aten_op_BI) |
| 73 | + pipeline.run() |
| 74 | + |
| 75 | + |
| 76 | +@common.parametrize("test_data", Silu.test_data) |
| 77 | +@common.XfailIfNoCorstone300 |
| 78 | +def test_silu_u55_BI(test_data: input_t): |
| 79 | + silu_data = (test_data[0], False) |
| 80 | + pipeline = EthosU55PipelineBI[input_t]( |
| 81 | + Silu(), silu_data, Silu.aten_op_BI, run_on_fvp=True |
| 82 | + ) |
| 83 | + pipeline.run() |
| 84 | + |
| 85 | + |
| 86 | +@common.parametrize("test_data", Silu.test_data) |
| 87 | +@common.XfailIfNoCorstone300 |
| 88 | +def test_silu_u55_BI_inplace(test_data: input_t): |
| 89 | + silu_data = (test_data[0], True) |
| 90 | + pipeline = EthosU55PipelineBI[input_t]( |
| 91 | + Silu(), silu_data, Silu.aten_op_BI, run_on_fvp=True |
| 92 | + ) |
| 93 | + pipeline.run() |
| 94 | + |
| 95 | + |
| 96 | +@common.parametrize("test_data", Silu.test_data) |
| 97 | +@common.XfailIfNoCorstone320 |
| 98 | +def test_silu_u85_BI(test_data: input_t): |
| 99 | + silu_data = (test_data[0], False) |
| 100 | + pipeline = EthosU85PipelineBI[input_t]( |
| 101 | + Silu(), silu_data, Silu.aten_op_BI, run_on_fvp=True |
| 102 | + ) |
| 103 | + pipeline.run() |
| 104 | + |
| 105 | + |
| 106 | +@common.parametrize("test_data", Silu.test_data) |
| 107 | +@common.XfailIfNoCorstone320 |
| 108 | +def test_silu_u85_BI_inplace(test_data: input_t): |
| 109 | + silu_data = (test_data[0], True) |
| 110 | + pipeline = EthosU85PipelineBI[input_t]( |
| 111 | + Silu(), silu_data, Silu.aten_op_BI, run_on_fvp=True |
| 112 | + ) |
| 113 | + pipeline.run() |
0 commit comments