|
| 1 | +# Copyright 2026 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 | + TosaPipelineFP, |
| 12 | + VgfPipeline, |
| 13 | +) |
| 14 | + |
| 15 | +aten_op = "torch.ops.aten.fft_rfft2.default" |
| 16 | +exir_op = "executorch_exir_dialects_edge__ops_aten_fft_rfft2_default" |
| 17 | + |
| 18 | +input_t1 = Tuple[torch.Tensor] |
| 19 | + |
| 20 | + |
| 21 | +class RFFT2D(torch.nn.Module): |
| 22 | + test_parameters = { |
| 23 | + "rank2": lambda: (torch.randn(8, 16),), |
| 24 | + "rank3": lambda: (torch.randn(2, 8, 16),), |
| 25 | + "rank4": lambda: (torch.randn(1, 2, 8, 16),), |
| 26 | + "ones": lambda: (torch.ones(2, 8, 16),), |
| 27 | + "zeros": lambda: (torch.zeros(2, 8, 16),), |
| 28 | + } |
| 29 | + |
| 30 | + def forward(self, x: torch.Tensor): |
| 31 | + output = torch.fft.rfft2(x) |
| 32 | + return output.real, output.imag |
| 33 | + |
| 34 | + |
| 35 | +@common.parametrize("test_data", RFFT2D.test_parameters) |
| 36 | +def test_rfft2d_tosa_FP(test_data: input_t1): |
| 37 | + pipeline = TosaPipelineFP[input_t1]( |
| 38 | + RFFT2D(), |
| 39 | + test_data(), |
| 40 | + aten_op, |
| 41 | + exir_op, |
| 42 | + run_on_tosa_ref_model=False, |
| 43 | + tosa_version="1.1", |
| 44 | + tosa_extensions=["fft"], |
| 45 | + ) |
| 46 | + pipeline.run() |
| 47 | + |
| 48 | + |
| 49 | +@common.parametrize("test_data", RFFT2D.test_parameters) |
| 50 | +@common.SkipIfNoModelConverter |
| 51 | +def test_rfft2d_vgf_no_quant(test_data: input_t1): |
| 52 | + pipeline = VgfPipeline[input_t1]( |
| 53 | + RFFT2D(), |
| 54 | + test_data(), |
| 55 | + aten_op, |
| 56 | + exir_op, |
| 57 | + run_on_vulkan_runtime=False, |
| 58 | + quantize=False, |
| 59 | + tosa_version="TOSA-1.1+FP", |
| 60 | + tosa_extensions=["fft"], |
| 61 | + ) |
| 62 | + pipeline.run() |
0 commit comments