| 
 | 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates.  | 
 | 2 | +# All rights reserved.  | 
 | 3 | +# Copyright 2024-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 | +from typing import Tuple, Union  | 
 | 9 | + | 
 | 10 | +import torch  | 
 | 11 | +from executorch.backends.arm.test import common  | 
 | 12 | + | 
 | 13 | +from executorch.backends.arm.test.tester.test_pipeline import (  | 
 | 14 | +    EthosU55PipelineINT,  | 
 | 15 | +    EthosU85PipelineINT,  | 
 | 16 | +    TosaPipelineFP,  | 
 | 17 | +    TosaPipelineINT,  | 
 | 18 | +    VgfPipeline,  | 
 | 19 | +)  | 
 | 20 | + | 
 | 21 | +test_data_suite = {  | 
 | 22 | +    # (test_name, input, other)  | 
 | 23 | +    "op_floor_div_rank1_ones": lambda: (  | 
 | 24 | +        torch.ones(5),  | 
 | 25 | +        torch.ones(5),  | 
 | 26 | +    ),  | 
 | 27 | +    "op_floor_div_rank1_rand": lambda: (  | 
 | 28 | +        torch.rand(5) * 5,  | 
 | 29 | +        torch.rand(5) * 5,  | 
 | 30 | +    ),  | 
 | 31 | +    "op_floor_div_rank4_negative_ones": lambda: (  | 
 | 32 | +        (-1) * torch.ones(5, 10, 25, 20),  | 
 | 33 | +        torch.ones(5, 10, 25, 20),  | 
 | 34 | +    ),  | 
 | 35 | +    "op_floor_div_rank4_ones_div_negative": lambda: (  | 
 | 36 | +        torch.ones(5, 10, 25, 20),  | 
 | 37 | +        (-1) * torch.ones(5, 10, 25, 20),  | 
 | 38 | +    ),  | 
 | 39 | +    "op_floor_div_rank4_large_rand": lambda: (  | 
 | 40 | +        200 * torch.rand(5, 10, 25, 20),  | 
 | 41 | +        torch.rand(5, 10, 25, 20),  | 
 | 42 | +    ),  | 
 | 43 | +    "op_floor_div_rank4_randn_mutltiple_broadcasts": lambda: (  | 
 | 44 | +        torch.randn(1, 4, 4, 1),  | 
 | 45 | +        torch.randn(1, 1, 4, 4),  | 
 | 46 | +    ),  | 
 | 47 | +    "op_floor_div_rank4_randn_scalar": lambda: (  | 
 | 48 | +        torch.randn(1, 4, 4, 1),  | 
 | 49 | +        2,  | 
 | 50 | +    ),  | 
 | 51 | +}  | 
 | 52 | + | 
 | 53 | + | 
 | 54 | +class FloorDivide(torch.nn.Module):  | 
 | 55 | +    aten_op = "torch.ops.aten.floor_divide.default"  | 
 | 56 | +    aten_ops_int = ["aten.mul.Tensor", "aten.reciprocal.default", "aten.floor.default"]  | 
 | 57 | +    exir_op = "executorch_exir_dialects_edge__ops_aten_div_Tensor_mode"  | 
 | 58 | +    exir_ops_int = [  | 
 | 59 | +        "executorch_exir_dialects_edge__ops_aten_reciprocal_default",  | 
 | 60 | +        "executorch_exir_dialects_edge__ops_aten_mul_Tensor",  | 
 | 61 | +        "executorch_exir_dialects_edge__ops_aten_floor_default",  | 
 | 62 | +    ]  | 
 | 63 | + | 
 | 64 | +    def forward(  | 
 | 65 | +        self,  | 
 | 66 | +        input_: Union[torch.Tensor, torch.types.Number],  | 
 | 67 | +        other_: Union[torch.Tensor, torch.types.Number],  | 
 | 68 | +    ):  | 
 | 69 | +        return torch.floor_divide(input=input_, other=other_)  | 
 | 70 | + | 
 | 71 | + | 
 | 72 | +input_t1 = Tuple[torch.Tensor, torch.Tensor]  | 
 | 73 | + | 
 | 74 | + | 
 | 75 | +@common.parametrize("test_data", test_data_suite)  | 
 | 76 | +def test_floor_divide_tosa_FP(test_data: input_t1):  | 
 | 77 | +    pipeline = TosaPipelineFP[input_t1](  | 
 | 78 | +        FloorDivide(),  | 
 | 79 | +        test_data(),  | 
 | 80 | +        FloorDivide.aten_op,  | 
 | 81 | +        FloorDivide.exir_op,  | 
 | 82 | +        use_to_edge_transform_and_lower=False,  | 
 | 83 | +    )  | 
 | 84 | +    pipeline.run()  | 
 | 85 | + | 
 | 86 | + | 
 | 87 | +@common.parametrize("test_data", test_data_suite)  | 
 | 88 | +def test_floor_divide_tosa_INT(test_data: input_t1):  | 
 | 89 | +    pipeline = TosaPipelineINT[input_t1](  | 
 | 90 | +        FloorDivide(),  | 
 | 91 | +        test_data(),  | 
 | 92 | +        aten_op=FloorDivide.aten_ops_int,  | 
 | 93 | +        exir_op=FloorDivide.exir_ops_int,  | 
 | 94 | +        use_to_edge_transform_and_lower=False,  | 
 | 95 | +    )  | 
 | 96 | +    pipeline.run()  | 
 | 97 | + | 
 | 98 | + | 
 | 99 | +@common.parametrize("test_data", test_data_suite)  | 
 | 100 | +@common.XfailIfNoCorstone300  | 
 | 101 | +def test_floor_divide_u55_INT(test_data: input_t1):  | 
 | 102 | +    pipeline = EthosU55PipelineINT[input_t1](  | 
 | 103 | +        FloorDivide(),  | 
 | 104 | +        test_data(),  | 
 | 105 | +        aten_ops=FloorDivide.aten_ops_int,  | 
 | 106 | +        exir_ops=FloorDivide.exir_ops_int,  | 
 | 107 | +        run_on_fvp=True,  | 
 | 108 | +        use_to_edge_transform_and_lower=False,  | 
 | 109 | +    )  | 
 | 110 | +    pipeline.run()  | 
 | 111 | + | 
 | 112 | + | 
 | 113 | +@common.parametrize("test_data", test_data_suite)  | 
 | 114 | +@common.XfailIfNoCorstone320  | 
 | 115 | +def test_floor_divide_u85_INT(test_data: input_t1):  | 
 | 116 | +    pipeline = EthosU85PipelineINT[input_t1](  | 
 | 117 | +        FloorDivide(),  | 
 | 118 | +        test_data(),  | 
 | 119 | +        aten_ops=FloorDivide.aten_ops_int,  | 
 | 120 | +        exir_ops=FloorDivide.exir_ops_int,  | 
 | 121 | +        run_on_fvp=True,  | 
 | 122 | +        use_to_edge_transform_and_lower=False,  | 
 | 123 | +    )  | 
 | 124 | +    pipeline.run()  | 
 | 125 | + | 
 | 126 | + | 
 | 127 | +@common.parametrize("test_data", test_data_suite)  | 
 | 128 | +@common.SkipIfNoModelConverter  | 
 | 129 | +def test_floor_divide_vgf_FP(test_data: input_t1):  | 
 | 130 | +    pipeline = VgfPipeline[input_t1](  | 
 | 131 | +        FloorDivide(),  | 
 | 132 | +        test_data(),  | 
 | 133 | +        FloorDivide.aten_op,  | 
 | 134 | +        FloorDivide.exir_op,  | 
 | 135 | +        tosa_version="TOSA-1.0+FP",  | 
 | 136 | +        use_to_edge_transform_and_lower=False,  | 
 | 137 | +    )  | 
 | 138 | +    pipeline.run()  | 
 | 139 | + | 
 | 140 | + | 
 | 141 | +@common.parametrize("test_data", test_data_suite)  | 
 | 142 | +@common.SkipIfNoModelConverter  | 
 | 143 | +def test_floor_divide_vgf_INT(test_data: input_t1):  | 
 | 144 | +    pipeline = VgfPipeline[input_t1](  | 
 | 145 | +        FloorDivide(),  | 
 | 146 | +        test_data(),  | 
 | 147 | +        aten_op=FloorDivide.aten_ops_int,  | 
 | 148 | +        exir_op=FloorDivide.exir_ops_int,  | 
 | 149 | +        tosa_version="TOSA-1.0+INT",  | 
 | 150 | +        use_to_edge_transform_and_lower=False,  | 
 | 151 | +    )  | 
 | 152 | +    pipeline.run()  | 
0 commit comments