From aa6a04a56f21ab8de23b24c5f9ee7cafeaef8320 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 29 Aug 2018 12:53:41 +0100 Subject: COMPMID-1528: Add ReorgLayer on NEON Change-Id: I44369b4a716767163e2233b7d87bff300c523383 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/146314 Reviewed-by: Pablo Tello Tested-by: Jenkins --- tests/validation/reference/ReorgLayer.cpp | 97 +++++++++++++++++++++++++++++++ tests/validation/reference/ReorgLayer.h | 43 ++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 tests/validation/reference/ReorgLayer.cpp create mode 100644 tests/validation/reference/ReorgLayer.h (limited to 'tests/validation/reference') diff --git a/tests/validation/reference/ReorgLayer.cpp b/tests/validation/reference/ReorgLayer.cpp new file mode 100644 index 0000000000..cb13a737e0 --- /dev/null +++ b/tests/validation/reference/ReorgLayer.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2018 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 "ReorgLayer.h" + +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +TensorShape compute_reorg_shape(const TensorShape &src_shape, int32_t stride) +{ + ARM_COMPUTE_ERROR_ON(stride <= 0); + + TensorShape dst_shape = src_shape; + dst_shape.set(0, src_shape.x() / stride); + dst_shape.set(1, src_shape.y() / stride); + dst_shape.set(2, src_shape.z() * stride * stride); + + return dst_shape; +} +} // namespace + +template +SimpleTensor reorg_layer(const SimpleTensor &src, int32_t stride) +{ + // Calculate output shape + const TensorShape dst_shape = compute_reorg_shape(src.shape(), stride); + + // Create destination tensor + SimpleTensor dst{ dst_shape, src.data_type() }; + + const unsigned int W = dst.shape().x(); + const unsigned int H = dst.shape().y(); + const unsigned int C = dst.shape().z(); + const unsigned int out_c = C / (stride * stride); + const unsigned int outer_dims = dst.shape().total_size() / (W * H * C); + + // Calculate layer reorg in NCHW + Coordinates map_coords; + for(unsigned int b = 0; b < outer_dims; ++b) + { + map_coords.set(3, b); + for(unsigned int c = 0; c < C; ++c) + { + map_coords.set(2, c % out_c); + const unsigned int offset = c / out_c; + for(unsigned int h = 0; h < H; ++h) + { + map_coords.set(1, h * stride + offset / stride); + for(unsigned int w = 0; w < W; ++w) + { + const unsigned int dst_idx = w + W * (h + H * (c + C * b)); + map_coords.set(0, w * stride + offset % stride); + dst[dst_idx] = *reinterpret_cast(src(map_coords)); + } + } + } + } + + return dst; +} + +template SimpleTensor reorg_layer(const SimpleTensor &src, int32_t stride); +template SimpleTensor reorg_layer(const SimpleTensor &src, int32_t stride); +template SimpleTensor reorg_layer(const SimpleTensor &src, int32_t stride); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/ReorgLayer.h b/tests/validation/reference/ReorgLayer.h new file mode 100644 index 0000000000..c3f42f4aa0 --- /dev/null +++ b/tests/validation/reference/ReorgLayer.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 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. + */ +#ifndef __ARM_COMPUTE_TEST_REORG_LAYER_H__ +#define __ARM_COMPUTE_TEST_REORG_LAYER_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor reorg_layer(const SimpleTensor &src, int32_t stride); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_REORG_LAYER_H__ */ -- cgit v1.2.1