From 3ce3ff4e7133942e75fceae8f317104644d88bea Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Fri, 21 Jul 2017 17:41:02 +0100 Subject: COMPMID-415: Move DepthConcatenateLayer to new validation Change-Id: I3e594d5800f563ba9af3195b7db2b6d3e32012dd Reviewed-on: http://mpd-gerrit.cambridge.arm.com/81340 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/datasets_new/ShapeDatasets.h | 6 +- tests/validation/CL/DepthConcatenateLayer.cpp | 200 --------------------- tests/validation/NEON/DepthConcatenateLayer.cpp | 200 --------------------- tests/validation/Reference.cpp | 24 --- tests/validation/Reference.h | 9 - tests/validation/ReferenceCPP.cpp | 13 -- tests/validation/ReferenceCPP.h | 6 - tests/validation/TensorOperations.h | 47 ----- tests/validation/TensorVisitors.h | 24 --- tests/validation_new/CL/DepthConcatenateLayer.cpp | 123 +++++++++++++ tests/validation_new/CPP/DepthConcatenateLayer.cpp | 104 +++++++++++ tests/validation_new/CPP/DepthConcatenateLayer.h | 43 +++++ tests/validation_new/Helpers.cpp | 57 ++++++ tests/validation_new/Helpers.h | 8 + .../validation_new/NEON/DepthConcatenateLayer.cpp | 125 +++++++++++++ .../fixtures/DepthConcatenateLayerFixture.h | 177 ++++++++++++++++++ 16 files changed, 641 insertions(+), 525 deletions(-) delete mode 100644 tests/validation/CL/DepthConcatenateLayer.cpp delete mode 100644 tests/validation/NEON/DepthConcatenateLayer.cpp create mode 100644 tests/validation_new/CL/DepthConcatenateLayer.cpp create mode 100644 tests/validation_new/CPP/DepthConcatenateLayer.cpp create mode 100644 tests/validation_new/CPP/DepthConcatenateLayer.h create mode 100644 tests/validation_new/Helpers.cpp create mode 100644 tests/validation_new/NEON/DepthConcatenateLayer.cpp create mode 100644 tests/validation_new/fixtures/DepthConcatenateLayerFixture.h diff --git a/tests/datasets_new/ShapeDatasets.h b/tests/datasets_new/ShapeDatasets.h index 690e401757..ba142cae0c 100644 --- a/tests/datasets_new/ShapeDatasets.h +++ b/tests/datasets_new/ShapeDatasets.h @@ -55,8 +55,9 @@ public: Small2DShapes() : ShapeDataset("Shape", { - TensorShape{ 5U, 5U }, - TensorShape{ 640U, 480U } + TensorShape{ 7U, 7U }, + TensorShape{ 27U, 13U }, + TensorShape{ 128U, 64U } }) { } @@ -100,6 +101,7 @@ public: : ShapeDataset("Shape", { TensorShape{ 1920U, 1080U }, + TensorShape{ 1245U, 652U }, TensorShape{ 4160U, 3120U } }) { diff --git a/tests/validation/CL/DepthConcatenateLayer.cpp b/tests/validation/CL/DepthConcatenateLayer.cpp deleted file mode 100644 index 8e254d2bd8..0000000000 --- a/tests/validation/CL/DepthConcatenateLayer.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2017 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 "AssetsLibrary.h" -#include "CL/CLAccessor.h" -#include "Globals.h" -#include "PaddingCalculator.h" -#include "TypePrinter.h" -#include "Utils.h" -#include "validation/Datasets.h" -#include "validation/Helpers.h" -#include "validation/Reference.h" -#include "validation/Validation.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/CL/CLScheduler.h" -#include "arm_compute/runtime/CL/CLTensor.h" -#include "arm_compute/runtime/CL/CLTensorAllocator.h" -#include "arm_compute/runtime/CL/functions/CLDepthConcatenate.h" - -#include "support/ToolchainSupport.h" - -#include "boost_wrapper.h" - -#include -#include -#include -#include -#include - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -/** Compute OpenCL depth concatenate layer function. - * - * @param[in] shapes List of shapes to concatenate - * @param[in] dt Datatype of tensors - * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of fixed point numbers. - * - * @return Computed output tensor. - */ -CLTensor compute_depth_concatenate_layer(const std::vector &shapes, DataType dt, int fixed_point_position = 0) -{ - std::vector> srcs{}; - TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); - - // Create tensors - for(unsigned int i = 0; i < shapes.size(); ++i) - { - srcs.push_back(support::cpp14::make_unique()); - srcs[i]->allocator()->init(TensorInfo(shapes[i], 1, dt, fixed_point_position)); - } - CLTensor dst = create_tensor(dst_shape, dt, 1, fixed_point_position); - - // Create a vector of raw pointer - std::vector srcs_raw{}; - srcs_raw.resize(srcs.size()); - std::transform(srcs.begin(), srcs.end(), srcs_raw.begin(), [](std::unique_ptr const & t) - { - return t.get(); - }); - - // Create and configure function - CLDepthConcatenate depth_concat; - depth_concat.configure(srcs_raw, &dst); - - // Allocate tensors - for(auto &t : srcs) - { - t->allocator()->allocate(); - } - dst.allocator()->allocate(); - - for(const auto &t : srcs) - { - BOOST_TEST(!t->info()->is_resizable()); - } - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors - for(unsigned int i = 0; i < srcs.size(); ++i) - { - library->fill_tensor_uniform(CLAccessor(*srcs[i]), i); - } - - // Compute function - depth_concat.run(); - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(CL) -BOOST_AUTO_TEST_SUITE(DepthConcatenateLayer) - -BOOST_AUTO_TEST_SUITE(Float) -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * CNNFloatDataTypes(), shape, dt) -{ - // Create input shapes - std::vector depths = { 4, 6, 11, 13 }; - std::vector shapes(depths.size(), shape); - for(unsigned int i = 0; i < shapes.size(); ++i) - { - shapes[i].set(2, depths[i]); - } - - // Compute function - CLTensor dst = compute_depth_concatenate_layer(shapes, dt); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt); - - // Validate output - validate(CLAccessor(dst), ref_dst); -} - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmallPad, CNNFloatDataTypes(), dt) -{ - // Create input shapes - std::vector shapes{ TensorShape(12u, 12u, 14u, 8u), TensorShape(14u, 14u, 12u, 8u), TensorShape(16u, 16u, 11u, 8u) }; - - // Compute function - CLTensor dst = compute_depth_concatenate_layer(shapes, dt); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt); - - // Validate output - validate(CLAccessor(dst), ref_dst); -} -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(Quantized) -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * CNNFixedPointDataTypes() * boost::unit_test::data::xrange(3, 6, 1), shape, dt, fixed_point_position) -{ - // Create input shapes - std::vector depths = { 4, 6, 11, 13 }; - std::vector shapes(depths.size(), shape); - for(unsigned int i = 0; i < shapes.size(); ++i) - { - shapes[i].set(2, depths[i]); - } - - // Compute function - CLTensor dst = compute_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Validate output - validate(CLAccessor(dst), ref_dst); -} - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmallPad, CNNFixedPointDataTypes() * boost::unit_test::data::xrange(3, 5, 1), dt, fixed_point_position) -{ - // Create input shapes - std::vector shapes{ TensorShape(12u, 12u, 14u, 8u), TensorShape(14u, 14u, 12u, 8u), TensorShape(16u, 16u, 11u, 8u) }; - - // Compute function - CLTensor dst = compute_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Validate output - validate(CLAccessor(dst), ref_dst); -} -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation/NEON/DepthConcatenateLayer.cpp b/tests/validation/NEON/DepthConcatenateLayer.cpp deleted file mode 100644 index 528d6f80d7..0000000000 --- a/tests/validation/NEON/DepthConcatenateLayer.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2017 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 "AssetsLibrary.h" -#include "Globals.h" -#include "NEON/Accessor.h" -#include "PaddingCalculator.h" -#include "TypePrinter.h" -#include "Utils.h" -#include "validation/Datasets.h" -#include "validation/Helpers.h" -#include "validation/Reference.h" -#include "validation/Validation.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/NEON/functions/NEDepthConcatenate.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "support/ToolchainSupport.h" - -#include "boost_wrapper.h" - -#include -#include -#include -#include -#include - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -/** Compute NEON depth concatenate layer function. - * - * @param[in] shapes List of shapes to concatenate - * @param[in] dt Datatype of tensors - * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of fixed point numbers. - * - * @return Computed output tensor. - */ -Tensor compute_depth_concatenate_layer(const std::vector &shapes, DataType dt, int fixed_point_position = 0) -{ - std::vector> srcs{}; - TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); - - // Create tensors - for(unsigned int i = 0; i < shapes.size(); ++i) - { - srcs.push_back(support::cpp14::make_unique()); - srcs[i]->allocator()->init(TensorInfo(shapes[i], 1, dt, fixed_point_position)); - } - Tensor dst = create_tensor(dst_shape, dt, 1, fixed_point_position); - - // Create a vector of raw pointer - std::vector srcs_raw{}; - srcs_raw.resize(srcs.size()); - std::transform(srcs.begin(), srcs.end(), srcs_raw.begin(), [](std::unique_ptr const & t) - { - return t.get(); - }); - - // Create and configure function - NEDepthConcatenate depth_concat; - depth_concat.configure(srcs_raw, &dst); - - // Allocate tensors - for(auto &t : srcs) - { - t->allocator()->allocate(); - } - dst.allocator()->allocate(); - - for(const auto &t : srcs) - { - BOOST_TEST(!t->info()->is_resizable()); - } - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors - for(unsigned int i = 0; i < srcs.size(); ++i) - { - library->fill_tensor_uniform(Accessor(*srcs[i]), i); - } - - // Compute function - depth_concat.run(); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(DepthConcatenateLayer) - -BOOST_AUTO_TEST_SUITE(Float) -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * CNNFloatDataTypes(), shape, dt) -{ - // Create input shapes - std::vector depths = { 4, 6, 11, 13 }; - std::vector shapes(depths.size(), shape); - for(unsigned int i = 0; i < shapes.size(); ++i) - { - shapes[i].set(2, depths[i]); - } - - // Compute function - Tensor dst = compute_depth_concatenate_layer(shapes, dt); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt); - - // Validate output - validate(Accessor(dst), ref_dst); -} - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmallPad, CNNFloatDataTypes(), dt) -{ - // Create input shapes - std::vector shapes{ TensorShape(12u, 12u, 14u, 8u), TensorShape(14u, 14u, 12u, 8u), TensorShape(16u, 16u, 11u, 8u) }; - - // Compute function - Tensor dst = compute_depth_concatenate_layer(shapes, dt); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt); - - // Validate output - validate(Accessor(dst), ref_dst); -} -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(Quantized) -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * CNNFixedPointDataTypes() * boost::unit_test::data::xrange(3, 6, 1), shape, dt, fixed_point_position) -{ - // Create input shapes - std::vector depths = { 4, 6, 11, 13 }; - std::vector shapes(depths.size(), shape); - for(unsigned int i = 0; i < shapes.size(); ++i) - { - shapes[i].set(2, depths[i]); - } - - // Compute function - Tensor dst = compute_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst); -} - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) -BOOST_DATA_TEST_CASE(RunSmallPad, CNNFixedPointDataTypes() * boost::unit_test::data::xrange(3, 5, 1), dt, fixed_point_position) -{ - // Create input shapes - std::vector shapes{ TensorShape(12u, 12u, 14u, 8u), TensorShape(14u, 14u, 12u, 8u), TensorShape(16u, 16u, 11u, 8u) }; - - // Compute function - Tensor dst = compute_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_concatenate_layer(shapes, dt, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst); -} -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation/Reference.cpp b/tests/validation/Reference.cpp index 011fd091f2..145f308c50 100644 --- a/tests/validation/Reference.cpp +++ b/tests/validation/Reference.cpp @@ -557,30 +557,6 @@ RawTensor Reference::compute_reference_convolution_layer(const TensorShape &inpu return ref_dst; } -RawTensor Reference::compute_reference_depth_concatenate_layer(const std::vector &shapes, DataType dt, int fixed_point_position) -{ - std::vector> ref_srcs{}; - TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); - - // Create tensors - for(const auto &shape : shapes) - { - ref_srcs.push_back(support::cpp14::make_unique(shape, dt, 1, fixed_point_position)); - } - RawTensor ref_dst(dst_shape, dt, 1, fixed_point_position); - - // Fill references - for(unsigned int i = 0; i < ref_srcs.size(); ++i) - { - library->fill_tensor_uniform(*ref_srcs[i], i); - } - - // Compute reference - ReferenceCPP::depth_concatenate_layer(ref_srcs, ref_dst); - - return ref_dst; -} - RawTensor Reference::compute_reference_fully_connected_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, DataType dt, bool transpose_weights, int fixed_point_position) { diff --git a/tests/validation/Reference.h b/tests/validation/Reference.h index 42c62f8d6a..8c22545cb1 100644 --- a/tests/validation/Reference.h +++ b/tests/validation/Reference.h @@ -320,15 +320,6 @@ public: */ static RawTensor compute_reference_convolution_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, DataType dt, const PadStrideInfo &conv_info, int fixed_point_position); - /** Compute reference depth concatenation layer - * - * @param[in] shapes Input tensor shapes (All dimensions should match apart from DimZ) - * @param[in] dt Data type to use - * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers - * - * @return Computed raw tensor. - */ - static RawTensor compute_reference_depth_concatenate_layer(const std::vector &shapes, DataType dt, int fixed_point_position = 0); /** Compute reference for fully connected layer function * * @param[in] input_shape Shape for the input tensor diff --git a/tests/validation/ReferenceCPP.cpp b/tests/validation/ReferenceCPP.cpp index 117fd5bebb..5f3fa1fcbc 100644 --- a/tests/validation/ReferenceCPP.cpp +++ b/tests/validation/ReferenceCPP.cpp @@ -306,19 +306,6 @@ void ReferenceCPP::convolution_layer(const RawTensor &src, const RawTensor &weig boost::apply_visitor(tensor_visitors::convolution_layer_visitor(s, w, b, conv_info), d); } -// Depth concatenate layer -void ReferenceCPP::depth_concatenate_layer(const std::vector> &srcs, RawTensor &dst) -{ - std::vector ss; - ss.resize(srcs.size()); - std::transform(srcs.begin(), srcs.end(), ss.begin(), [](std::unique_ptr const & t) - { - return TensorFactory::get_tensor(*t); - }); - TensorVariant d = TensorFactory::get_tensor(dst); - boost::apply_visitor(tensor_visitors::depth_concatenate_layer_visitor(ss), d); -} - // Fully connected layer void ReferenceCPP::fully_connected_layer(const RawTensor &src, const RawTensor &weights, const RawTensor &bias, RawTensor &dst) { diff --git a/tests/validation/ReferenceCPP.h b/tests/validation/ReferenceCPP.h index 0d1bea48bd..ab77d783b6 100644 --- a/tests/validation/ReferenceCPP.h +++ b/tests/validation/ReferenceCPP.h @@ -275,12 +275,6 @@ public: * @param[in] conv_info Pads and strides information for the convolution layer. */ static void convolution_layer(const RawTensor &src, const RawTensor &weights, const RawTensor &bias, RawTensor &dst, const PadStrideInfo &conv_info); - /** Depth concatenate layer from @p srcs to @p dst - * - * @param[in] srcs Input tensors. - * @param[out] dst Result tensor. - */ - static void depth_concatenate_layer(const std::vector> &srcs, RawTensor &dst); /** Fully connected layer function * * @param[in] src Input tensor diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h index db145c19ad..84aa965a9f 100644 --- a/tests/validation/TensorOperations.h +++ b/tests/validation/TensorOperations.h @@ -999,53 +999,6 @@ void batch_normalization_layer(const Tensor &in, Tensor &out, const Tensor } } -// Depth Concatenate layer -template -void depth_concatenate_layer(const std::vector *> &srcs, Tensor &out) -{ - unsigned depth_offset = 0; - const int width_out = out.shape().x(); - const int height_out = out.shape().y(); - const int depth_out = out.shape().z(); - const int out_stride_z = width_out * height_out; - const int batches = out.shape().total_size_upper(3); - - // Set output tensor to 0 - memset(out.data(), 0, out.num_elements() * element_size_from_data_type(out.data_type())); - - for(unsigned int i = 0; i < srcs.size(); ++i) - { - ARM_COMPUTE_ERROR_ON(srcs[i] == nullptr); - ARM_COMPUTE_ERROR_ON(srcs[i]->data_type() != out.data_type()); - ARM_COMPUTE_ERROR_ON(depth_offset >= out.shape().z()); - ARM_COMPUTE_ERROR_ON(batches != static_cast(srcs[i]->shape().total_size_upper(3))); - - const Tensor *src = srcs[i]; - const int width = src->shape().x(); - const int height = src->shape().y(); - const int depth = src->shape().z(); - const unsigned int x_diff = (width_out - width) / 2; - const unsigned int y_diff = (height_out - height) / 2; - - const T *src_ptr = src->data(); - for(int b = 0; b < batches; ++b) - { - const unsigned int offset_to_first_element = b * out_stride_z * depth_out + depth_offset * out_stride_z - + y_diff * width_out + x_diff; - for(int d = 0; d < depth; ++d) - { - for(int r = 0; r < height; ++r) - { - std::copy(src_ptr, src_ptr + width, out.data() + offset_to_first_element + d * out_stride_z + r * width_out); - src_ptr += width; - } - } - } - - depth_offset += depth; - } -} - // Convolution layer template void convolution_layer(const Tensor &in, const Tensor &weights, const Tensor &bias, Tensor &out, const PadStrideInfo &conv_info) diff --git a/tests/validation/TensorVisitors.h b/tests/validation/TensorVisitors.h index 365aac7758..d72b437344 100644 --- a/tests/validation/TensorVisitors.h +++ b/tests/validation/TensorVisitors.h @@ -278,30 +278,6 @@ private: const TensorVariant &_bias; PadStrideInfo _conv_info; }; -// Depth Concatenate Layer visitor -struct depth_concatenate_layer_visitor : public boost::static_visitor<> -{ -public: - explicit depth_concatenate_layer_visitor(const std::vector &srcs) - : _srcs(srcs) - { - } - - template - void operator()(Tensor &out) const - { - std::vector *> srcs; - srcs.resize(_srcs.size()); - std::transform(_srcs.begin(), _srcs.end(), srcs.begin(), [](const TensorVariant & t) - { - return &(boost::get>(t)); - }); - tensor_operations::depth_concatenate_layer(srcs, out); - } - -private: - const std::vector &_srcs; -}; // Fully Connected Layer visitor struct fully_connected_layer_visitor : public boost::static_visitor<> { diff --git a/tests/validation_new/CL/DepthConcatenateLayer.cpp b/tests/validation_new/CL/DepthConcatenateLayer.cpp new file mode 100644 index 0000000000..ff64e2340b --- /dev/null +++ b/tests/validation_new/CL/DepthConcatenateLayer.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2017 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/Types.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLDepthConcatenate.h" +#include "framework/Asserts.h" +#include "framework/Macros.h" +#include "framework/datasets/Datasets.h" +#include "tests/CL/CLAccessor.h" +#include "tests/datasets_new/ShapeDatasets.h" +#include "tests/validation_new/Validation.h" +#include "tests/validation_new/fixtures/DepthConcatenateLayerFixture.h" +#include "tests/validation_new/half.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(CL) +TEST_SUITE(DepthConcatenateLayer) + +//TODO(COMPMID-415): Add configuration test? + +template +using CLDepthConcatenateLayerFixture = DepthConcatenateValidationFixture; + +TEST_SUITE(Float) +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", + DataType::F16))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), framework::dataset::make("DataType", + DataType::F16))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() + +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", + DataType::F32))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), framework::dataset::make("DataType", + DataType::F32))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE(Quantized) +TEST_SUITE(QS8) +FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), + framework::dataset::make("DataType", + DataType::QS8))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), + framework::dataset::make("DataType", + DataType::QS8))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() + +TEST_SUITE(QS16) +FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), + framework::dataset::make("DataType", + DataType::QS16))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), + framework::dataset::make("DataType", + DataType::QS16))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation_new/CPP/DepthConcatenateLayer.cpp b/tests/validation_new/CPP/DepthConcatenateLayer.cpp new file mode 100644 index 0000000000..c54c6c8568 --- /dev/null +++ b/tests/validation_new/CPP/DepthConcatenateLayer.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017 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 "DepthConcatenateLayer.h" + +#include "tests/validation_new/FixedPoint.h" +#include "tests/validation_new/Helpers.h" +#include "tests/validation_new/half.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor depthconcatenate_layer(const std::vector> &srcs) +{ + // Create reference + std::vector shapes; + + for(const auto &src : srcs) + { + shapes.emplace_back(src.shape()); + } + + DataType dst_type = srcs.empty() ? DataType::UNKNOWN : srcs[0].data_type(); + TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); + SimpleTensor dst(dst_shape, dst_type); + + // Compute reference + int depth_offset = 0; + const int width_out = dst.shape().x(); + const int height_out = dst.shape().y(); + const int depth_out = dst.shape().z(); + const int out_stride_z = width_out * height_out; + const int batches = dst.shape().total_size_upper(3); + + // Set output tensor to 0 + std::fill_n(dst.data(), dst.num_elements(), 0); + + for(const auto &src : srcs) + { + ARM_COMPUTE_ERROR_ON(depth_offset >= depth_out); + ARM_COMPUTE_ERROR_ON(batches != static_cast(src.shape().total_size_upper(3))); + + const int width = src.shape().x(); + const int height = src.shape().y(); + const int depth = src.shape().z(); + const int x_diff = (width_out - width) / 2; + const int y_diff = (height_out - height) / 2; + + const T *src_ptr = src.data(); + + for(int b = 0; b < batches; ++b) + { + const size_t offset_to_first_element = b * out_stride_z * depth_out + depth_offset * out_stride_z + y_diff * width_out + x_diff; + + for(int d = 0; d < depth; ++d) + { + for(int r = 0; r < height; ++r) + { + std::copy(src_ptr, src_ptr + width, dst.data() + offset_to_first_element + d * out_stride_z + r * width_out); + src_ptr += width; + } + } + } + + depth_offset += depth; + } + + return dst; +} + +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +template SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation_new/CPP/DepthConcatenateLayer.h b/tests/validation_new/CPP/DepthConcatenateLayer.h new file mode 100644 index 0000000000..e7467d8ad0 --- /dev/null +++ b/tests/validation_new/CPP/DepthConcatenateLayer.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 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_DEPTHCONCATENATE_LAYER_H__ +#define __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ + +#include "tests/validation_new/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor depthconcatenate_layer(const std::vector> &srcs); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ */ diff --git a/tests/validation_new/Helpers.cpp b/tests/validation_new/Helpers.cpp new file mode 100644 index 0000000000..c65966b06f --- /dev/null +++ b/tests/validation_new/Helpers.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 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 "tests/validation_new/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TensorShape calculate_depth_concatenate_shape(const std::vector &input_shapes) +{ + ARM_COMPUTE_ERROR_ON(input_shapes.empty()); + + TensorShape out_shape = input_shapes[0]; + + size_t max_x = 0; + size_t max_y = 0; + size_t depth = 0; + + for(const auto &shape : input_shapes) + { + max_x = std::max(shape.x(), max_x); + max_y = std::max(shape.y(), max_y); + depth += shape.z(); + } + + out_shape.set(0, max_x); + out_shape.set(1, max_y); + out_shape.set(2, depth); + + return out_shape; +} +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation_new/Helpers.h b/tests/validation_new/Helpers.h index 3058b8eaee..30959161bb 100644 --- a/tests/validation_new/Helpers.h +++ b/tests/validation_new/Helpers.h @@ -128,6 +128,14 @@ std::pair get_activation_layer_test_bounds(ActivationLayerInfo::Activation return bounds; } + +/** Calculate output tensor shape give a vector of input tensor to concatenate + * + * @param[in] input_shapes Shapes of the tensors to concatenate across depth. + * + * @return The shape of output concatenated tensor. + */ +TensorShape calculate_depth_concatenate_shape(const std::vector &input_shapes); } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation_new/NEON/DepthConcatenateLayer.cpp b/tests/validation_new/NEON/DepthConcatenateLayer.cpp new file mode 100644 index 0000000000..d6400d2df5 --- /dev/null +++ b/tests/validation_new/NEON/DepthConcatenateLayer.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2017 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/Types.h" +#include "arm_compute/runtime/NEON/functions/NEDepthConcatenate.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" +#include "framework/Asserts.h" +#include "framework/Macros.h" +#include "framework/datasets/Datasets.h" +#include "tests/NEON/Accessor.h" +#include "tests/datasets_new/ShapeDatasets.h" +#include "tests/validation_new/Validation.h" +#include "tests/validation_new/fixtures/DepthConcatenateLayerFixture.h" +#include "tests/validation_new/half.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(NEON) +TEST_SUITE(DepthConcatenateLayer) + +//TODO(COMPMID-415): Add configuration test? + +template +using NEDepthConcatenateLayerFixture = DepthConcatenateValidationFixture; + +TEST_SUITE(Float) +#ifdef ARM_COMPUTE_ENABLE_FP16 +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", + DataType::F16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), framework::dataset::make("DataType", + DataType::F16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() +#endif /* ARM_COMPUTE_ENABLE_FP16 */ + +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType", + DataType::F32))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), framework::dataset::make("DataType", + DataType::F32))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE(Quantized) +TEST_SUITE(QS8) +FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), + framework::dataset::make("DataType", + DataType::QS8))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), + framework::dataset::make("DataType", + DataType::QS8))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() + +TEST_SUITE(QS16) +FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConcatenateLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), + framework::dataset::make("DataType", + DataType::QS16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthConcatenateLayerFixture, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), + framework::dataset::make("DataType", + DataType::QS16))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation_new/fixtures/DepthConcatenateLayerFixture.h b/tests/validation_new/fixtures/DepthConcatenateLayerFixture.h new file mode 100644 index 0000000000..601758f80e --- /dev/null +++ b/tests/validation_new/fixtures/DepthConcatenateLayerFixture.h @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2017 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_DEPTHCONCATENATE_LAYER_FIXTURE +#define ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "framework/Asserts.h" +#include "framework/Fixture.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/validation_new/CPP/DepthConcatenateLayer.h" +#include "tests/validation_new/Helpers.h" + +#include + +namespace arm_compute +{ +class ITensor; +class Tensor; +class ICLTensor; +class CLTensor; + +namespace test +{ +namespace validation +{ +template +class DepthConcatenateValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape, DataType data_type) + { + // Create input shapes + std::mt19937 gen(library->seed()); + std::uniform_int_distribution<> num_dis(2, 6); + const int num_tensors = num_dis(gen); + + std::vector shapes(num_tensors, shape); + std::uniform_int_distribution<> depth_dis(1, 7); + std::bernoulli_distribution mutate_dis(0.25f); + std::uniform_real_distribution<> change_dis(-0.25f, 0.f); + + // Generate more shapes based on the input + for(auto &s : shapes) + { + // Set the depth of the tensor + s.set(2, depth_dis(gen)); + + // Randomly change the first dimension + if(mutate_dis(gen)) + { + // Decrease the dimension by a small percentage. Don't increase + // as that could make tensor too large. Also the change must be + // an even number. Otherwise out depth concatenate fails. + s.set(0, s[0] + 2 * static_cast(s[0] * change_dis(gen))); + } + + // Repeat the same as above for the second dimension + if(mutate_dis(gen)) + { + s.set(1, s[1] + 2 * static_cast(s[1] * change_dis(gen))); + } + } + + _target = compute_target(shapes, data_type); + _reference = compute_reference(shapes, data_type); + } + +protected: + template + void fill(U &&tensor, int i) + { + library->fill_tensor_uniform(tensor, i); + } + + TensorType compute_target(std::vector shapes, DataType data_type) + { + using ITensorType = typename std::conditional::value, ITensor, ICLTensor>::type; + + std::vector srcs; + std::vector src_ptrs; + + // Create tensors + srcs.reserve(shapes.size()); + + for(const auto &shape : shapes) + { + srcs.emplace_back(create_tensor(shape, data_type, 1, _fractional_bits)); + src_ptrs.emplace_back(&srcs.back()); + } + + TensorShape dst_shape = calculate_depth_concatenate_shape(shapes); + TensorType dst = create_tensor(dst_shape, data_type, 1, _fractional_bits); + + // Create and configure function + FunctionType depth_concat; + depth_concat.configure(src_ptrs, &dst); + + for(auto &src : srcs) + { + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + } + + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + for(auto &src : srcs) + { + src.allocator()->allocate(); + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + } + + dst.allocator()->allocate(); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + int i = 0; + for(auto &src : srcs) + { + fill(AccessorType(src), i++); + } + + // Compute function + depth_concat.run(); + + return dst; + } + + SimpleTensor compute_reference(std::vector shapes, DataType data_type) + { + std::vector> srcs; + + // Create and fill tensors + int i = 0; + for(const auto &shape : shapes) + { + srcs.emplace_back(shape, data_type, 1, _fractional_bits); + fill(srcs.back(), i++); + } + + return reference::depthconcatenate_layer(srcs); + } + + TensorType _target{}; + SimpleTensor _reference{}; + +private: + int _fractional_bits{ 1 }; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_FIXTURE */ -- cgit v1.2.1