blob: b3bcb8542697c1d45488da241bf66f614aaf5ed9 [file] [log] [blame]
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +01001/*
2 * Copyright (c) 2020 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_SCALE_VALIDATION_DATASET
25#define ARM_COMPUTE_TEST_SCALE_VALIDATION_DATASET
26
27#include "utils/TypePrinter.h"
28
29#include "arm_compute/core/TensorShape.h"
30#include "arm_compute/core/Types.h"
31#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/InterpolationPolicyDataset.h"
33#include "tests/datasets/SamplingPolicyDataset.h"
34#include "tests/datasets/ShapeDatasets.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace datasets
41{
42/** Class to generate boundary values for the given template parameters
43 * including shapes with large differences between width and height.
44 * element_per_iteration is the number of elements processed by one iteration
45 * of an implementation. (E.g., if an iteration is based on a 16-byte vector
46 * and size of one element is 1-byte, this value would be 16.).
47 * iterations is the total number of complete iterations we want to test
48 * for the effect of larger shapes.
49 */
50template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration, uint32_t iterations>
51class ScaleShapesBaseDataSet : public ShapeDataset
52{
53 static constexpr auto boundary_minus_one = element_per_iteration * iterations - 1;
54 static constexpr auto boundary_plus_one = element_per_iteration * iterations + 1;
55 static constexpr auto small_size = 3;
56
57public:
58 // These tensor shapes are NCHW layout, fixture will convert to NHWC.
59 ScaleShapesBaseDataSet()
60 : ShapeDataset("Shape",
61 {
62 TensorShape{ small_size, boundary_minus_one, channel, batch },
63 TensorShape{ small_size, boundary_plus_one, channel, batch },
64 TensorShape{ boundary_minus_one, small_size, channel, batch },
65 TensorShape{ boundary_plus_one, small_size, channel, batch },
66 TensorShape{ boundary_minus_one, boundary_plus_one, channel, batch },
67 TensorShape{ boundary_plus_one, boundary_minus_one, channel, batch },
68 })
69 {
70 }
71};
72
73/** For the single vector, only larger value (+1) than boundary
74 * since smaller value (-1) could cause some invalid shapes like
75 * - invalid zero size
76 * - size 1 which isn't compatible with scale with aligned corners.
77 */
78template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration>
79class ScaleShapesBaseDataSet<channel, batch, element_per_iteration, 1> : public ShapeDataset
80{
81 static constexpr auto small_size = 3;
82 static constexpr auto boundary_plus_one = element_per_iteration + 1;
83
84public:
85 // These tensor shapes are NCHW layout, fixture will convert to NHWC.
86 ScaleShapesBaseDataSet()
87 : ShapeDataset("Shape",
88 {
89 TensorShape{ small_size, boundary_plus_one, channel, batch },
90 TensorShape{ boundary_plus_one, small_size, channel, batch },
91 })
92 {
93 }
94};
95
96/** For the shapes smaller than one vector, only pre-defined tiny shapes
97 * are tested (3x2, 2x3) as smaller shapes are more likely to cause
98 * issues and easier to debug.
99 */
100template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration>
101class ScaleShapesBaseDataSet<channel, batch, element_per_iteration, 0> : public ShapeDataset
102{
103 static constexpr auto small_size = 3;
104 static constexpr auto zero_vector_boundary_value = 2;
105
106public:
107 // These tensor shapes are NCHW layout, fixture will convert to NHWC.
108 ScaleShapesBaseDataSet()
109 : ShapeDataset("Shape",
110 {
111 TensorShape{ small_size, zero_vector_boundary_value, channel, batch },
112 TensorShape{ zero_vector_boundary_value, small_size, channel, batch },
113 })
114 {
115 }
116};
117
118/** Interpolation policy test set */
119const auto ScaleInterpolationPolicySet = framework::dataset::make("InterpolationPolicy",
120{
121 InterpolationPolicy::NEAREST_NEIGHBOR,
122 InterpolationPolicy::BILINEAR,
123});
124
125/** Scale data types */
126const auto ScaleDataLayouts = framework::dataset::make("DataLayout",
127{
128 DataLayout::NCHW,
129 DataLayout::NHWC,
130});
131
132/** Sampling policy data set */
133const auto ScaleSamplingPolicySet = combine(datasets::SamplingPolicies(),
134 framework::dataset::make("AlignCorners", { false }));
135
136/** Sampling policy data set for Aligned Corners which only allows TOP_LEFT policy.*/
137const auto ScaleAlignCornersSamplingPolicySet = combine(framework::dataset::make("SamplingPolicy",
138{
139 SamplingPolicy::TOP_LEFT,
140}),
141framework::dataset::make("AlignCorners", { true }));
142
143/** Generated shapes: Used by NEON precommit and nightly
144 * - 2D shapes with 0, 1, 2 vector iterations
145 * - 3D shapes with 0, 1 vector iterations
146 * - 4D shapes with 0 vector iterations
147 */
148#define SCALE_SHAPE_DATASET(element_per_iteration) \
149 concat(concat(concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 0>(), \
150 ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 1>()), \
151 ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 2>()), \
152 ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 0>()), \
153 ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 1>()), \
154 ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 0>())
155
156// To prevent long precommit time for OpenCL, shape set for OpenCL is separated into below two parts.
157/** Generated shapes for precommits to achieve essential coverage. Used by CL precommit and nightly
158 * - 3D shapes with 1 vector iterations
159 * - 4D shapes with 1 vector iterations
160 */
161#define SCALE_PRECOMMIT_SHAPE_DATASET(element_per_iteration) \
162 concat(ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 1>(), ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 1>())
163
164/** Generated shapes for nightly to achieve more small and variety shapes. Used by CL nightly
165 * - 2D shapes with 0, 1, 2 vector iterations
166 * - 3D shapes with 0 vector iterations (1 vector iteration is covered by SCALE_PRECOMMIT_SHAPE_DATASET)
167 * - 4D shapes with 0 vector iterations
168 */
169#define SCALE_NIGHTLY_SHAPE_DATASET(element_per_iteration) \
170 concat(concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 0>(), \
171 ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 1>()), \
172 ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 2>()), \
173 ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 0>()), \
174 ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 0>())
175
176/** Generating dataset for non-quantized data tyeps with the given shapes */
177#define ASSEMBLE_DATASET(shape, samping_policy_set) \
178 combine(combine(combine(combine((shape), ScaleDataLayouts), \
179 ScaleInterpolationPolicySet), \
180 datasets::BorderModes()), \
181 samping_policy_set)
182
183/** Generating dataset for quantized data tyeps with the given shapes */
184#define ASSEMBLE_QUANTIZED_DATASET(shape, sampling_policy_set, quantization_info_set) \
185 combine(combine(combine(combine(combine(shape, \
186 quantization_info_set), \
187 ScaleDataLayouts), \
188 ScaleInterpolationPolicySet), \
189 datasets::BorderModes()), \
190 sampling_policy_set)
191
192} // namespace datasets
193} // namespace test
194} // namespace arm_compute
195#endif /* ARM_COMPUTE_TEST_SCALE_VALIDATION_DATASET */