aboutsummaryrefslogtreecommitdiff
path: root/tests/datasets/ScaleValidationDataset.h
blob: 217876b28b16b2f3f95711345ac9ad508af20bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * Copyright (c) 2020 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_SCALE_VALIDATION_DATASET
#define ARM_COMPUTE_TEST_SCALE_VALIDATION_DATASET

#include "utils/TypePrinter.h"

#include "arm_compute/core/TensorShape.h"
#include "arm_compute/core/Types.h"
#include "tests/datasets/BorderModeDataset.h"
#include "tests/datasets/InterpolationPolicyDataset.h"
#include "tests/datasets/SamplingPolicyDataset.h"
#include "tests/datasets/ShapeDatasets.h"

namespace arm_compute
{
namespace test
{
namespace datasets
{
/** Class to generate boundary values for the given template parameters
 * including shapes with large differences between width and height.
 * element_per_iteration is the number of elements processed by one iteration
 * of an implementation. (E.g., if an iteration is based on a 16-byte vector
 * and size of one element is 1-byte, this value would be 16.).
 * iterations is the total number of complete iterations we want to test
 * for the effect of larger shapes.
 */
template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration, uint32_t iterations>
class ScaleShapesBaseDataSet : public ShapeDataset
{
    static constexpr auto boundary_minus_one = element_per_iteration * iterations - 1;
    static constexpr auto boundary_plus_one  = element_per_iteration * iterations + 1;
    static constexpr auto small_size         = 3;

public:
    // These tensor shapes are NCHW layout, fixture will convert to NHWC.
    ScaleShapesBaseDataSet()
        : ShapeDataset("Shape",
    {
        TensorShape{ small_size, boundary_minus_one, channel, batch },
                     TensorShape{ small_size, boundary_plus_one, channel, batch },
                     TensorShape{ boundary_minus_one, small_size, channel, batch },
                     TensorShape{ boundary_plus_one, small_size, channel, batch },
                     TensorShape{ boundary_minus_one, boundary_plus_one, channel, batch },
                     TensorShape{ boundary_plus_one, boundary_minus_one, channel, batch },
    })
    {
    }
};

/** For the single vector, only larger value (+1) than boundary
 * since smaller value (-1) could cause some invalid shapes like
 * - invalid zero size
 * - size 1 which isn't compatible with scale with aligned corners.
 */
template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration>
class ScaleShapesBaseDataSet<channel, batch, element_per_iteration, 1> : public ShapeDataset
{
    static constexpr auto small_size        = 3;
    static constexpr auto boundary_plus_one = element_per_iteration + 1;

public:
    // These tensor shapes are NCHW layout, fixture will convert to NHWC.
    ScaleShapesBaseDataSet()
        : ShapeDataset("Shape",
    {
        TensorShape{ small_size, boundary_plus_one, channel, batch },
                     TensorShape{ boundary_plus_one, small_size, channel, batch },
    })
    {
    }
};

/** For the shapes smaller than one vector, only pre-defined tiny shapes
 * are tested (3x2, 2x3) as smaller shapes are more likely to cause
 * issues and easier to debug.
 */
template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration>
class ScaleShapesBaseDataSet<channel, batch, element_per_iteration, 0> : public ShapeDataset
{
    static constexpr auto small_size                 = 3;
    static constexpr auto zero_vector_boundary_value = 2;

public:
    // These tensor shapes are NCHW layout, fixture will convert to NHWC.
    ScaleShapesBaseDataSet()
        : ShapeDataset("Shape",
    {
        TensorShape{ small_size, zero_vector_boundary_value, channel, batch },
                     TensorShape{ zero_vector_boundary_value, small_size, channel, batch },
    })
    {
    }
};

/** Interpolation policy test set */
const auto ScaleInterpolationPolicySet = framework::dataset::make("InterpolationPolicy",
{
    InterpolationPolicy::NEAREST_NEIGHBOR,
    InterpolationPolicy::BILINEAR,
});

/** Scale data types */
const auto ScaleDataLayouts = framework::dataset::make("DataLayout",
{
    DataLayout::NCHW,
    DataLayout::NHWC,
});

/** Sampling policy data set */
const auto ScaleSamplingPolicySet = combine(datasets::SamplingPolicies(),
                                            framework::dataset::make("AlignCorners", { false }));

/** Sampling policy data set for Aligned Corners which only allows TOP_LEFT policy.*/
const auto ScaleAlignCornersSamplingPolicySet = combine(framework::dataset::make("SamplingPolicy",
{
    SamplingPolicy::TOP_LEFT,
}),
framework::dataset::make("AlignCorners", { true }));

/** Generated shapes: Used by NEON precommit and nightly
 * - 2D shapes with 0, 1, 2 vector iterations
 * - 3D shapes with 0, 1 vector iterations
 * - 4D shapes with 0 vector iterations
 */
#define SCALE_SHAPE_DATASET(element_per_iteration)                                                  \
    concat(concat(concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 0>(),  \
                                       ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 1>()), \
                                ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 2>()),        \
                         ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 0>()),               \
                  ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 1>()),                      \
           ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 0>())

// To prevent long precommit time for OpenCL, shape set for OpenCL is separated into below two parts.
/** Generated shapes for precommits to achieve essential coverage. Used by CL precommit and nightly
 * - 3D shapes with 1 vector iterations
 * - 4D shapes with 1 vector iterations
 */
#define SCALE_PRECOMMIT_SHAPE_DATASET(element_per_iteration) \
    concat(ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 1>(), ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 1>())

/** Generated shapes for nightly to achieve more small and variety shapes. Used by CL nightly
 * - 2D shapes with 0, 1, 2 vector iterations
 * - 3D shapes with 0 vector iterations (1 vector iteration is covered by SCALE_PRECOMMIT_SHAPE_DATASET)
 * - 4D shapes with 0 vector iterations
 */
#define SCALE_NIGHTLY_SHAPE_DATASET(element_per_iteration)                                   \
    concat(concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 0>(),  \
                                ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 1>()), \
                         ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 2>()),        \
                  ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 0>()),               \
           ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 0>())

/** Generating dataset for non-quantized data tyeps with the given shapes */
#define ASSEMBLE_DATASET(shape, samping_policy_set)             \
    combine(combine(combine(combine((shape), ScaleDataLayouts), \
                            ScaleInterpolationPolicySet),       \
                    datasets::BorderModes()),                   \
            samping_policy_set)

/** Generating dataset for quantized data tyeps with the given shapes */
#define ASSEMBLE_QUANTIZED_DATASET(shape, sampling_policy_set, quantization_info_set) \
    combine(combine(combine(combine(combine(shape,                                    \
                                            quantization_info_set),                   \
                                    ScaleDataLayouts),                                \
                            ScaleInterpolationPolicySet),                             \
                    datasets::BorderModes()),                                         \
            sampling_policy_set)

} // namespace datasets
} // namespace test
} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_SCALE_VALIDATION_DATASET */