blob: 6656e1482e279e4b6434c844d97a175f0118dc88 [file] [log] [blame]
Sanghoon Leec7b82f12018-07-06 13:27:27 +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_COLOR_CONVERT_FIXTURE
25#define ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/Globals.h"
30#include "tests/Utils.h"
31#include "tests/framework/Fixture.h"
32
33namespace arm_compute
34{
35namespace test
36{
37namespace benchmark
38{
39template <typename MultiImageType, typename TensorType, typename AccessorType, typename FunctionType>
40class ColorConvertFixture : public framework::Fixture
41{
42public:
43 template <typename...>
44 void setup(TensorShape input_shape, Format src_format, Format dst_format)
45 {
46 _src_num_planes = num_planes_from_format(src_format);
47 _dst_num_planes = num_planes_from_format(dst_format);
48
49 TensorShape dst_shape = adjust_odd_shape(input_shape, src_format);
50 dst_shape = adjust_odd_shape(dst_shape, dst_format);
51
52 // Create tensors
53 ref_src = create_multi_image<MultiImageType>(dst_shape, src_format);
54 ref_dst = create_multi_image<MultiImageType>(dst_shape, dst_format);
55
56 if(1U == _src_num_planes)
57 {
58 const TensorType *plane_src = static_cast<TensorType *>(ref_src.plane(0));
59
60 if(1U == _dst_num_planes)
61 {
62 TensorType *plane_dst = static_cast<TensorType *>(ref_dst.plane(0));
63 colorconvert_func.configure(plane_src, plane_dst);
64 }
65 else
66 {
67 colorconvert_func.configure(plane_src, &ref_dst);
68 }
69 }
70 else
71 {
72 if(1U == _dst_num_planes)
73 {
74 TensorType *plane_dst = static_cast<TensorType *>(ref_dst.plane(0));
75 colorconvert_func.configure(&ref_src, plane_dst);
76 }
77 else
78 {
79 colorconvert_func.configure(&ref_src, &ref_dst);
80 }
81 }
82
83 // Allocate tensors
84 ref_src.allocate();
85 ref_dst.allocate();
86
87 // Fill tensor planes
88 for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx)
89 {
90 TensorType *src_plane = static_cast<TensorType *>(ref_src.plane(plane_idx));
91
92 fill(AccessorType(*src_plane), plane_idx);
93 }
94 }
95
96 void run()
97 {
98 colorconvert_func.run();
99 }
100
101 void sync()
102 {
103 sync_if_necessary<TensorType>();
104 for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx)
105 {
106 TensorType *dst_plane = static_cast<TensorType *>(ref_dst.plane(plane_idx));
107 sync_tensor_if_necessary<TensorType>(*dst_plane);
108 }
109 }
110
111 void teardown()
112 {
113 for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx)
114 {
115 TensorType *src_plane = static_cast<TensorType *>(ref_src.plane(plane_idx));
116 src_plane->allocator()->free();
117 }
118 for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx)
119 {
120 TensorType *dst_plane = static_cast<TensorType *>(ref_dst.plane(plane_idx));
121 dst_plane->allocator()->free();
122 }
123 }
124
125protected:
126 template <typename U>
127 void fill(U &&tensor, int i)
128 {
129 library->fill_tensor_uniform(tensor, i);
130 }
131
132private:
133 MultiImageType ref_src{};
134 MultiImageType ref_dst{};
135 FunctionType colorconvert_func{};
136
137 unsigned int _src_num_planes{};
138 unsigned int _dst_num_planes{};
139};
140} // namespace benchmark
141} // namespace test
142} // namespace arm_compute
143#endif /* ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE */