blob: 68d023715ceaed05349853d257996f6d952fc152 [file] [log] [blame]
Ioan-Cristian Szaboae3c8ab2017-11-16 17:55:03 +00001/*
2 * Copyright (c) 2017-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_CHANNEL_COMBINE_FIXTURE
25#define ARM_COMPUTE_TEST_CHANNEL_COMBINE_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
34#include "tests/validation/Helpers.h"
35#include "tests/validation/reference/ChannelCombine.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45template <typename TensorType>
46inline std::vector<TensorType> create_tensor_planes(const TensorShape &shape, Format format)
47{
48 TensorShape image_shape = adjust_odd_shape(shape, format);
49 TensorInfo info(image_shape, Format::U8);
50
51 std::vector<TensorType> tensor_planes;
52
53 switch(format)
54 {
55 case Format::RGB888:
56 case Format::RGBA8888:
57 case Format::YUV444:
58 {
59 tensor_planes.resize(3);
60
61 if(format == Format::RGBA8888)
62 {
63 tensor_planes.resize(4);
64 }
65
66 for(unsigned int plane_idx = 0; plane_idx < tensor_planes.size(); ++plane_idx)
67 {
68 tensor_planes[plane_idx].allocator()->init(info);
69 }
70
71 break;
72 }
73 case Format::YUYV422:
74 case Format::UYVY422:
75 {
76 const TensorShape uv_shape = calculate_subsampled_shape(image_shape, format);
77 const TensorInfo info_hor2(uv_shape, Format::U8);
78
79 tensor_planes.resize(3);
80
81 tensor_planes[0].allocator()->init(info);
82 tensor_planes[1].allocator()->init(info_hor2);
83 tensor_planes[2].allocator()->init(info_hor2);
84 break;
85 }
86 case Format::NV12:
87 case Format::NV21:
88 case Format::IYUV:
89 {
90 const TensorShape sub2_shape = calculate_subsampled_shape(image_shape, format);
91 const TensorInfo info_sub2(sub2_shape, Format::U8);
92
93 tensor_planes.resize(3);
94
95 tensor_planes[0].allocator()->init(info);
96 tensor_planes[1].allocator()->init(info_sub2);
97 tensor_planes[2].allocator()->init(info_sub2);
98 break;
99 }
100 default:
101 ARM_COMPUTE_ERROR("Not supported");
102 break;
103 }
104
105 return tensor_planes;
106}
107} // namespace
108
109template <typename MultiImageType, typename TensorType, typename AccessorType, typename FunctionType, typename T>
110class ChannelCombineValidationFixture : public framework::Fixture
111{
112public:
113 template <typename...>
114 void setup(TensorShape shape, Format format)
115 {
116 _num_planes = num_planes_from_format(format);
117 _target = compute_target(shape, format);
118 _reference = compute_reference(shape, format);
119 }
120
121protected:
122 template <typename U>
123 void fill(U &&tensor, int i)
124 {
125 library->fill_tensor_uniform(tensor, i);
126 }
127
128 template <typename U>
129 std::vector<SimpleTensor<U>> create_tensor_planes_reference(const TensorShape &shape, Format format)
130 {
131 std::vector<SimpleTensor<U>> tensor_planes;
132
133 TensorShape image_shape = adjust_odd_shape(shape, format);
134
135 switch(format)
136 {
137 case Format::RGB888:
138 case Format::RGBA8888:
139 case Format::YUV444:
140 {
141 if(format == Format::RGBA8888)
142 {
143 tensor_planes.emplace_back(image_shape, Format::U8);
144 }
145
146 tensor_planes.emplace_back(image_shape, Format::U8);
147 tensor_planes.emplace_back(image_shape, Format::U8);
148 tensor_planes.emplace_back(image_shape, Format::U8);
149 break;
150 }
151 case Format::YUYV422:
152 case Format::UYVY422:
153 {
154 const TensorShape hor2_shape = calculate_subsampled_shape(image_shape, format);
155
156 tensor_planes.emplace_back(image_shape, Format::U8);
157 tensor_planes.emplace_back(hor2_shape, Format::U8);
158 tensor_planes.emplace_back(hor2_shape, Format::U8);
159 break;
160 }
161 case Format::NV12:
162 case Format::NV21:
163 case Format::IYUV:
164 {
165 const TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, format);
166
167 tensor_planes.emplace_back(image_shape, Format::U8);
168 tensor_planes.emplace_back(shape_sub2, Format::U8);
169 tensor_planes.emplace_back(shape_sub2, Format::U8);
170 break;
171 }
172 default:
173 ARM_COMPUTE_ERROR("Not supported");
174 break;
175 }
176
177 return tensor_planes;
178 }
179
180 MultiImageType compute_target(const TensorShape &shape, Format format)
181 {
182 // Create tensors
183 std::vector<TensorType> ref_src = create_tensor_planes<TensorType>(shape, format);
184 MultiImageType dst = create_multi_image<MultiImageType>(shape, format);
185
186 // Create and configure function
187 FunctionType channel_combine;
188
189 if(1 == _num_planes)
190 {
191 const TensorType *tensor_extra = ((Format::RGBA8888 == format) ? &ref_src[3] : nullptr);
192 TensorType *tensor_dst = dynamic_cast<TensorType *>(dst.plane(0));
193
194 channel_combine.configure(&ref_src[0], &ref_src[1], &ref_src[2], tensor_extra, tensor_dst);
195 }
196 else
197 {
198 channel_combine.configure(&ref_src[0], &ref_src[1], &ref_src[2], &dst);
199 }
200
201 for(unsigned int plane_idx = 0; plane_idx < _num_planes; ++plane_idx)
202 {
203 const TensorType *dst_plane = static_cast<const TensorType *>(dst.plane(plane_idx));
204
205 ARM_COMPUTE_EXPECT(dst_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
206 }
207
208 for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx)
209 {
210 ARM_COMPUTE_EXPECT(ref_src[plane_idx].info()->is_resizable(), framework::LogLevel::ERRORS);
211 }
212
213 // Allocate tensors
214 dst.allocate();
215
216 for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx)
217 {
218 ref_src[plane_idx].allocator()->allocate();
219 }
220
221 for(unsigned int plane_idx = 0; plane_idx < _num_planes; ++plane_idx)
222 {
223 const TensorType *dst_plane = static_cast<const TensorType *>(dst.plane(plane_idx));
224
225 ARM_COMPUTE_EXPECT(!dst_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
226 }
227
228 for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx)
229 {
230 ARM_COMPUTE_EXPECT(!ref_src[plane_idx].info()->is_resizable(), framework::LogLevel::ERRORS);
231 }
232
233 // Fill tensor planes
234 for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx)
235 {
236 fill(AccessorType(ref_src[plane_idx]), plane_idx);
237 }
238
239 // Compute function
240 channel_combine.run();
241
242 return dst;
243 }
244
245 std::vector<SimpleTensor<T>> compute_reference(const TensorShape &shape, Format format)
246 {
247 // Create reference
248 std::vector<SimpleTensor<T>> ref_src = create_tensor_planes_reference<T>(shape, format);
249
250 // Fill references
251 for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx)
252 {
253 fill(ref_src[plane_idx], plane_idx);
254 }
255
256 return reference::channel_combine<T>(shape, ref_src, format);
257 }
258
259 unsigned int _num_planes{};
260 MultiImageType _target{};
261 std::vector<SimpleTensor<T>> _reference{};
262};
263} // namespace validation
264} // namespace test
265} // namespace arm_compute
266#endif /* ARM_COMPUTE_TEST_CHANNEL_COMBINE_FIXTURE */