From 3dd5b6884a65c06bcb9d15589ee2dc2978e3b336 Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Mon, 4 Mar 2019 14:14:02 +0000 Subject: COMPMID-1933: Implement NEHeightConcatenateLayer. Added support to concactenate tensors along the Y axis in NEConcatenateLayer. Change-Id: Ib714bfcf9954cc35918efa7d52fc9164bb08bdf6 Signed-off-by: Pablo Tello Reviewed-on: https://review.mlplatform.org/c/841 Reviewed-by: Gian Marco Iodice Reviewed-by: Georgios Pinitas Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins --- tests/validation/reference/ConcatenateLayer.cpp | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tests/validation/reference/ConcatenateLayer.cpp (limited to 'tests/validation/reference/ConcatenateLayer.cpp') diff --git a/tests/validation/reference/ConcatenateLayer.cpp b/tests/validation/reference/ConcatenateLayer.cpp new file mode 100644 index 0000000000..1440878829 --- /dev/null +++ b/tests/validation/reference/ConcatenateLayer.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2019 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 "ConcatenateLayer.h" + +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/Permute.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +template +SimpleTensor widthconcatenate_layer(const std::vector> &srcs, SimpleTensor &dst) +{ + // Create reference + std::vector shapes; + for(const auto &src : srcs) + { + shapes.emplace_back(src.shape()); + } + // Compute reference + int width_offset = 0; + const int width_out = dst.shape().x(); + // Set output tensor to 0 + std::fill_n(dst.data(), dst.num_elements(), 0); + for(const auto &src : srcs) + { + ARM_COMPUTE_ERROR_ON(width_offset >= width_out); + + const int width = src.shape().x(); + const int height = src.shape().y(); + const int depth = src.shape().z(); + const int upper_dims = src.shape().total_size() / (width * height * depth); + + const T *src_ptr = src.data(); + T *dst_ptr = dst.data(); + + for(int u = 0; u < upper_dims; ++u) + { + for(int d = 0; d < depth; ++d) + { + for(int r = 0; r < height; ++r) + { + const int offset = u * height * depth + d * height + r; + if(src.data_type() == DataType::QASYMM8 && src.quantization_info() != dst.quantization_info()) + { + std::transform(src_ptr, src_ptr + width, dst_ptr + width_offset + offset * width_out, [src, dst](T t) + { + const float dequantized_input = src.quantization_info().dequantize(t); + return dst.quantization_info().quantize(dequantized_input, RoundingPolicy::TO_NEAREST_UP); + }); + src_ptr += width; + } + else + { + std::copy(src_ptr, src_ptr + width, dst_ptr + width_offset + offset * width_out); + src_ptr += width; + } + } + } + } + width_offset += width; + } + return dst; +} + +template SimpleTensor widthconcatenate_layer(const std::vector> &srcs, SimpleTensor &dst); +template SimpleTensor widthconcatenate_layer(const std::vector> &srcs, SimpleTensor &dst); +template SimpleTensor widthconcatenate_layer(const std::vector> &srcs, SimpleTensor &dst); +} // namespace + +template +SimpleTensor concatenate_layer(std::vector> &srcs, SimpleTensor &dst, unsigned int axis) +{ + switch(axis) + { + case Window::DimX: + { + return widthconcatenate_layer(srcs, dst); + } + case Window::DimY: + { + for(auto &t : srcs) + { + t = reference::permute(t, PermutationVector(1U, 0U)); + } + dst = reference::permute(dst, PermutationVector(1U, 0U)); + return reference::permute(widthconcatenate_layer(srcs, dst), PermutationVector(1U, 0U)); + } + default: + { + ARM_COMPUTE_ERROR("Not supported"); + return dst; + } + } +} + +template SimpleTensor concatenate_layer(std::vector> &srcs, SimpleTensor &dst, unsigned int axis); +template SimpleTensor concatenate_layer(std::vector> &srcs, SimpleTensor &dst, unsigned int axis); +template SimpleTensor concatenate_layer(std::vector> &srcs, SimpleTensor &dst, unsigned int axis); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute -- cgit v1.2.1