Moritz Pflanzer | 7655a67 | 2017-09-23 11:57:33 +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/Types.h" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLSobel3x3.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLSobel5x5.h" |
| 29 | #include "arm_compute/runtime/CL/functions/CLSobel7x7.h" |
| 30 | #include "tests/CL/CLAccessor.h" |
| 31 | #include "tests/PaddingCalculator.h" |
| 32 | #include "tests/datasets/BorderModeDataset.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/SobelFixture.h" |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | TEST_SUITE(CL) |
| 47 | TEST_SUITE(Sobel) |
| 48 | |
| 49 | TEST_SUITE(W3x3) |
| 50 | using CLSobel3x3Fixture = SobelValidationFixture<CLTensor, CLAccessor, CLSobel3x3, uint8_t, int16_t>; |
| 51 | |
| 52 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format", |
| 53 | Format::U8)), |
| 54 | shape, border_mode, format) |
| 55 | { |
| 56 | // Generate a random constant value |
| 57 | std::mt19937 gen(library->seed()); |
| 58 | std::uniform_int_distribution<uint8_t> int_dist(0, 255); |
| 59 | const uint8_t constant_border_value = int_dist(gen); |
| 60 | |
| 61 | // Create tensors |
| 62 | CLTensor src = create_tensor<CLTensor>(shape, data_type_from_format(format)); |
| 63 | CLTensor dst_x = create_tensor<CLTensor>(shape, DataType::S16); |
| 64 | CLTensor dst_y = create_tensor<CLTensor>(shape, DataType::S16); |
| 65 | |
| 66 | src.info()->set_format(format); |
| 67 | dst_x.info()->set_format(Format::S16); |
| 68 | dst_y.info()->set_format(Format::S16); |
| 69 | |
| 70 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 71 | ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 72 | ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 73 | |
| 74 | // Create sobel 3x3 configure function |
| 75 | CLSobel3x3 sobel; |
| 76 | sobel.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); |
| 77 | |
| 78 | // Validate valid region |
| 79 | constexpr BorderSize border_size{ 1 }; |
| 80 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); |
| 81 | |
| 82 | validate(dst_x.info()->valid_region(), dst_valid_region); |
| 83 | validate(dst_y.info()->valid_region(), dst_valid_region); |
| 84 | |
| 85 | // Validate padding |
| 86 | PaddingCalculator calculator(shape.x(), 8); |
| 87 | |
| 88 | calculator.set_border_mode(border_mode); |
| 89 | calculator.set_border_size(1); |
| 90 | |
| 91 | const PaddingSize dst_padding = calculator.required_padding(); |
| 92 | |
| 93 | calculator.set_accessed_elements(16); |
| 94 | calculator.set_access_offset(-1); |
| 95 | |
| 96 | const PaddingSize src_padding = calculator.required_padding(); |
| 97 | |
| 98 | validate(src.info()->padding(), src_padding); |
| 99 | validate(dst_x.info()->padding(), dst_padding); |
| 100 | validate(dst_y.info()->padding(), dst_padding); |
| 101 | } |
| 102 | |
| 103 | FIXTURE_DATA_TEST_CASE(RunSmall, CLSobel3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 104 | Format::U8))) |
| 105 | { |
| 106 | // Validate output |
| 107 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 108 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 109 | |
| 110 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 111 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 112 | } |
| 113 | |
| 114 | FIXTURE_DATA_TEST_CASE(RunLarge, CLSobel3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 115 | Format::U8))) |
| 116 | { |
| 117 | // Validate output |
| 118 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 119 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 120 | |
| 121 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 122 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 123 | } |
| 124 | TEST_SUITE_END() |
| 125 | |
| 126 | TEST_SUITE(W5x5) |
| 127 | using CLSobel5x5Fixture = SobelValidationFixture<CLTensor, CLAccessor, CLSobel5x5, uint8_t, int16_t>; |
| 128 | |
| 129 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format", |
| 130 | Format::U8)), |
| 131 | shape, border_mode, format) |
| 132 | { |
| 133 | // Generate a random constant value |
| 134 | std::mt19937 gen(library->seed()); |
| 135 | std::uniform_int_distribution<uint8_t> int_dist(0, 255); |
| 136 | const uint8_t constant_border_value = int_dist(gen); |
| 137 | |
| 138 | // Create tensors |
| 139 | CLTensor src = create_tensor<CLTensor>(shape, data_type_from_format(format)); |
| 140 | CLTensor dst_x = create_tensor<CLTensor>(shape, DataType::S16); |
| 141 | CLTensor dst_y = create_tensor<CLTensor>(shape, DataType::S16); |
| 142 | |
| 143 | src.info()->set_format(format); |
| 144 | dst_x.info()->set_format(Format::S16); |
| 145 | dst_y.info()->set_format(Format::S16); |
| 146 | |
| 147 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 148 | ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 149 | ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 150 | |
| 151 | // Create sobel 5x5 configure function |
| 152 | CLSobel5x5 sobel; |
| 153 | sobel.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); |
| 154 | |
| 155 | // Validate valid region |
| 156 | constexpr BorderSize border_size{ 2 }; |
| 157 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); |
| 158 | |
| 159 | validate(dst_x.info()->valid_region(), dst_valid_region); |
| 160 | validate(dst_y.info()->valid_region(), dst_valid_region); |
| 161 | |
| 162 | // Validate padding |
| 163 | PaddingCalculator calculator(shape.x(), 8); |
| 164 | calculator.set_border_mode(border_mode); |
| 165 | calculator.set_border_size(2); |
| 166 | |
| 167 | const PaddingSize dst_padding = calculator.required_padding(); |
| 168 | |
| 169 | calculator.set_accessed_elements(16); |
| 170 | calculator.set_access_offset(-2); |
| 171 | |
| 172 | const PaddingSize src_padding = calculator.required_padding(); |
| 173 | |
| 174 | validate(src.info()->padding(), src_padding); |
| 175 | validate(dst_x.info()->padding(), dst_padding); |
| 176 | validate(dst_y.info()->padding(), dst_padding); |
| 177 | } |
| 178 | |
| 179 | FIXTURE_DATA_TEST_CASE(RunSmall, CLSobel5x5Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 180 | Format::U8))) |
| 181 | { |
| 182 | // Validate output |
| 183 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2)); |
| 184 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 185 | |
| 186 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2)); |
| 187 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 188 | } |
| 189 | |
| 190 | FIXTURE_DATA_TEST_CASE(RunLarge, CLSobel5x5Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 191 | Format::U8))) |
| 192 | { |
| 193 | // Validate output |
| 194 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2)); |
| 195 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 196 | |
| 197 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2)); |
| 198 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 199 | } |
| 200 | TEST_SUITE_END() |
| 201 | |
| 202 | TEST_SUITE(W7x7) |
| 203 | using CLSobel7x7Fixture = SobelValidationFixture<CLTensor, CLAccessor, CLSobel7x7, uint8_t, int32_t>; |
| 204 | |
| 205 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format", |
| 206 | Format::U8)), |
| 207 | shape, border_mode, format) |
| 208 | { |
| 209 | // Generate a random constant value |
| 210 | std::mt19937 gen(library->seed()); |
| 211 | std::uniform_int_distribution<uint8_t> int_dist(0, 255); |
| 212 | const uint8_t constant_border_value = int_dist(gen); |
| 213 | |
| 214 | // Create tensors |
| 215 | CLTensor src = create_tensor<CLTensor>(shape, data_type_from_format(format)); |
| 216 | CLTensor dst_x = create_tensor<CLTensor>(shape, DataType::S32); |
| 217 | CLTensor dst_y = create_tensor<CLTensor>(shape, DataType::S32); |
| 218 | |
| 219 | src.info()->set_format(format); |
| 220 | dst_x.info()->set_format(Format::S32); |
| 221 | dst_y.info()->set_format(Format::S32); |
| 222 | |
| 223 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 224 | ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 225 | ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 226 | |
| 227 | // Create sobel 7x7 configure function |
| 228 | CLSobel7x7 sobel; |
| 229 | sobel.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); |
| 230 | |
| 231 | // Validate valid region |
| 232 | constexpr BorderSize border_size{ 3 }; |
| 233 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); |
| 234 | |
| 235 | validate(dst_x.info()->valid_region(), dst_valid_region); |
| 236 | validate(dst_y.info()->valid_region(), dst_valid_region); |
| 237 | |
| 238 | // Validate padding |
| 239 | PaddingCalculator calculator(shape.x(), 8); |
| 240 | |
| 241 | calculator.set_border_mode(border_mode); |
| 242 | calculator.set_border_size(3); |
| 243 | |
| 244 | const PaddingSize dst_padding = calculator.required_padding(); |
| 245 | |
| 246 | calculator.set_accessed_elements(16); |
| 247 | calculator.set_access_offset(-3); |
| 248 | |
| 249 | const PaddingSize src_padding = calculator.required_padding(); |
| 250 | |
| 251 | validate(src.info()->padding(), src_padding); |
| 252 | validate(dst_x.info()->padding(), dst_padding); |
| 253 | validate(dst_y.info()->padding(), dst_padding); |
| 254 | } |
| 255 | |
| 256 | FIXTURE_DATA_TEST_CASE(RunSmall, CLSobel7x7Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 257 | Format::U8))) |
| 258 | { |
| 259 | // Validate output |
| 260 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3)); |
| 261 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 262 | |
| 263 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3)); |
| 264 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 265 | } |
| 266 | |
| 267 | FIXTURE_DATA_TEST_CASE(RunLarge, CLSobel7x7Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 268 | Format::U8))) |
| 269 | { |
| 270 | // Validate output |
| 271 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3)); |
| 272 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 273 | |
| 274 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3)); |
| 275 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 276 | } |
| 277 | TEST_SUITE_END() |
| 278 | |
| 279 | TEST_SUITE_END() |
| 280 | TEST_SUITE_END() |
| 281 | } // namespace validation |
| 282 | } // namespace test |
| 283 | } // namespace arm_compute |