Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 1 | /* |
Isabella Gottardi | 0a1090a | 2019-02-14 18:07:36 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [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/core/NEON/kernels/NEReshapeLayerKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/Validate.h" |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Error.h" |
| 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/IAccessWindow.h" |
| 31 | #include "arm_compute/core/ITensor.h" |
| 32 | #include "arm_compute/core/NEON/INEKernel.h" |
| 33 | #include "arm_compute/core/TensorInfo.h" |
| 34 | #include "arm_compute/core/Validate.h" |
| 35 | |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 36 | #include <cstdint> |
| 37 | |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 38 | /** [NEReshapeLayerKernel Kernel] **/ |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 39 | using namespace arm_compute; |
| 40 | |
| 41 | namespace |
| 42 | { |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 43 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output) |
| 44 | { |
| 45 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | 8f5802f | 2019-02-22 11:08:32 +0000 | [diff] [blame] | 46 | // Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input) is not needed here as this kernel doesn't use NEON FP16 instructions. |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 47 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QASYMM8, DataType::U16, DataType::S16, |
| 48 | DataType::U32, DataType::S32, DataType::F16, DataType::F32); |
| 49 | |
| 50 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 51 | ARM_COMPUTE_RETURN_ERROR_ON(input->tensor_shape().total_size() != output->tensor_shape().total_size()); |
Isabella Gottardi | 0a1090a | 2019-02-14 18:07:36 +0000 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output); |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 53 | |
| 54 | return Status{}; |
| 55 | } |
| 56 | |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 57 | template <typename T> |
| 58 | inline void reshape_tensor(const Window &window, const ITensor *input, ITensor *output) |
| 59 | { |
| 60 | const TensorShape &input_shape = input->info()->tensor_shape(); |
| 61 | const TensorShape &output_shape = output->info()->tensor_shape(); |
| 62 | Coordinates output_coord{}; |
| 63 | |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 64 | Iterator in(input, window); |
| 65 | |
| 66 | execute_window_loop(window, [&](const Coordinates & id) |
| 67 | { |
| 68 | output_coord = index2coords(output_shape, coords2index(input_shape, id)); |
| 69 | *reinterpret_cast<T *>(output->ptr_to_element(output_coord)) = *reinterpret_cast<T *>(in.ptr()); |
| 70 | }, |
| 71 | in); |
| 72 | } |
| 73 | } // namespace |
| 74 | |
| 75 | void NEReshapeLayerKernel::configure(const ITensor *input, ITensor *output) |
| 76 | { |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 77 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 78 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info())); |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 79 | |
| 80 | _input = input; |
| 81 | _output = output; |
| 82 | |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 83 | // Configure kernel window |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 84 | Window win = calculate_max_window(*input->info()); |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 85 | |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 86 | // Set the output valid region |
| 87 | output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape())); |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 88 | |
| 89 | INEKernel::configure(win); |
| 90 | } |
| 91 | |
Giuseppe Rossini | 6a90b69 | 2018-08-23 11:29:59 +0100 | [diff] [blame] | 92 | Status NEReshapeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output) |
| 93 | { |
| 94 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); |
| 95 | |
| 96 | return Status{}; |
| 97 | } |
| 98 | |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 99 | void NEReshapeLayerKernel::run(const Window &window, const ThreadInfo &info) |
| 100 | { |
| 101 | ARM_COMPUTE_UNUSED(info); |
| 102 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 103 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INESimpleKernel::window(), window); |
| 104 | |
| 105 | switch(_input->info()->data_type()) |
| 106 | { |
| 107 | case DataType::U8: |
| 108 | case DataType::S8: |
Les Bell | a5e6d67 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 109 | case DataType::QASYMM8: |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 110 | reshape_tensor<uint8_t>(window, _input, _output); |
| 111 | break; |
| 112 | case DataType::U16: |
| 113 | case DataType::S16: |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 114 | case DataType::F16: |
| 115 | reshape_tensor<uint16_t>(window, _input, _output); |
| 116 | break; |
| 117 | case DataType::U32: |
| 118 | case DataType::S32: |
| 119 | case DataType::F32: |
| 120 | reshape_tensor<uint32_t>(window, _input, _output); |
| 121 | break; |
| 122 | default: |
| 123 | ARM_COMPUTE_ERROR("Unsupported data type!"); |
| 124 | } |
| 125 | } |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 126 | /** [NEReshapeLayerKernel Kernel] **/ |