giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/runtime/NEON/functions/NEFFT2D.h" |
| 25 | |
| 26 | #include "arm_compute/core/ITensor.h" |
| 27 | #include "arm_compute/core/Validate.h" |
| 28 | #include "arm_compute/runtime/Scheduler.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 32 | NEFFT2D::~NEFFT2D() = default; |
| 33 | |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 34 | NEFFT2D::NEFFT2D(std::shared_ptr<IMemoryManager> memory_manager) |
| 35 | : _memory_group(memory_manager), _first_pass_func(memory_manager), _second_pass_func(memory_manager), _first_pass_tensor() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void NEFFT2D::configure(const ITensor *input, ITensor *output, const FFT2DInfo &config) |
| 40 | { |
| 41 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 42 | ARM_COMPUTE_ERROR_THROW_ON(NEFFT2D::validate(input->info(), output->info(), config)); |
| 43 | |
| 44 | // Setup first pass |
| 45 | FFT1DInfo first_pass_config; |
Georgios Pinitas | 0b192e8 | 2020-02-20 17:09:28 +0000 | [diff] [blame] | 46 | first_pass_config.axis = config.axis0; |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 47 | first_pass_config.direction = config.direction; |
| 48 | _memory_group.manage(&_first_pass_tensor); |
| 49 | _first_pass_func.configure(input, &_first_pass_tensor, first_pass_config); |
| 50 | |
| 51 | // Setup second pass |
| 52 | FFT1DInfo second_pass_config; |
Georgios Pinitas | 0b192e8 | 2020-02-20 17:09:28 +0000 | [diff] [blame] | 53 | second_pass_config.axis = config.axis1; |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 54 | second_pass_config.direction = config.direction; |
| 55 | _second_pass_func.configure(&_first_pass_tensor, output, second_pass_config); |
| 56 | _first_pass_tensor.allocator()->allocate(); |
| 57 | } |
| 58 | |
| 59 | Status NEFFT2D::validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config) |
| 60 | { |
| 61 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
| 62 | |
| 63 | // Create intermediate tensor info |
| 64 | TensorInfo first_pass_tensor(input->clone()->set_is_resizable(true).reset_padding().set_num_channels(2)); |
| 65 | |
| 66 | // Validate first pass |
| 67 | FFT1DInfo first_pass_config; |
Georgios Pinitas | 0b192e8 | 2020-02-20 17:09:28 +0000 | [diff] [blame] | 68 | first_pass_config.axis = config.axis0; |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 69 | first_pass_config.direction = config.direction; |
| 70 | ARM_COMPUTE_RETURN_ON_ERROR(NEFFT1D::validate(input, &first_pass_tensor, first_pass_config)); |
| 71 | |
| 72 | // Validate second pass |
| 73 | FFT1DInfo second_pass_config; |
Georgios Pinitas | 0b192e8 | 2020-02-20 17:09:28 +0000 | [diff] [blame] | 74 | second_pass_config.axis = config.axis1; |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 75 | second_pass_config.direction = config.direction; |
| 76 | ARM_COMPUTE_RETURN_ON_ERROR(NEFFT1D::validate(&first_pass_tensor, output, second_pass_config)); |
| 77 | |
| 78 | // Checks performed when output is configured |
| 79 | if((output != nullptr) && (output->total_size() != 0)) |
| 80 | { |
| 81 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
| 82 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 83 | } |
| 84 | |
| 85 | return Status{}; |
| 86 | } |
| 87 | |
| 88 | void NEFFT2D::run() |
| 89 | { |
| 90 | _memory_group.acquire(); |
| 91 | |
| 92 | _first_pass_func.run(); |
| 93 | _second_pass_func.run(); |
| 94 | |
| 95 | _memory_group.release(); |
| 96 | } |
| 97 | } // namespace arm_compute |