diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CL/CLArrayAccessor.h | 83 | ||||
-rw-r--r-- | tests/IArrayAccessor.h | 60 | ||||
-rw-r--r-- | tests/NEON/ArrayAccessor.h | 73 | ||||
-rw-r--r-- | tests/NEON/Helper.h | 12 | ||||
-rw-r--r-- | tests/Utils.h | 55 | ||||
-rw-r--r-- | tests/benchmark_new/CL/ROIPoolingLayer.cpp | 53 | ||||
-rw-r--r-- | tests/benchmark_new/NEON/ROIPoolingLayer.cpp | 53 | ||||
-rw-r--r-- | tests/datasets_new/ROIPoolingLayerDataset.h | 127 | ||||
-rw-r--r-- | tests/fixtures_new/ROIPoolingLayerFixture.h | 95 | ||||
-rw-r--r-- | tests/validation/CL/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/validation/CL/ROIPoolingLayer.cpp | 112 | ||||
-rw-r--r-- | tests/validation/Helpers.cpp | 72 | ||||
-rw-r--r-- | tests/validation/Helpers.h | 13 | ||||
-rw-r--r-- | tests/validation/NEON/Gaussian5x5.cpp | 2 | ||||
-rw-r--r-- | tests/validation/NEON/ROIPoolingLayer.cpp | 12 |
15 files changed, 728 insertions, 103 deletions
diff --git a/tests/CL/CLArrayAccessor.h b/tests/CL/CLArrayAccessor.h new file mode 100644 index 0000000000..a38907dd78 --- /dev/null +++ b/tests/CL/CLArrayAccessor.h @@ -0,0 +1,83 @@ +/* + * 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_CLARRAYACCESSOR_H__ +#define __ARM_COMPUTE_TEST_CLARRAYACCESSOR_H__ + +#include "arm_compute/runtime/CL/CLArray.h" +#include "tests/IArrayAccessor.h" + +namespace arm_compute +{ +namespace test +{ +/** Accessor implementation for @ref CLArray objects. */ +template <typename T> +class CLArrayAccessor : public IArrayAccessor<T> +{ +public: + /** Create an accessor for the given @p array. + * + * @param[in, out] array To be accessed array. + * + * @note The CL memory is mapped by the constructor. + * + */ + CLArrayAccessor(CLArray<T> &array) + : _array{ array } + { + _array.map(); + } + + CLArrayAccessor(const CLArrayAccessor &) = delete; + CLArrayAccessor &operator=(const CLArrayAccessor &) = delete; + CLArrayAccessor(CLArrayAccessor &&) = default; + CLArrayAccessor &operator=(CLArrayAccessor &&) = default; + + /** Destructor that unmaps the CL memory. */ + ~CLArrayAccessor() + { + _array.unmap(); + } + + int num_values() const override + { + return _array.num_values(); + } + + T *buffer() override + { + return _array.buffer(); + } + + void resize(size_t num) override + { + _array.resize(num); + } + +private: + CLArray<T> &_array; +}; +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_CLARRAYACCESSOR_H__ */ diff --git a/tests/IArrayAccessor.h b/tests/IArrayAccessor.h new file mode 100644 index 0000000000..73f8829ed2 --- /dev/null +++ b/tests/IArrayAccessor.h @@ -0,0 +1,60 @@ +/* + * 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_IARRAYACCESSOR_H__ +#define __ARM_COMPUTE_TEST_IARRAYACCESSOR_H__ + +namespace arm_compute +{ +namespace test +{ +/** Common interface to provide information and access to array like + * structures. + */ +template <typename T> +class IArrayAccessor +{ +public: + using value_type = T; + + /** Virtual destructor. */ + virtual ~IArrayAccessor() = default; + + /** Number of elements of the tensor. */ + virtual int num_values() const = 0; + + /** Access to the buffer. + * + * @return A pointer to the first element in the buffer. + */ + virtual T *buffer() = 0; + + /** Resize array. + * + * @param[in] num The new array size in number of elements + */ + virtual void resize(size_t num) = 0; +}; +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_IARRAYACCESSOR_H__ */ diff --git a/tests/NEON/ArrayAccessor.h b/tests/NEON/ArrayAccessor.h new file mode 100644 index 0000000000..e56e6538ba --- /dev/null +++ b/tests/NEON/ArrayAccessor.h @@ -0,0 +1,73 @@ +/* + * 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_ARRAYACCESSOR_H__ +#define __ARM_COMPUTE_TEST_ARRAYACCESSOR_H__ + +#include "arm_compute/runtime/Array.h" +#include "tests/IArrayAccessor.h" + +namespace arm_compute +{ +namespace test +{ +/** ArrayAccessor implementation for @ref Array objects. */ +template <typename T> +class ArrayAccessor : public IArrayAccessor<T> +{ +public: + /** Create an accessor for the given @p array. + * + * @param[in, out] array To be accessed array. + */ + ArrayAccessor(Array<T> &array) + : _array{ array } + { + } + + ArrayAccessor(const ArrayAccessor &) = delete; + ArrayAccessor &operator=(const ArrayAccessor &) = delete; + ArrayAccessor(ArrayAccessor &&) = default; + ArrayAccessor &operator=(ArrayAccessor &&) = default; + + int num_values() const override + { + return _array.num_values(); + } + + T *buffer() override + { + return _array.buffer(); + } + + void resize(size_t num) override + { + _array.resize(num); + } + +private: + Array<T> &_array; +}; +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_ARRAYACCESSOR_H__ */ diff --git a/tests/NEON/Helper.h b/tests/NEON/Helper.h index 9e60a48ecd..4efab17fca 100644 --- a/tests/NEON/Helper.h +++ b/tests/NEON/Helper.h @@ -35,18 +35,6 @@ namespace arm_compute { namespace test { -template <typename T> -Array<T> create_array(const std::vector<T> &v) -{ - const size_t v_size = v.size(); - Array<T> array(v_size); - - array.resize(v_size); - std::copy(v.begin(), v.end(), array.buffer()); - - return array; -} - template <typename D, typename T, typename... Ts> void fill_tensors(D &&dist, std::initializer_list<int> seeds, T &&tensor, Ts &&... other_tensors) { diff --git a/tests/Utils.h b/tests/Utils.h index 93831aa30b..f1725d7d74 100644 --- a/tests/Utils.h +++ b/tests/Utils.h @@ -37,9 +37,11 @@ #include <cstddef> #include <limits> #include <memory> +#include <random> #include <sstream> #include <string> #include <type_traits> +#include <vector> namespace arm_compute { @@ -421,6 +423,59 @@ inline T create_tensor(const TensorShape &shape, DataType data_type, int num_cha return tensor; } + +/** Create a vector of random ROIs. + * + * @param[in] shape The shape of the input tensor. + * @param[in] pool_info The ROI pooling information. + * @param[in] num_rois The number of ROIs to be created. + * @param[in] seed The random seed to be used. + * + * @return A vector that contains the requested number of random ROIs + */ +inline std::vector<ROI> generate_random_rois(const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, unsigned int num_rois, std::random_device::result_type seed) +{ + ARM_COMPUTE_ERROR_ON((pool_info.pooled_width() < 4) || (pool_info.pooled_height() < 4)); + + std::vector<ROI> rois; + std::mt19937 gen(seed); + const int pool_width = pool_info.pooled_width(); + const int pool_height = pool_info.pooled_height(); + const float roi_scale = pool_info.spatial_scale(); + + // Calculate distribution bounds + const auto scaled_width = static_cast<int>((shape.x() / roi_scale) / pool_width); + const auto scaled_height = static_cast<int>((shape.y() / roi_scale) / pool_height); + const auto min_width = static_cast<int>(pool_width / roi_scale); + const auto min_height = static_cast<int>(pool_height / roi_scale); + + // Create distributions + std::uniform_int_distribution<int> dist_batch(0, shape[3] - 1); + std::uniform_int_distribution<int> dist_x(0, scaled_width); + std::uniform_int_distribution<int> dist_y(0, scaled_height); + std::uniform_int_distribution<int> dist_w(min_width, std::max(min_width, (pool_width - 2) * scaled_width)); + std::uniform_int_distribution<int> dist_h(min_height, std::max(min_height, (pool_height - 2) * scaled_height)); + + for(unsigned int r = 0; r < num_rois; ++r) + { + ROI roi; + roi.batch_idx = dist_batch(gen); + roi.rect.x = dist_x(gen); + roi.rect.y = dist_y(gen); + roi.rect.width = dist_w(gen); + roi.rect.height = dist_h(gen); + rois.push_back(roi); + } + + return rois; +} + +template <typename T, typename ArrayAccessor_T> +inline void fill_array(ArrayAccessor_T &&array, const std::vector<T> &v) +{ + array.resize(v.size()); + std::memcpy(array.buffer(), v.data(), v.size() * sizeof(T)); +} } // namespace test } // namespace arm_compute #endif /* __ARM_COMPUTE_TEST_UTILS_H__ */ diff --git a/tests/benchmark_new/CL/ROIPoolingLayer.cpp b/tests/benchmark_new/CL/ROIPoolingLayer.cpp new file mode 100644 index 0000000000..260f4d7b0d --- /dev/null +++ b/tests/benchmark_new/CL/ROIPoolingLayer.cpp @@ -0,0 +1,53 @@ +/* + * 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/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/CL/CLArray.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLROIPoolingLayer.h" +#include "framework/Macros.h" +#include "framework/datasets/Datasets.h" +#include "tests/CL/CLAccessor.h" +#include "tests/CL/CLArrayAccessor.h" +#include "tests/TypePrinter.h" +#include "tests/datasets_new/ROIPoolingLayerDataset.h" +#include "tests/fixtures_new/ROIPoolingLayerFixture.h" + +namespace arm_compute +{ +namespace test +{ +using CLROIPoolingLayerFixture = ROIPoolingLayerFixture<CLTensor, CLROIPoolingLayer, CLAccessor, CLArray<ROI>, CLArrayAccessor<ROI>>; + +TEST_SUITE(CL) + +REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayer, CLROIPoolingLayerFixture, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::SmallROIPoolingLayerDataset(), + framework::dataset::make("DataType", { DataType::F16, DataType::F32 })), + framework::dataset::make("Batches", { 1, 4, 8 }))); + +TEST_SUITE_END() +} // namespace test +} // namespace arm_compute diff --git a/tests/benchmark_new/NEON/ROIPoolingLayer.cpp b/tests/benchmark_new/NEON/ROIPoolingLayer.cpp new file mode 100644 index 0000000000..e8c5ba3109 --- /dev/null +++ b/tests/benchmark_new/NEON/ROIPoolingLayer.cpp @@ -0,0 +1,53 @@ +/* + * 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/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/Array.h" +#include "arm_compute/runtime/NEON/functions/NEROIPoolingLayer.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" +#include "framework/Macros.h" +#include "framework/datasets/Datasets.h" +#include "tests/NEON/Accessor.h" +#include "tests/NEON/ArrayAccessor.h" +#include "tests/TypePrinter.h" +#include "tests/datasets_new/ROIPoolingLayerDataset.h" +#include "tests/fixtures_new/ROIPoolingLayerFixture.h" + +namespace arm_compute +{ +namespace test +{ +using NEROIPoolingLayerFixture = ROIPoolingLayerFixture<Tensor, NEROIPoolingLayer, Accessor, Array<ROI>, ArrayAccessor<ROI>>; + +TEST_SUITE(NEON) + +REGISTER_FIXTURE_DATA_TEST_CASE(SmallROIPoolingLayer, NEROIPoolingLayerFixture, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::SmallROIPoolingLayerDataset(), + framework::dataset::make("DataType", { DataType::F32 })), + framework::dataset::make("Batches", { 1, 4, 8 }))); + +TEST_SUITE_END() +} // namespace test +} // namespace arm_compute diff --git a/tests/datasets_new/ROIPoolingLayerDataset.h b/tests/datasets_new/ROIPoolingLayerDataset.h new file mode 100644 index 0000000000..c68a33fe8f --- /dev/null +++ b/tests/datasets_new/ROIPoolingLayerDataset.h @@ -0,0 +1,127 @@ +/* + * 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_ROI_POOLING_LAYER_DATASET +#define ARM_COMPUTE_TEST_ROI_POOLING_LAYER_DATASET + +#include "tests/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class ROIPoolingLayerDataset +{ +public: + using type = std::tuple<TensorShape, ROIPoolingLayerInfo, int>; + + struct iterator + { + iterator(std::vector<TensorShape>::const_iterator tensor_shape_it, + std::vector<ROIPoolingLayerInfo>::const_iterator infos_it, + std::vector<unsigned int>::const_iterator num_rois_it) + : _tensor_shape_it{ std::move(tensor_shape_it) }, + _infos_it{ std::move(infos_it) }, + _num_rois_it{ std::move(num_rois_it) } + { + } + + std::string description() const + { + std::stringstream description; + description << "In=" << *_tensor_shape_it << ":"; + description << "Info=" << *_infos_it; + description << "NumROIS=" << *_num_rois_it; + return description.str(); + } + + ROIPoolingLayerDataset::type operator*() const + { + return std::make_tuple(*_tensor_shape_it, *_infos_it, *_num_rois_it); + } + + iterator &operator++() + { + ++_tensor_shape_it; + ++_infos_it; + ++_num_rois_it; + + return *this; + } + + private: + std::vector<TensorShape>::const_iterator _tensor_shape_it; + std::vector<ROIPoolingLayerInfo>::const_iterator _infos_it; + std::vector<unsigned int>::const_iterator _num_rois_it; + }; + + iterator begin() const + { + return iterator(_tensor_shapes.begin(), _infos.begin(), _num_rois.begin()); + } + + int size() const + { + return std::min(std::min(_tensor_shapes.size(), _infos.size()), _num_rois.size()); + } + + void add_config(TensorShape tensor_shape, ROIPoolingLayerInfo info, unsigned int num_rois) + { + _tensor_shapes.emplace_back(std::move(tensor_shape)); + _infos.emplace_back(std::move(info)); + _num_rois.emplace_back(std::move(num_rois)); + } + +protected: + ROIPoolingLayerDataset() = default; + ROIPoolingLayerDataset(ROIPoolingLayerDataset &&) = default; + +private: + std::vector<TensorShape> _tensor_shapes{}; + std::vector<ROIPoolingLayerInfo> _infos{}; + std::vector<unsigned int> _num_rois{}; +}; + +class SmallROIPoolingLayerDataset final : public ROIPoolingLayerDataset +{ +public: + SmallROIPoolingLayerDataset() + { + add_config(TensorShape(50U, 47U, 3U), ROIPoolingLayerInfo(7U, 7U, 1.f / 8.f), 40U); + add_config(TensorShape(50U, 47U, 10U), ROIPoolingLayerInfo(7U, 7U, 1.f / 8.f), 80U); + add_config(TensorShape(50U, 47U, 80U), ROIPoolingLayerInfo(7U, 7U, 1.f / 8.f), 80U); + add_config(TensorShape(50U, 47U, 3U), ROIPoolingLayerInfo(9U, 9U, 1.f / 8.f), 40U); + add_config(TensorShape(50U, 47U, 10U), ROIPoolingLayerInfo(9U, 9U, 1.f / 8.f), 80U); + add_config(TensorShape(50U, 47U, 80U), ROIPoolingLayerInfo(9U, 9U, 1.f / 8.f), 80U); + } +}; + +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_ROI_POOLING_LAYER_DATASET */ diff --git a/tests/fixtures_new/ROIPoolingLayerFixture.h b/tests/fixtures_new/ROIPoolingLayerFixture.h new file mode 100644 index 0000000000..54dac51ee4 --- /dev/null +++ b/tests/fixtures_new/ROIPoolingLayerFixture.h @@ -0,0 +1,95 @@ +/* + * 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_ROIPOOLINGLAYERFIXTURE +#define ARM_COMPUTE_TEST_ROIPOOLINGLAYERFIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "framework/Fixture.h" +#include "tests/Globals.h" +#include "tests/Utils.h" + +#include <vector> + +namespace arm_compute +{ +namespace test +{ +/** Fixture that can be used for NEON and CL */ +template <typename TensorType, typename Function, typename Accessor, typename Array_T, typename ArrayAccessor> +class ROIPoolingLayerFixture : public framework::Fixture +{ +public: + template <typename...> + void setup(TensorShape shape, const ROIPoolingLayerInfo pool_info, unsigned int num_rois, DataType data_type, int batches) + { + // Set batched in source and destination shapes + const unsigned int fixed_point_position = 4; + TensorShape shape_dst; + shape.set(shape.num_dimensions(), batches); + shape_dst.set(0, pool_info.pooled_width()); + shape_dst.set(1, pool_info.pooled_height()); + shape_dst.set(2, shape.z()); + shape_dst.set(3, num_rois); + + // Create tensors + src = create_tensor<TensorType>(shape, data_type, 1, fixed_point_position); + dst = create_tensor<TensorType>(shape_dst, data_type, 1, fixed_point_position); + + // Create random ROIs + std::vector<ROI> rois = generate_random_rois(shape, pool_info, num_rois, 0U); + rois_array = arm_compute::support::cpp14::make_unique<Array_T>(num_rois); + fill_array(ArrayAccessor(*rois_array), rois); + + // Create and configure function + roi_pool.configure(&src, rois_array.get(), &dst, pool_info); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + // Fill tensors + library->fill_tensor_uniform(Accessor(src), 0); + } + + void run() + { + roi_pool.run(); + } + + void teardown() + { + src.allocator()->free(); + dst.allocator()->free(); + } + +private: + TensorType src{}; + TensorType dst{}; + std::unique_ptr<Array_T> rois_array{}; + Function roi_pool{}; +}; +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_ROIPOOLINGLAYERFIXTURE */ diff --git a/tests/validation/CL/CMakeLists.txt b/tests/validation/CL/CMakeLists.txt index 67900b3edc..f4477f621f 100644 --- a/tests/validation/CL/CMakeLists.txt +++ b/tests/validation/CL/CMakeLists.txt @@ -27,15 +27,24 @@ set(arm_compute_test_validation_OPENCL_SOURCE_FILES ${CMAKE_SOURCE_DIR}/CL/CLAccessor.h ${CMAKE_CURRENT_SOURCE_DIR}/CLFixture.h ${CMAKE_CURRENT_SOURCE_DIR}/CLFixture.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ActivationLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/BitwiseAnd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Box3x3.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ConvolutionLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DepthConvert.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FillBorder.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FixedPoint/FixedPoint_QS8.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FullyConnectedLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gaussian3x3.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gaussian5x5.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/GEMM.cpp ` ${CMAKE_CURRENT_SOURCE_DIR}/IntegralImage.cpp +` ${CMAKE_CURRENT_SOURCE_DIR}/NonLinearFilter.cpp +` ${CMAKE_CURRENT_SOURCE_DIR}/PoolingLayer.cpp +` ${CMAKE_CURRENT_SOURCE_DIR}/ROIPoolingLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Sobel3x3.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Sobel5x5.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SoftmaxLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Threshold.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DirectConvolutionLayer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/MeanStdDev.cpp diff --git a/tests/validation/CL/ROIPoolingLayer.cpp b/tests/validation/CL/ROIPoolingLayer.cpp new file mode 100644 index 0000000000..19d7903128 --- /dev/null +++ b/tests/validation/CL/ROIPoolingLayer.cpp @@ -0,0 +1,112 @@ +/* + * 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 "CL/CLAccessor.h" +#include "CL/CLArrayAccessor.h" +#include "TypePrinter.h" +#include "arm_compute/runtime/CL/CLArray.h" +#include "arm_compute/runtime/CL/functions/CLROIPoolingLayer.h" +#include "tests/Globals.h" +#include "tests/Utils.h" +#include "validation/Datasets.h" +#include "validation/Reference.h" +#include "validation/Validation.h" +#include "validation/ValidationUserConfiguration.h" + +#include <random> +#include <vector> + +using namespace arm_compute; +using namespace arm_compute::test; +using namespace arm_compute::test::validation; + +namespace +{ +CLTensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, ROIPoolingLayerInfo pool_info) +{ + TensorShape shape_dst; + shape_dst.set(0, pool_info.pooled_width()); + shape_dst.set(1, pool_info.pooled_height()); + shape_dst.set(2, shape.z()); + shape_dst.set(3, rois.size()); + + // Create tensors + CLTensor src = create_tensor<CLTensor>(shape, dt); + CLTensor dst = create_tensor<CLTensor>(shape_dst, dt); + + // Create ROI array + CLArray<ROI> rois_array(rois.size()); + fill_array(CLArrayAccessor<ROI>(rois_array), rois); + + // Create and configure function + CLROIPoolingLayer roi_pool; + roi_pool.configure(&src, &rois_array, &dst, pool_info); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + BOOST_TEST(!src.info()->is_resizable()); + BOOST_TEST(!dst.info()->is_resizable()); + + // Fill tensors + std::uniform_real_distribution<> distribution(-1, 1); + library->fill(CLAccessor(src), distribution, 0); + + // Compute function + roi_pool.run(); + + return dst; +} +} // namespace + +#ifndef DOXYGEN_SKIP_THIS +BOOST_AUTO_TEST_SUITE(CL) +BOOST_AUTO_TEST_SUITE(ROIPoolingLayer) + +BOOST_AUTO_TEST_SUITE(Float) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RunSmall, boost::unit_test::data::make({ DataType::F16, DataType::F32 }) * boost::unit_test::data::make({ 10, 20, 40 }) * boost::unit_test::data::make({ 7, 9 }) * + boost::unit_test::data::make({ 1.f / 8.f, 1.f / 16.f }), + dt, num_rois, roi_pool_size, roi_scale) +{ + TensorShape shape(50U, 47U, 2U, 3U); + ROIPoolingLayerInfo pool_info(roi_pool_size, roi_pool_size, roi_scale); + + // Construct ROI vector + std::vector<ROI> rois = generate_random_rois(shape, pool_info, num_rois, user_config.seed); + + // Compute function + CLTensor dst = compute_roi_pooling_layer(shape, dt, rois, pool_info); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_roi_pooling_layer(shape, dt, rois, pool_info); + + // 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/Helpers.cpp b/tests/validation/Helpers.cpp deleted file mode 100644 index 747260ea99..0000000000 --- a/tests/validation/Helpers.cpp +++ /dev/null @@ -1,72 +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 "validation/Helpers.h" - -using namespace arm_compute::test; - -namespace arm_compute -{ -namespace test -{ -namespace validation -{ -std::vector<ROI> generate_random_rois(const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, unsigned int num_rois, std::random_device::result_type seed) -{ - ARM_COMPUTE_ERROR_ON((pool_info.pooled_width() < 4) || (pool_info.pooled_height() < 4)); - - std::vector<ROI> rois; - std::mt19937 gen(seed); - const int pool_width = pool_info.pooled_width(); - const int pool_height = pool_info.pooled_height(); - const float roi_scale = pool_info.spatial_scale(); - - // Calculate distribution bounds - const auto scaled_width = static_cast<int>((shape.x() / roi_scale) / pool_width); - const auto scaled_height = static_cast<int>((shape.y() / roi_scale) / pool_height); - const auto min_width = static_cast<int>(pool_width / roi_scale); - const auto min_height = static_cast<int>(pool_height / roi_scale); - - // Create distributions - std::uniform_int_distribution<int> dist_batch(0, shape[3] - 1); - std::uniform_int_distribution<int> dist_x(0, scaled_width); - std::uniform_int_distribution<int> dist_y(0, scaled_height); - std::uniform_int_distribution<int> dist_w(min_width, std::max(min_width, (pool_width - 2) * scaled_width)); - std::uniform_int_distribution<int> dist_h(min_height, std::max(min_height, (pool_height - 2) * scaled_height)); - - for(unsigned int r = 0; r < num_rois; ++r) - { - ROI roi{}; - roi.batch_idx = dist_batch(gen); - roi.rect.x = dist_x(gen); - roi.rect.y = dist_y(gen); - roi.rect.width = dist_w(gen); - roi.rect.height = dist_h(gen); - rois.push_back(roi); - } - - return rois; -} -} // namespace validation -} // namespace test -} // namespace arm_compute diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h index 09ffda8957..19a0c4105c 100644 --- a/tests/validation/Helpers.h +++ b/tests/validation/Helpers.h @@ -32,6 +32,7 @@ #include "tests/validation/half.h" #include <array> +#include <cstring> #include <random> #include <type_traits> #include <utility> @@ -250,17 +251,6 @@ inline void fill_warp_matrix(std::array<float, SIZE> &matrix, int cols, int rows } } -/** Create a vector of random ROIs. - * - * @param[in] shape The shape of the input tensor. - * @param[in] pool_info The ROI pooling information. - * @param[in] num_rois The number of ROIs to be created. - * @param[in] seed The random seed to be used. - * - * @return A vector that contains the requested number of random ROIs - */ -std::vector<ROI> generate_random_rois(const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, unsigned int num_rois, std::random_device::result_type seed); - /** Helper function to fill the Lut random by a ILutAccessor. * * @param[in,out] table Accessor at the Lut. @@ -277,7 +267,6 @@ void fill_lookuptable(T &&table) table[i] = distribution(generator); } } - } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/NEON/Gaussian5x5.cpp b/tests/validation/NEON/Gaussian5x5.cpp index 522ececee9..7727340f66 100644 --- a/tests/validation/NEON/Gaussian5x5.cpp +++ b/tests/validation/NEON/Gaussian5x5.cpp @@ -41,8 +41,6 @@ #include "boost_wrapper.h" -#include <iostream> - #include <random> #include <string> diff --git a/tests/validation/NEON/ROIPoolingLayer.cpp b/tests/validation/NEON/ROIPoolingLayer.cpp index 5775db7e03..523885d908 100644 --- a/tests/validation/NEON/ROIPoolingLayer.cpp +++ b/tests/validation/NEON/ROIPoolingLayer.cpp @@ -22,13 +22,12 @@ * SOFTWARE. */ #include "NEON/Accessor.h" -#include "NEON/Helper.h" +#include "NEON/ArrayAccessor.h" #include "TypePrinter.h" #include "arm_compute/runtime/NEON/functions/NEROIPoolingLayer.h" #include "tests/Globals.h" #include "tests/Utils.h" #include "validation/Datasets.h" -#include "validation/Helpers.h" #include "validation/Reference.h" #include "validation/Validation.h" #include "validation/ValidationUserConfiguration.h" @@ -51,9 +50,12 @@ Tensor compute_roi_pooling_layer(const TensorShape &shape, DataType dt, const st shape_dst.set(3, rois.size()); // Create tensors - Tensor src = create_tensor<Tensor>(shape, dt); - Tensor dst = create_tensor<Tensor>(shape_dst, dt); - Array<ROI> rois_array = create_array(rois); + Tensor src = create_tensor<Tensor>(shape, dt); + Tensor dst = create_tensor<Tensor>(shape_dst, dt); + + // Create ROI array + Array<ROI> rois_array(rois.size()); + fill_array(ArrayAccessor<ROI>(rois_array), rois); // Create and configure function NEROIPoolingLayer roi_pool; |