blob: eb1139d7a36607c00d9e0cad061fef4ad3fa55d2 [file] [log] [blame]
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +01001/*
Michalis Spyroubcd23522020-05-21 15:02:36 +01002 * Copyright (c) 2017-2020 ARM Limited.
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +01003 *
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 Barbiereaefd002018-07-20 17:49:35 +010027#include "arm_compute/core/CPP/Validate.h"
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010028#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"
Michalis Spyroubcd23522020-05-21 15:02:36 +010034#include "arm_compute/core/Types.h"
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010035#include "arm_compute/core/Validate.h"
36
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010037#include <cstdint>
38
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +000039/** [NEReshapeLayerKernel Kernel] **/
Michalis Spyroubcd23522020-05-21 15:02:36 +010040namespace arm_compute
41{
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010042namespace
43{
Giuseppe Rossini6a90b692018-08-23 11:29:59 +010044Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
45{
46 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas8f5802f2019-02-22 11:08:32 +000047 // Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input) is not needed here as this kernel doesn't use NEON FP16 instructions.
Georgios Pinitas33843562019-12-10 13:33:18 +000048 ARM_COMPUTE_RETURN_ERROR_ON(input->data_type() == DataType::UNKNOWN);
Giuseppe Rossini6a90b692018-08-23 11:29:59 +010049
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 Gottardi0a1090a2019-02-14 18:07:36 +000052 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output);
Giuseppe Rossini6a90b692018-08-23 11:29:59 +010053
54 return Status{};
55}
56
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010057template <typename T>
58inline 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 Pinitas5ee66ea2017-09-07 17:29:16 +010064 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
Michalis Spyroubcd23522020-05-21 15:02:36 +010075void NEReshapeLayerKernel::configure(const ITensorInfo *input, ITensorInfo *output)
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010076{
Giuseppe Rossini6a90b692018-08-23 11:29:59 +010077 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Michalis Spyroubcd23522020-05-21 15:02:36 +010078 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, output));
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010079
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010080 // Configure kernel window
Michalis Spyroubcd23522020-05-21 15:02:36 +010081 Window win = calculate_max_window(*input);
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010082
Giuseppe Rossini6a90b692018-08-23 11:29:59 +010083 // Set the output valid region
Michalis Spyroubcd23522020-05-21 15:02:36 +010084 output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape()));
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +010085
86 INEKernel::configure(win);
87}
88
Michalis Spyrouce0c6752020-06-18 10:14:57 +010089void NEReshapeLayerKernel::run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, const ThreadInfo &info)
Michalis Spyroubcd23522020-05-21 15:02:36 +010090{
91 ARM_COMPUTE_UNUSED(info);
92 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
93 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
94
Michalis Spyrouce0c6752020-06-18 10:14:57 +010095 const auto src = inputs.at(TensorType::ACL_SRC);
96 auto dst = outputs.at(TensorType::ACL_DST);
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010097
98 switch(src->info()->data_type())
Michalis Spyroubcd23522020-05-21 15:02:36 +010099 {
100 case DataType::U8:
101 case DataType::S8:
102 case DataType::QASYMM8:
103 case DataType::QASYMM8_SIGNED:
Georgios Pinitas1fd2c802020-06-16 17:44:46 +0100104 reshape_tensor<uint8_t>(window, src, dst);
Michalis Spyroubcd23522020-05-21 15:02:36 +0100105 break;
106 case DataType::U16:
107 case DataType::S16:
108 case DataType::F16:
Georgios Pinitas1fd2c802020-06-16 17:44:46 +0100109 reshape_tensor<uint16_t>(window, src, dst);
Michalis Spyroubcd23522020-05-21 15:02:36 +0100110 break;
111 case DataType::U32:
112 case DataType::S32:
113 case DataType::F32:
Georgios Pinitas1fd2c802020-06-16 17:44:46 +0100114 reshape_tensor<uint32_t>(window, src, dst);
Michalis Spyroubcd23522020-05-21 15:02:36 +0100115 break;
116 default:
117 ARM_COMPUTE_ERROR("Unsupported data type!");
118 }
119}
120
Giuseppe Rossini6a90b692018-08-23 11:29:59 +0100121Status NEReshapeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
122{
123 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
124
125 return Status{};
126}
Michalis Spyroubcd23522020-05-21 15:02:36 +0100127} // namespace arm_compute
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000128/** [NEReshapeLayerKernel Kernel] **/