Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 1 | /* |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017, 2018 ARM Limited. |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [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 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/functions/CLConvolution.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/BorderModeDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/ConvolutionFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 46 | } // namespace |
| 47 | |
| 48 | TEST_SUITE(CL) |
| 49 | TEST_SUITE(CustomConvolution) |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 50 | TEST_SUITE(CustomConvolutionSquare) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 51 | TEST_SUITE(CustomConvolution3x3) |
| 52 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 53 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", DataType::U8)), |
| 54 | datasets::BorderModes()), |
| 55 | framework::dataset::make("filter_size", { 3 })), |
| 56 | shape, data_type, border_mode, filter_size) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 57 | { |
| 58 | // Create tensors |
| 59 | CLTensor src = create_tensor<CLTensor>(shape, data_type); |
| 60 | CLTensor dst = create_tensor<CLTensor>(shape, data_type); |
| 61 | |
| 62 | // Create conv matrix |
| 63 | int16_t conv[9]; |
| 64 | |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 66 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 67 | |
| 68 | // Create and configure function |
| 69 | CLConvolution3x3 convolution; |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 70 | convolution.configure(&src, &dst, conv, 0, border_mode); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 71 | |
| 72 | // Validate valid region |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 73 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2)); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 74 | validate(dst.info()->valid_region(), dst_valid_region); |
| 75 | |
| 76 | // Validate padding |
| 77 | PaddingCalculator calculator(shape.x(), 8); |
| 78 | calculator.set_border_size(1); |
| 79 | calculator.set_border_mode(border_mode); |
| 80 | |
| 81 | const PaddingSize dst_padding = calculator.required_padding(); |
| 82 | |
| 83 | calculator.set_accessed_elements(16); |
| 84 | calculator.set_access_offset(-1); |
| 85 | |
| 86 | const PaddingSize src_padding = calculator.required_padding(); |
| 87 | |
| 88 | validate(src.info()->padding(), src_padding); |
| 89 | validate(dst.info()->padding(), dst_padding); |
| 90 | } |
| 91 | |
| 92 | template <typename T> |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 93 | using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution3x3, T>; |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 94 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 95 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 96 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 97 | datasets::BorderModes()), |
| 98 | framework::dataset::make("filter_size", { 3 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 99 | { |
| 100 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 101 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 104 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 105 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 106 | datasets::BorderModes()), |
| 107 | framework::dataset::make("filter_size", { 3 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 108 | { |
| 109 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 110 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 111 | } |
| 112 | TEST_SUITE_END() /* Custom_Convolution 3x3 */ |
| 113 | |
| 114 | TEST_SUITE(CustomConvolution5x5) |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 115 | |
| 116 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", DataType::U8)), |
| 117 | datasets::BorderModes()), |
| 118 | framework::dataset::make("filter_size", { 5 })), |
| 119 | shape, data_type, border_mode, filter_size) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 120 | { |
| 121 | // Create tensors |
| 122 | CLTensor src = create_tensor<CLTensor>(shape, data_type); |
| 123 | CLTensor dst = create_tensor<CLTensor>(shape, data_type); |
| 124 | |
| 125 | // Create conv matrix |
| 126 | int16_t conv[25]; |
| 127 | |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 128 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 129 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 130 | |
| 131 | // Create and configure function |
| 132 | CLConvolution5x5 convolution; |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 133 | convolution.configure(&src, &dst, conv, 0, border_mode); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 134 | |
| 135 | // Validate valid region |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 136 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2)); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 137 | validate(dst.info()->valid_region(), dst_valid_region); |
| 138 | |
| 139 | // Validate padding |
| 140 | PaddingCalculator calculator(shape.x(), 8); |
| 141 | calculator.set_border_size(2); |
| 142 | calculator.set_border_mode(border_mode); |
| 143 | |
| 144 | const PaddingSize dst_padding = calculator.required_padding(); |
| 145 | |
| 146 | calculator.set_accessed_elements(16); |
| 147 | calculator.set_access_offset(-2); |
| 148 | |
| 149 | const PaddingSize src_padding = calculator.required_padding(); |
| 150 | |
| 151 | validate(src.info()->padding(), src_padding); |
| 152 | validate(dst.info()->padding(), dst_padding); |
| 153 | } |
| 154 | |
| 155 | template <typename T> |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 156 | using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution5x5, T>; |
| 157 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 158 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 159 | datasets::BorderModes()), |
| 160 | framework::dataset::make("filter_size", { 5 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 161 | { |
| 162 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 163 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 166 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 167 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 168 | datasets::BorderModes()), |
| 169 | framework::dataset::make("filter_size", { 5 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 170 | { |
| 171 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 172 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 173 | } |
| 174 | TEST_SUITE_END() /* Custom Convolution 5x5 */ |
| 175 | |
| 176 | TEST_SUITE(CustomConvolution7x7) |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 177 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", DataType::U8)), |
| 178 | datasets::BorderModes()), |
| 179 | framework::dataset::make("filter_size", { 7 })), |
| 180 | shape, data_type, border_mode, filter_size) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 181 | { |
| 182 | // Create tensors |
| 183 | CLTensor src = create_tensor<CLTensor>(shape, data_type); |
| 184 | CLTensor dst = create_tensor<CLTensor>(shape, data_type); |
| 185 | |
| 186 | // Create conv matrix |
| 187 | int16_t conv[49]; |
| 188 | |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 189 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 190 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 191 | |
| 192 | // Create and configure function |
| 193 | CLConvolution7x7 convolution; |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 194 | convolution.configure(&src, &dst, conv, 0, border_mode); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 195 | |
| 196 | // Validate valid region |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 197 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2)); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 198 | validate(dst.info()->valid_region(), dst_valid_region); |
| 199 | |
| 200 | // Validate padding |
| 201 | PaddingCalculator calculator(shape.x(), 8); |
| 202 | calculator.set_border_size(3); |
| 203 | calculator.set_border_mode(border_mode); |
| 204 | |
| 205 | const PaddingSize dst_padding = calculator.required_padding(); |
| 206 | |
| 207 | calculator.set_accessed_elements(16); |
| 208 | calculator.set_access_offset(-3); |
| 209 | |
| 210 | const PaddingSize src_padding = calculator.required_padding(); |
| 211 | |
| 212 | validate(src.info()->padding(), src_padding); |
| 213 | validate(dst.info()->padding(), dst_padding); |
| 214 | } |
| 215 | |
| 216 | template <typename T> |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 217 | using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution7x7, T>; |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 218 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 219 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 220 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 221 | datasets::BorderModes()), |
| 222 | framework::dataset::make("filter_size", { 7 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 223 | { |
| 224 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 225 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 228 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 229 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 230 | datasets::BorderModes()), |
| 231 | framework::dataset::make("filter_size", { 7 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 232 | { |
| 233 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 234 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 235 | } |
| 236 | TEST_SUITE_END() /* Custom Convolution 7x7 */ |
| 237 | |
| 238 | TEST_SUITE(CustomConvolution9x9) |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 239 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", DataType::U8)), |
| 240 | datasets::BorderModes()), |
| 241 | framework::dataset::make("filter_size", { 9 })), |
| 242 | shape, data_type, border_mode, filter_size) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 243 | { |
| 244 | // Create tensors |
| 245 | CLTensor src = create_tensor<CLTensor>(shape, data_type); |
| 246 | CLTensor dst = create_tensor<CLTensor>(shape, data_type); |
| 247 | |
| 248 | // Create conv matrix |
| 249 | int16_t conv[81]; |
| 250 | |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 251 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 252 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 253 | |
| 254 | // Create and configure function |
| 255 | CLConvolution9x9 convolution; |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 256 | convolution.configure(&src, &dst, conv, 0, border_mode); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 257 | |
| 258 | // Validate valid region |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 259 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2)); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 260 | validate(dst.info()->valid_region(), dst_valid_region); |
| 261 | |
| 262 | // Validate padding |
| 263 | PaddingCalculator calculator(shape.x(), 8); |
| 264 | calculator.set_border_size(4); |
| 265 | calculator.set_border_mode(border_mode); |
| 266 | |
| 267 | const PaddingSize dst_padding = calculator.required_padding(); |
| 268 | |
| 269 | calculator.set_accessed_elements(16); |
| 270 | calculator.set_access_offset(-4); |
| 271 | |
| 272 | const PaddingSize src_padding = calculator.required_padding(); |
| 273 | |
| 274 | validate(src.info()->padding(), src_padding); |
| 275 | validate(dst.info()->padding(), dst_padding); |
| 276 | } |
| 277 | |
| 278 | template <typename T> |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 279 | using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution9x9, T>; |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 280 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 281 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 282 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 283 | datasets::BorderModes()), |
| 284 | framework::dataset::make("filter_size", { 9 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 285 | { |
| 286 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 287 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 290 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 291 | DataType::U8)), |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 292 | datasets::BorderModes()), |
| 293 | framework::dataset::make("filter_size", { 9 }))) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 294 | { |
| 295 | // Validate output |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 296 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 297 | } |
| 298 | TEST_SUITE_END() /* Custom Convolution 9x9 */ |
Sanghoon Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 299 | TEST_SUITE_END() /* Custom Convolution Square */ |
| 300 | |
| 301 | TEST_SUITE(CustomConvolutionRectangle) |
| 302 | |
| 303 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", |
| 304 | DataType::U8)), |
| 305 | datasets::BorderModes()), |
| 306 | framework::dataset::make("filter_width", { 3, 5, 7, 9 })), |
| 307 | framework::dataset::make("filter_height", { 3, 5, 7, 9 })), |
| 308 | shape, data_type, border_mode, filter_width, filter_height) |
| 309 | { |
| 310 | // Create tensors |
| 311 | CLTensor src = create_tensor<CLTensor>(shape, data_type); |
| 312 | CLTensor dst = create_tensor<CLTensor>(shape, data_type); |
| 313 | |
| 314 | // Create conv matrix |
| 315 | int16_t conv[filter_width * filter_height]; |
| 316 | |
| 317 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 318 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 319 | |
| 320 | // Create and configure function |
| 321 | CLConvolutionRectangle convolution; |
| 322 | convolution.configure(&src, &dst, conv, filter_width, filter_height, 1, border_mode); |
| 323 | |
| 324 | // Validate valid region |
| 325 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_height / 2, filter_width / 2)); |
| 326 | validate(dst.info()->valid_region(), dst_valid_region); |
| 327 | |
| 328 | // Validate padding |
| 329 | PaddingCalculator calculator(shape.x(), 8); |
| 330 | calculator.set_border_size(filter_width / 2); |
| 331 | calculator.set_border_mode(border_mode); |
| 332 | |
| 333 | const PaddingSize dst_padding = calculator.required_padding(); |
| 334 | |
| 335 | calculator.set_accessed_elements(16); |
| 336 | calculator.set_access_offset(-(filter_width / 2)); |
| 337 | |
| 338 | const PaddingSize width_padding = calculator.required_padding(); |
| 339 | |
| 340 | calculator.set_border_size(filter_height / 2); |
| 341 | calculator.set_access_offset(-(filter_height / 2)); |
| 342 | const PaddingSize height_padding = calculator.required_padding(); |
| 343 | |
| 344 | validate(src.info()->padding(), width_padding, height_padding); |
| 345 | validate(dst.info()->padding(), dst_padding); |
| 346 | } |
| 347 | |
| 348 | template <typename T> |
| 349 | using CLConvolutionFixture = ConvolutionRectangleValidationFixture<CLTensor, CLAccessor, CLConvolutionRectangle, T>; |
| 350 | |
| 351 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
| 352 | DataType::U8)), |
| 353 | datasets::BorderModes()), |
| 354 | framework::dataset::make("filter_width", { 3, 5, 7, 9 })), |
| 355 | framework::dataset::make("filter_height", { 3, 5, 7, 9 }))) |
| 356 | { |
| 357 | // Validate output |
| 358 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
| 359 | } |
| 360 | |
| 361 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
| 362 | DataType::U8)), |
| 363 | datasets::BorderModes()), |
| 364 | framework::dataset::make("filter_width", { 3, 5, 7, 9 })), |
| 365 | framework::dataset::make("filter_height", { 3, 5, 7, 9 }))) |
| 366 | { |
| 367 | // Validate output |
| 368 | validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2))); |
| 369 | } |
| 370 | TEST_SUITE_END() /* Custom Convolution Rectangle */ |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 371 | TEST_SUITE_END() |
| 372 | TEST_SUITE_END() |
| 373 | } // namespace validation |
| 374 | } // namespace test |
| 375 | } // namespace arm_compute |