| 
 | 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 | +from typing import Tuple  | 
 | 7 | + | 
 | 8 | +import torch  | 
 | 9 | +from executorch.backends.arm.test import common  | 
 | 10 | +from executorch.backends.arm.test.tester.test_pipeline import (  | 
 | 11 | +    EthosU55PipelineBI,  | 
 | 12 | +    EthosU85PipelineBI,  | 
 | 13 | +    TosaPipelineBI,  | 
 | 14 | +    TosaPipelineMI,  | 
 | 15 | +)  | 
 | 16 | + | 
 | 17 | +input_t1 = Tuple[torch.Tensor]  | 
 | 18 | + | 
 | 19 | + | 
 | 20 | +class AliasCopy(torch.nn.Module):  | 
 | 21 | +    """  | 
 | 22 | +    Tests proper handling of alias_copy when used directly.  | 
 | 23 | +
  | 
 | 24 | +    alias_copy can also appear from PyTorch/ExecuTorch optimizations  | 
 | 25 | +    such as `x.transpose(0, 0)`. This is optimized to an alias_copy but  | 
 | 26 | +    not before dq/q operators are added.  | 
 | 27 | +    """  | 
 | 28 | + | 
 | 29 | +    aten_op = "torch.ops.aten.alias_copy.default"  | 
 | 30 | +    exir_op = "executorch_exir_dialects_edge__ops_aten_alias_copy_default"  | 
 | 31 | + | 
 | 32 | +    test_data: dict[input_t1] = {  | 
 | 33 | +        "1d_ramp": (torch.arange(-16, 16, 0.2),),  | 
 | 34 | +        "2d_ones": (torch.ones(5, 5),),  | 
 | 35 | +        "3d_rand": (torch.rand(3, 5, 5),),  | 
 | 36 | +        "4d_zeros": (torch.zeros(1, 10, 10, 10),),  | 
 | 37 | +    }  | 
 | 38 | + | 
 | 39 | +    def __init__(self):  | 
 | 40 | +        super().__init__()  | 
 | 41 | + | 
 | 42 | +    def forward(self, x: torch.Tensor):  | 
 | 43 | +        return torch.alias_copy(x)  | 
 | 44 | + | 
 | 45 | + | 
 | 46 | +@common.parametrize("test_data", AliasCopy.test_data)  | 
 | 47 | +def test_alias_copy_tosa_MI(test_data: input_t1):  | 
 | 48 | +    TosaPipelineMI[input_t1](  | 
 | 49 | +        AliasCopy(),  | 
 | 50 | +        test_data,  | 
 | 51 | +        AliasCopy.aten_op,  | 
 | 52 | +        AliasCopy.exir_op,  | 
 | 53 | +    ).run()  | 
 | 54 | + | 
 | 55 | + | 
 | 56 | +@common.parametrize("test_data", AliasCopy.test_data)  | 
 | 57 | +def test_alias_copy_tosa_BI(test_data: input_t1):  | 
 | 58 | +    TosaPipelineBI[input_t1](  | 
 | 59 | +        AliasCopy(),  | 
 | 60 | +        test_data,  | 
 | 61 | +        AliasCopy.aten_op,  | 
 | 62 | +        AliasCopy.exir_op,  | 
 | 63 | +    ).run()  | 
 | 64 | + | 
 | 65 | + | 
 | 66 | +@common.parametrize("test_data", AliasCopy.test_data)  | 
 | 67 | +def test_alias_copy_u55_BI(test_data: input_t1):  | 
 | 68 | +    EthosU55PipelineBI[input_t1](  | 
 | 69 | +        AliasCopy(),  | 
 | 70 | +        test_data,  | 
 | 71 | +        AliasCopy.aten_op,  | 
 | 72 | +        AliasCopy.exir_op,  | 
 | 73 | +    ).run()  | 
 | 74 | + | 
 | 75 | + | 
 | 76 | +@common.parametrize("test_data", AliasCopy.test_data)  | 
 | 77 | +def test_alias_copy_u85_BI(test_data: input_t1):  | 
 | 78 | +    EthosU85PipelineBI[input_t1](  | 
 | 79 | +        AliasCopy(),  | 
 | 80 | +        test_data,  | 
 | 81 | +        AliasCopy.aten_op,  | 
 | 82 | +        AliasCopy.exir_op,  | 
 | 83 | +    ).run()  | 
0 commit comments