Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #include "arm_compute/core/Helpers.h" |
| 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/runtime/CL/functions/CLScale.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/datasets/BorderModeDataset.h" |
| 32 | #include "tests/datasets/ShapeDatasets.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/framework/datasets/Datasets.h" |
| 36 | #include "tests/validation/Helpers.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/ScaleFixture.h" |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | namespace |
| 47 | { |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 48 | /** CNN data types */ |
| 49 | const auto ScaleDataTypes = framework::dataset::make("DataType", |
| 50 | { |
| 51 | DataType::U8, |
| 52 | DataType::S16, |
| 53 | DataType::F16, |
| 54 | DataType::F32, |
| 55 | }); |
| 56 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 57 | /** Tolerance */ |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 58 | constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); |
| 59 | constexpr AbsoluteTolerance<int16_t> tolerance_s16(1); |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 60 | RelativeTolerance<float> tolerance_f32(0.05); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 61 | RelativeTolerance<half> tolerance_f16(half(0.1)); |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 62 | |
| 63 | constexpr float tolerance_num_f32(0.01f); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 64 | } // namespace |
| 65 | |
| 66 | TEST_SUITE(CL) |
| 67 | TEST_SUITE(Scale) |
| 68 | |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 69 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes), |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 70 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 71 | datasets::BorderModes()), |
| 72 | shape, data_type, policy, border_mode) |
| 73 | { |
| 74 | std::mt19937 generator(library->seed()); |
| 75 | std::uniform_real_distribution<float> distribution_float(0.25, 2); |
| 76 | const float scale_x = distribution_float(generator); |
| 77 | const float scale_y = distribution_float(generator); |
| 78 | std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); |
| 79 | uint8_t constant_border_value = distribution_u8(generator); |
| 80 | |
| 81 | // Create tensors |
| 82 | CLTensor src = create_tensor<CLTensor>(shape, data_type); |
| 83 | TensorShape shape_scaled(shape); |
| 84 | shape_scaled.set(0, shape[0] * scale_x); |
| 85 | shape_scaled.set(1, shape[1] * scale_y); |
| 86 | CLTensor dst = create_tensor<CLTensor>(shape_scaled, data_type); |
| 87 | |
| 88 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 89 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 90 | |
| 91 | // Create and configure function |
| 92 | CLScale clscale; |
| 93 | clscale.configure(&src, &dst, policy, border_mode, constant_border_value); |
| 94 | |
| 95 | // Validate valid region |
| 96 | const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED)); |
| 97 | |
| 98 | validate(dst.info()->valid_region(), dst_valid_region); |
| 99 | |
| 100 | // Validate padding |
| 101 | PaddingCalculator calculator(shape_scaled.x(), 4); |
| 102 | calculator.set_border_mode(border_mode); |
| 103 | |
| 104 | const PaddingSize read_padding(1); |
| 105 | const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER); |
| 106 | validate(src.info()->padding(), read_padding); |
| 107 | validate(dst.info()->padding(), write_padding); |
| 108 | } |
| 109 | |
| 110 | template <typename T> |
| 111 | using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>; |
| 112 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 113 | TEST_SUITE(Float) |
| 114 | TEST_SUITE(FP32) |
| 115 | FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)), |
| 116 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 117 | datasets::BorderModes())) |
| 118 | { |
| 119 | //Create valid region |
| 120 | TensorInfo src_info(_shape, 1, _data_type); |
| 121 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 122 | |
| 123 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 124 | validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 125 | } |
| 126 | FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), |
| 127 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 128 | datasets::BorderModes())) |
| 129 | { |
| 130 | //Create valid region |
| 131 | TensorInfo src_info(_shape, 1, _data_type); |
| 132 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 133 | |
| 134 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 135 | validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 136 | } |
| 137 | TEST_SUITE_END() |
| 138 | TEST_SUITE(FP16) |
| 139 | FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), |
| 140 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 141 | datasets::BorderModes())) |
| 142 | { |
| 143 | //Create valid region |
| 144 | TensorInfo src_info(_shape, 1, _data_type); |
| 145 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 146 | |
| 147 | // Validate output |
| 148 | validate(CLAccessor(_target), _reference, valid_region, tolerance_f16); |
| 149 | } |
| 150 | FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
| 151 | DataType::F16)), |
| 152 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 153 | datasets::BorderModes())) |
| 154 | { |
| 155 | //Create valid region |
| 156 | TensorInfo src_info(_shape, 1, _data_type); |
| 157 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 158 | |
| 159 | // Validate output |
| 160 | validate(CLAccessor(_target), _reference, valid_region, tolerance_f16); |
| 161 | } |
| 162 | TEST_SUITE_END() |
| 163 | TEST_SUITE_END() |
| 164 | |
| 165 | TEST_SUITE(Integer) |
| 166 | TEST_SUITE(U8) |
| 167 | FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::U8)), |
| 168 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 169 | datasets::BorderModes())) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 170 | { |
| 171 | //Create valid region |
| 172 | TensorInfo src_info(_shape, 1, _data_type); |
| 173 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 174 | |
| 175 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 176 | validate(CLAccessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 177 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 178 | FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::U8)), |
| 179 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 180 | datasets::BorderModes())) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 181 | { |
| 182 | //Create valid region |
| 183 | TensorInfo src_info(_shape, 1, _data_type); |
| 184 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 185 | |
| 186 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 187 | validate(CLAccessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 188 | } |
| 189 | TEST_SUITE_END() |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 190 | TEST_SUITE(S16) |
| 191 | FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::S16)), |
| 192 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 193 | datasets::BorderModes())) |
| 194 | { |
| 195 | //Create valid region |
| 196 | TensorInfo src_info(_shape, 1, _data_type); |
| 197 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 198 | |
| 199 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 200 | validate(CLAccessor(_target), _reference, valid_region, tolerance_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 201 | } |
| 202 | FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::S16)), |
| 203 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 204 | datasets::BorderModes())) |
| 205 | { |
| 206 | //Create valid region |
| 207 | TensorInfo src_info(_shape, 1, _data_type); |
| 208 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
| 209 | |
| 210 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 211 | validate(CLAccessor(_target), _reference, valid_region, tolerance_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 212 | } |
| 213 | TEST_SUITE_END() |
| 214 | TEST_SUITE_END() |
| 215 | |
| 216 | TEST_SUITE_END() |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 217 | TEST_SUITE_END() |
| 218 | } // namespace validation |
| 219 | } // namespace test |
| 220 | } // namespace arm_compute |