Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021 Arm Limited. |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 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 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace 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 | */ |
| 50 | template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration, uint32_t iterations> |
| 51 | class 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 | |
| 57 | public: |
| 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 | */ |
| 78 | template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration> |
| 79 | class 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 | |
| 84 | public: |
| 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 | */ |
| 100 | template <uint32_t channel, uint32_t batch, uint32_t element_per_iteration> |
| 101 | class 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 | |
| 106 | public: |
| 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 */ |
| 119 | const auto ScaleInterpolationPolicySet = framework::dataset::make("InterpolationPolicy", |
| 120 | { |
| 121 | InterpolationPolicy::NEAREST_NEIGHBOR, |
| 122 | InterpolationPolicy::BILINEAR, |
| 123 | }); |
| 124 | |
| 125 | /** Scale data types */ |
| 126 | const auto ScaleDataLayouts = framework::dataset::make("DataLayout", |
| 127 | { |
| 128 | DataLayout::NCHW, |
| 129 | DataLayout::NHWC, |
| 130 | }); |
| 131 | |
| 132 | /** Sampling policy data set */ |
| 133 | const 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.*/ |
| 137 | const auto ScaleAlignCornersSamplingPolicySet = combine(framework::dataset::make("SamplingPolicy", |
| 138 | { |
| 139 | SamplingPolicy::TOP_LEFT, |
| 140 | }), |
| 141 | framework::dataset::make("AlignCorners", { true })); |
| 142 | |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 143 | /** Generated shapes: used by precommit and nightly for CPU tests |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 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 | */ |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 148 | #define SCALE_SHAPE_DATASET(element_per_iteration) \ |
| 149 | concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 0>(), \ |
| 150 | ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 2>()), \ |
| 151 | ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 1>()), \ |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 152 | ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 0>()) |
| 153 | |
| 154 | // To prevent long precommit time for OpenCL, shape set for OpenCL is separated into below two parts. |
| 155 | /** Generated shapes for precommits to achieve essential coverage. Used by CL precommit and nightly |
| 156 | * - 3D shapes with 1 vector iterations |
| 157 | * - 4D shapes with 1 vector iterations |
| 158 | */ |
| 159 | #define SCALE_PRECOMMIT_SHAPE_DATASET(element_per_iteration) \ |
| 160 | concat(ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 1>(), ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 1>()) |
| 161 | |
| 162 | /** Generated shapes for nightly to achieve more small and variety shapes. Used by CL nightly |
| 163 | * - 2D shapes with 0, 1, 2 vector iterations |
| 164 | * - 3D shapes with 0 vector iterations (1 vector iteration is covered by SCALE_PRECOMMIT_SHAPE_DATASET) |
| 165 | * - 4D shapes with 0 vector iterations |
| 166 | */ |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 167 | #define SCALE_NIGHTLY_SHAPE_DATASET(element_per_iteration) \ |
| 168 | concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 0>(), \ |
| 169 | ScaleShapesBaseDataSet<1, 1, (element_per_iteration), 1>()), \ |
| 170 | ScaleShapesBaseDataSet<3, 1, (element_per_iteration), 0>()), \ |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 171 | ScaleShapesBaseDataSet<3, 3, (element_per_iteration), 0>()) |
| 172 | |
| 173 | /** Generating dataset for non-quantized data tyeps with the given shapes */ |
| 174 | #define ASSEMBLE_DATASET(shape, samping_policy_set) \ |
| 175 | combine(combine(combine(combine((shape), ScaleDataLayouts), \ |
| 176 | ScaleInterpolationPolicySet), \ |
| 177 | datasets::BorderModes()), \ |
| 178 | samping_policy_set) |
| 179 | |
| 180 | /** Generating dataset for quantized data tyeps with the given shapes */ |
| 181 | #define ASSEMBLE_QUANTIZED_DATASET(shape, sampling_policy_set, quantization_info_set) \ |
| 182 | combine(combine(combine(combine(combine(shape, \ |
| 183 | quantization_info_set), \ |
| 184 | ScaleDataLayouts), \ |
| 185 | ScaleInterpolationPolicySet), \ |
| 186 | datasets::BorderModes()), \ |
| 187 | sampling_policy_set) |
| 188 | |
| 189 | } // namespace datasets |
| 190 | } // namespace test |
| 191 | } // namespace arm_compute |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 192 | #endif /* ARM_COMPUTE_TEST_SCALE_VALIDATION_DATASET */ |