aboutsummaryrefslogtreecommitdiff
path: root/src/core/NEON
diff options
context:
space:
mode:
authormorgolock <pablo.tello@arm.com>2020-04-09 14:17:48 +0100
committerPablo Marquez <pablo.tello@arm.com>2020-06-15 14:04:49 +0000
commit37722d9a81627520fa347eb65199dbfeb84b26bd (patch)
tree3cb811c83e933337e685606625fcd44690b570d7 /src/core/NEON
parent4a61653202afb018f4f259d3c144a735d73f0a20 (diff)
downloadComputeLibrary-37722d9a81627520fa347eb65199dbfeb84b26bd.tar.gz
COMPMID-2449: Implement NEUnPoolLayer
Change-Id: I5677c87bba97dd395a3e13dbce34a3dd2c437033 Signed-off-by: morgolock <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3289 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/NEON')
-rw-r--r--src/core/NEON/kernels/NEMaxUnpoolingLayerKernel.cpp146
-rw-r--r--src/core/NEON/kernels/NEPoolingLayerKernel.cpp68
2 files changed, 192 insertions, 22 deletions
diff --git a/src/core/NEON/kernels/NEMaxUnpoolingLayerKernel.cpp b/src/core/NEON/kernels/NEMaxUnpoolingLayerKernel.cpp
new file mode 100644
index 0000000000..1967c553bd
--- /dev/null
+++ b/src/core/NEON/kernels/NEMaxUnpoolingLayerKernel.cpp
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2020 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/core/NEON/kernels/NEMaxUnpoolingLayerKernel.h"
+
+#include "arm_compute/core/AccessWindowStatic.h"
+#include "arm_compute/core/CPP/Validate.h"
+#include "arm_compute/core/Error.h"
+#include "arm_compute/core/Helpers.h"
+#include "arm_compute/core/ITensor.h"
+#include "arm_compute/core/NEON/NEAsymm.h"
+#include "arm_compute/core/NEON/NEFixedPoint.h"
+#include "arm_compute/core/NEON/NEMath.h"
+#include "arm_compute/core/TensorInfo.h"
+#include "arm_compute/core/Utils.h"
+#include "arm_compute/core/Validate.h"
+#include "arm_compute/core/Window.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
+
+#include "support/ToolchainSupport.h"
+
+namespace arm_compute
+{
+using namespace misc::shape_calculator;
+
+namespace
+{
+Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info, const ITensorInfo *indices)
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output, indices);
+ int pool_stride_x = 0;
+ int pool_stride_y = 0;
+ PoolingType pool_type = pool_info.pool_type;
+ const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
+ std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.stride();
+ const int pool_size_x = pool_info.pool_size.width;
+ const int pool_size_y = pool_info.pool_size.height;
+ const Size2D pool_size(pool_size_x, pool_size_y);
+ ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(indices, 1, DataType::U32);
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(pool_type != PoolingType::MAX, "Pooling indices only supported for MAX pooling method");
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32);
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG((pool_size != Size2D(2, 2)), "Pooling indices only supported for pool size 2x2");
+ if(output->total_size() != 0)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output);
+ }
+
+ return Status{};
+}
+} // namespace
+
+NEMaxUnpoolingLayerKernel::NEMaxUnpoolingLayerKernel()
+ : _func(nullptr), _input(nullptr), _output(nullptr), _indices(nullptr), _pool_info(), _data_layout(DataLayout::UNKNOWN), _num_elems_processed_per_iteration(0)
+{
+}
+
+void NEMaxUnpoolingLayerKernel::configure(const ITensor *input, const ITensor *indices, ITensor *output, const PoolingLayerInfo &pool_info)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+ const Size2D pool_size(pool_info.pool_size.width, pool_info.pool_size.height);
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), pool_info, indices->info()));
+ _input = input;
+ _output = output;
+ _indices = indices;
+ _pool_info = pool_info;
+ _data_layout = input->info()->data_layout();
+ switch(input->info()->data_type())
+ {
+ case DataType::F32:
+ _func = &NEMaxUnpoolingLayerKernel::unpooling2<float>;
+ break;
+ case DataType::QASYMM8:
+ _func = &NEMaxUnpoolingLayerKernel::unpooling2<uint8_t>;
+ break;
+ case DataType::QASYMM8_SIGNED:
+ _func = &NEMaxUnpoolingLayerKernel::unpooling2<int8_t>;
+ break;
+#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+ case DataType::F16:
+ _func = &NEMaxUnpoolingLayerKernel::unpooling2<float16_t>;
+ break;
+#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
+ default:
+ break;
+ }
+ const TensorShape output_shape = compute_unpool_shape(*input->info(), pool_info);
+ auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
+ _num_elems_processed_per_iteration = 1;
+ auto window = calculate_max_window(*input->info(), Steps(_num_elems_processed_per_iteration));
+ INEKernel::configure(window);
+}
+template <typename T>
+void NEMaxUnpoolingLayerKernel::unpooling2(const Window &window)
+{
+ Iterator input(_input, window);
+ Iterator indices(_indices, window);
+ auto out_ptr = reinterpret_cast<T *>(_output->buffer());
+ const int out_stride_w = static_cast<int>(_output->info()->strides_in_bytes()[3]);
+ execute_window_loop(window, [&](const Coordinates & id)
+ {
+ auto vindices = reinterpret_cast<uint32_t *>(indices.ptr());
+ auto vinput = reinterpret_cast<T *>(input.ptr());
+ out_ptr[id[3] * out_stride_w / sizeof(T) + *vindices] = *vinput;
+ },
+ input, indices);
+}
+
+Status NEMaxUnpoolingLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *indices, const ITensorInfo *output, const PoolingLayerInfo &pool_info)
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, indices, output);
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, pool_info, indices));
+ return Status{};
+}
+
+void NEMaxUnpoolingLayerKernel::run(const Window &window, const ThreadInfo &info)
+{
+ ARM_COMPUTE_UNUSED(info);
+ ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
+ ARM_COMPUTE_ERROR_ON(_func == nullptr);
+ // Run function
+ (this->*_func)(window);
+}
+} // namespace arm_compute
diff --git a/src/core/NEON/kernels/NEPoolingLayerKernel.cpp b/src/core/NEON/kernels/NEPoolingLayerKernel.cpp
index 6d61f51f31..d6b17534d3 100644
--- a/src/core/NEON/kernels/NEPoolingLayerKernel.cpp
+++ b/src/core/NEON/kernels/NEPoolingLayerKernel.cpp
@@ -36,7 +36,6 @@
#include "arm_compute/core/Validate.h"
#include "arm_compute/core/Window.h"
#include "arm_compute/core/utils/misc/ShapeCalculator.h"
-
#include "support/ToolchainSupport.h"
#include "arm_compute/core/NEON/wrapper/wrapper.h"
@@ -137,6 +136,7 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, c
ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
if(indices)
{
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16);
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(indices, 1, DataType::U32);
ARM_COMPUTE_RETURN_ERROR_ON_MSG(pool_type != PoolingType::MAX, "Pooling indices only supported for MAX pooling method");
}
@@ -156,7 +156,6 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, c
if(indices)
{
ARM_COMPUTE_RETURN_ERROR_ON_MSG((pool_size != Size2D(2, 2)), "Pooling indices only supported for pool size 2x2");
-
ARM_COMPUTE_RETURN_ERROR_ON((indices->dimension(get_data_layout_dimension_index(indices->data_layout(), DataLayoutDimension::WIDTH)) != pooled_w)
|| (indices->dimension(get_data_layout_dimension_index(indices->data_layout(), DataLayoutDimension::HEIGHT)) != pooled_h));
}
@@ -1489,6 +1488,39 @@ void NEPoolingLayerKernel::poolingMxN_f32_nchw(const Window &window_input, const
input, output);
}
+inline uint32_t offset_no_padding(uint32_t padded_offset, const Coordinates &id, const ITensorInfo &info, int pool_stride_x, int pool_stride_y)
+{
+ const int pad_left = info.padding().left;
+ const int pad_right = info.padding().right;
+ const int pad_top = info.padding().top;
+ const int pad_bottom = info.padding().bottom;
+ const int in_stride_y = static_cast<int>(info.strides_in_bytes().y());
+ const int in_stride_w = static_cast<int>(info.strides_in_bytes()[3]);
+ const int pad_horiz = pad_left + pad_right;
+ const int pad_vert = pad_top + pad_bottom;
+
+ if(info.data_layout() == DataLayout::NCHW)
+ {
+ const uint32_t offset_base = padded_offset
+ - sizeof(float) * pad_horiz * id.y() * pool_stride_y /* subtract padding elems per row */
+ - pad_top * sizeof(float) /* top padding */
+ - sizeof(float) * pad_horiz * info.tensor_shape()[1] * id.z() - pad_vert * in_stride_y * id.z() /* for each Z plane there are height*pad_right padding elems */
+ - in_stride_w * id[3];
+
+ return offset_base;
+ }
+ else
+ {
+ const uint32_t offset_base = padded_offset
+ - sizeof(float) * pad_horiz * id.y() * pool_stride_x // subtract padding elems per row
+ - pad_top * sizeof(float) // top padding
+ - sizeof(float) * pad_horiz * info.tensor_shape()[1] * id.z() * pool_stride_y // for each Z plane there are width*pad_right padding elems
+ - in_stride_w * id[3];
+
+ return offset_base;
+ }
+}
+
void NEPoolingLayerKernel::pooling2_f32_nchw_maxpool_indices(const Window &window_input, const Window &window)
{
Iterator input(_input, window_input);
@@ -1502,11 +1534,10 @@ void NEPoolingLayerKernel::pooling2_f32_nchw_maxpool_indices(const Window &windo
std::tie(pool_stride_x, pool_stride_y) = _pool_info.pad_stride_info.stride();
const uint8_t *const input_top_ptr = _input->ptr_to_element(Coordinates(-static_cast<int>(pool_pad_left), -static_cast<int>(pool_pad_top)));
const uint8_t *const input_bottom_ptr = _input->ptr_to_element(Coordinates(-static_cast<int>(pool_pad_left), -static_cast<int>(pool_pad_top) + 1));
-
- const Strides &input_strides = _input->info()->strides_in_bytes();
- const auto in_stridew = input_strides[1];
-
- execute_window_loop(window, [&](const Coordinates &)
+ const int pad_left = _input->info()->padding().left;
+ const int pad_right = _input->info()->padding().right;
+ const int in_stride_y = static_cast<int>(_input->info()->strides_in_bytes().y());
+ execute_window_loop(window, [&](const Coordinates & id)
{
const auto input_offset_top = input_top_ptr + input.offset();
const auto input_offset_bottom = input_bottom_ptr + input.offset();
@@ -1521,8 +1552,9 @@ void NEPoolingLayerKernel::pooling2_f32_nchw_maxpool_indices(const Window &windo
final_res = vget_lane_f32(res, 0);
// Store result
*(reinterpret_cast<float *>(output.ptr())) = final_res;
- const uint32_t offset_top = (uint32_t)(input.offset() / sizeof(float));
- const uint32_t offset_bottom = (uint32_t)offset_top + (in_stridew / sizeof(float));
+ const uint32_t offset_base = offset_no_padding(input.offset(), id, *_input->info(), pool_stride_x, pool_stride_y);
+ const uint32_t offset_top = (uint32_t)(offset_base / sizeof(float));
+ const uint32_t offset_bottom = offset_top + in_stride_y / sizeof(float) - pad_right - pad_left;
const uint32x2_t voffset_top = { offset_top, offset_top + 1u };
const uint32x2_t voffset_bottom = { offset_bottom, offset_bottom + 1u };
const uint32x2_t tmp_indices = vbsl_u32(vcgt_f32(top_data, bottom_data), voffset_top, voffset_bottom);
@@ -1867,10 +1899,8 @@ void NEPoolingLayerKernel::pooling2_f32_nhwc_maxpool_indices(const Window &windo
float32x4_t vres;
const int pad_right = _input->info()->padding().right;
- const int pad_top = _input->info()->padding().top;
const int in_stride_y = static_cast<int>(_input->info()->strides_in_bytes().y());
const int in_stride_z = static_cast<int>(_input->info()->strides_in_bytes().z());
- const int in_stride_w = static_cast<int>(_input->info()->strides_in_bytes()[3]);
execute_window_loop(window, [&](const Coordinates & id)
{
@@ -1904,17 +1934,11 @@ void NEPoolingLayerKernel::pooling2_f32_nhwc_maxpool_indices(const Window &windo
// Store result
vst1q_f32(reinterpret_cast<float *>(output.ptr()), vres);
- const uint32_t offset_base = input.offset()
- - sizeof(float) * pad_right * id.y() * pool_stride_x /* subtract padding elems per row */
- - pad_top * sizeof(float) /* top padding */
- - sizeof(float) * pad_right * _input->info()->tensor_shape()[1] * id.z() * pool_stride_y /* for each Z plane there are width*pad_right padding elems */
- - in_stride_w * id[3] + _input->info()->tensor_shape()[0] * sizeof(float) * id[3];
-
- const uint32_t offset_x0 = (uint32_t)offset_base / sizeof(float);
- const uint32_t offset_x1 = (uint32_t)offset_x0 + in_stride_y / sizeof(float) - pad_right;
- const uint32_t offset_x2 = (uint32_t)offset_x0 + in_stride_z / sizeof(float) - pad_right * _input->info()->tensor_shape()[1];
- const uint32_t offset_x3 = (uint32_t)offset_x2 + in_stride_y / sizeof(float) - pad_right;
-
+ const uint32_t offset_base = offset_no_padding(input.offset(), id, *_input->info(), pool_stride_x, pool_stride_y);
+ const uint32_t offset_x0 = (uint32_t)offset_base / sizeof(float);
+ const uint32_t offset_x1 = (uint32_t)offset_x0 + in_stride_y / sizeof(float) - pad_right;
+ const uint32_t offset_x2 = (uint32_t)offset_x0 + in_stride_z / sizeof(float) - pad_right * _input->info()->tensor_shape()[1];
+ const uint32_t offset_x3 = (uint32_t)offset_x2 + in_stride_y / sizeof(float) - pad_right;
const uint32x4_t voffset_x0 = { offset_x0, offset_x0 + 1, offset_x0 + 2, offset_x0 + 3 };
const uint32x4_t voffset_x1 = { offset_x1, offset_x1 + 1, offset_x1 + 2, offset_x1 + 3 };
const uint32x4_t voffset_x2 = { offset_x2, offset_x2 + 1, offset_x2 + 2, offset_x2 + 3 };