blob: d327b0914e1cd84ecd0c636c15d0b40b26d89f55 [file] [log] [blame]
giuros0118870812018-09-13 09:31:40 +01001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_TEST_ROIALIGNLAYER_FIXTURE
25#define ARM_COMPUTE_TEST_ROIALIGNLAYER_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "arm_compute/runtime/CL/functions/CLROIAlignLayer.h"
30#include "tests/AssetsLibrary.h"
31#include "tests/Globals.h"
32#include "tests/IAccessor.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Fixture.h"
35#include "tests/validation/Helpers.h"
36#include "tests/validation/reference/ROIAlignLayer.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename Array_T, typename ArrayAccessor, typename T>
45class ROIAlignLayerFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape input_shape, const ROIPoolingLayerInfo pool_info, unsigned int num_rois, DataType data_type, int batches)
50 {
51 input_shape.set(2, batches);
52 std::vector<ROI> rois = generate_random_rois(input_shape, pool_info, num_rois, 0U);
53
54 _target = compute_target(input_shape, data_type, rois, pool_info);
55 _reference = compute_reference(input_shape, data_type, rois, pool_info);
56 }
57
58protected:
59 template <typename U>
60 void fill(U &&tensor)
61 {
62 library->fill_tensor_uniform(tensor, 0);
63 }
64
65 TensorType compute_target(const TensorShape &input_shape,
66 DataType data_type,
67 std::vector<ROI> const &rois,
68 const ROIPoolingLayerInfo &pool_info)
69 {
70 // Create tensors
71 TensorType src = create_tensor<TensorType>(input_shape, data_type);
72 TensorType dst;
73
74 size_t num_rois = rois.size();
75
76 // Create roi arrays
77 std::unique_ptr<Array_T> rois_array = arm_compute::support::cpp14::make_unique<Array_T>(num_rois);
78 fill_array(ArrayAccessor(*rois_array), rois);
79
80 // Create and configure function
81 FunctionType roi_align_layer;
82 roi_align_layer.configure(&src, rois_array.get(), &dst, pool_info);
83
84 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
86
87 // Allocate tensors
88 src.allocator()->allocate();
89 dst.allocator()->allocate();
90
91 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
92 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
93
94 // Fill tensors
95 fill(AccessorType(src));
96
97 // Compute function
98 roi_align_layer.run();
99
100 return dst;
101 }
102
103 SimpleTensor<T> compute_reference(const TensorShape &input_shape,
104 DataType data_type,
105 std::vector<ROI> const &rois,
106 const ROIPoolingLayerInfo &pool_info)
107 {
108 // Create reference tensor
109 SimpleTensor<T> src{ input_shape, data_type };
110
111 // Fill reference tensor
112 fill(src);
113
114 return reference::roi_align_layer(src, rois, pool_info);
115 }
116
117 TensorType _target{};
118 SimpleTensor<T> _reference{};
119};
120
121} // namespace validation
122} // namespace test
123} // namespace arm_compute
124#endif /* ARM_COMPUTE_TEST_ROIALIGNLAYER_FIXTURE */