|
| 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 | + EthosU55PipelineINT, |
| 12 | + EthosU85PipelineINT, |
| 13 | + TosaPipelineFP, |
| 14 | + TosaPipelineINT, |
| 15 | + VgfPipeline, |
| 16 | +) |
| 17 | + |
| 18 | +aten_op = "torch.ops.aten.fill_.Scalar" |
| 19 | +exir_op = "executorch_exir_dialects_edge__ops_aten_full_like_default" |
| 20 | + |
| 21 | +input_t1 = Tuple[torch.Tensor] |
| 22 | + |
| 23 | +test_data_suite = { |
| 24 | + "ones_float": [torch.ones(2, 3), 5.0], |
| 25 | + "ones_int": [torch.ones(2, 3), -3], |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +class FillScalar(torch.nn.Module): |
| 30 | + def __init__(self): |
| 31 | + super().__init__() |
| 32 | + |
| 33 | + def forward(self, y: torch.Tensor, fill_value: int | float): |
| 34 | + mask = torch.full_like(y, 0) |
| 35 | + mask.fill_(fill_value) |
| 36 | + return mask * y |
| 37 | + |
| 38 | + |
| 39 | +@common.parametrize("test_data", test_data_suite) |
| 40 | +def test_fill_scalar_tosa_FP(test_data: Tuple): |
| 41 | + pipeline = TosaPipelineFP[input_t1]( |
| 42 | + FillScalar(), |
| 43 | + (*test_data,), |
| 44 | + aten_op=aten_op, |
| 45 | + exir_op=exir_op, |
| 46 | + ) |
| 47 | + pipeline.run() |
| 48 | + |
| 49 | + |
| 50 | +@common.parametrize("test_data", test_data_suite) |
| 51 | +def test_fill_scalar_tosa_INT(test_data: Tuple): |
| 52 | + pipeline = TosaPipelineINT[input_t1]( |
| 53 | + FillScalar(), |
| 54 | + (*test_data,), |
| 55 | + aten_op=aten_op, |
| 56 | + exir_op=exir_op, |
| 57 | + ) |
| 58 | + pipeline.run() |
| 59 | + |
| 60 | + |
| 61 | +@common.XfailIfNoCorstone300 |
| 62 | +@common.parametrize("test_data", test_data_suite) |
| 63 | +def test_fill_scalar_u55_INT(test_data: Tuple): |
| 64 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 65 | + FillScalar(), |
| 66 | + (*test_data,), |
| 67 | + aten_ops=[aten_op], |
| 68 | + exir_ops=exir_op, |
| 69 | + ) |
| 70 | + pipeline.run() |
| 71 | + |
| 72 | + |
| 73 | +@common.XfailIfNoCorstone320 |
| 74 | +@common.parametrize("test_data", test_data_suite) |
| 75 | +def test_fill_scalar_u85_INT(test_data: Tuple): |
| 76 | + pipeline = EthosU85PipelineINT[input_t1]( |
| 77 | + FillScalar(), |
| 78 | + (*test_data,), |
| 79 | + aten_ops=[aten_op], |
| 80 | + exir_ops=exir_op, |
| 81 | + ) |
| 82 | + pipeline.run() |
| 83 | + |
| 84 | + |
| 85 | +@common.parametrize("test_data", test_data_suite) |
| 86 | +@common.SkipIfNoModelConverter |
| 87 | +def test_fill_scalar_vgf_FP(test_data: input_t1): |
| 88 | + pipeline = VgfPipeline[input_t1]( |
| 89 | + FillScalar(), |
| 90 | + (*test_data,), |
| 91 | + aten_op, |
| 92 | + exir_op, |
| 93 | + tosa_version="TOSA-1.0+FP", |
| 94 | + ) |
| 95 | + pipeline.run() |
| 96 | + |
| 97 | + |
| 98 | +@common.parametrize("test_data", test_data_suite) |
| 99 | +@common.SkipIfNoModelConverter |
| 100 | +def test_fill_scalar_vgf_INT(test_data: input_t1): |
| 101 | + pipeline = VgfPipeline[input_t1]( |
| 102 | + FillScalar(), |
| 103 | + (*test_data,), |
| 104 | + aten_op, |
| 105 | + exir_op, |
| 106 | + tosa_version="TOSA-1.0+INT", |
| 107 | + ) |
| 108 | + pipeline.run() |
0 commit comments