Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 "Globals.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | #include "NEON/NEAccessor.h" |
Moritz Pflanzer | 5b51229 | 2017-06-21 15:54:07 +0100 | [diff] [blame] | 26 | #include "PaddingCalculator.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "TensorLibrary.h" |
| 28 | #include "TypePrinter.h" |
| 29 | #include "Utils.h" |
| 30 | #include "validation/Datasets.h" |
| 31 | #include "validation/Reference.h" |
| 32 | #include "validation/Validation.h" |
| 33 | |
| 34 | #include "arm_compute/core/Helpers.h" |
| 35 | #include "arm_compute/core/Types.h" |
| 36 | #include "arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h" |
| 37 | #include "arm_compute/runtime/Tensor.h" |
| 38 | #include "arm_compute/runtime/TensorAllocator.h" |
| 39 | |
| 40 | #include "boost_wrapper.h" |
| 41 | |
| 42 | #include <random> |
| 43 | #include <string> |
| 44 | |
| 45 | using namespace arm_compute; |
| 46 | using namespace arm_compute::test; |
| 47 | using namespace arm_compute::test::neon; |
| 48 | using namespace arm_compute::test::validation; |
| 49 | |
| 50 | namespace |
| 51 | { |
Michele Di Giorgio | ab0a77e | 2017-06-21 15:36:24 +0100 | [diff] [blame] | 52 | /** Compute Neon pixel-wise multiplication function. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | * |
| 54 | * @param[in] shape Shape of the input and output tensors. |
| 55 | * @param[in] dt_in0 Data type of first input tensor. |
| 56 | * @param[in] dt_in1 Data type of second input tensor. |
| 57 | * @param[in] dt_out Data type of the output tensor. |
| 58 | * @param[in] scale Non-negative scale. |
| 59 | * @param[in] convert_policy Overflow policy of the operation. |
| 60 | * @param[in] rounding_policy Rounding policy of the operation. |
Michele Di Giorgio | ab0a77e | 2017-06-21 15:36:24 +0100 | [diff] [blame] | 61 | * @param[in] fixed_point_position (Optional) Fixed point position that expresses the number of bits for the fractional part of the number. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | * |
| 63 | * @return Computed output tensor. |
| 64 | */ |
| 65 | Tensor compute_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, |
| 66 | int fixed_point_position = 0) |
| 67 | { |
| 68 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 69 | Tensor src1 = create_tensor<Tensor>(shape, dt_in0, 1, fixed_point_position); |
| 70 | Tensor src2 = create_tensor<Tensor>(shape, dt_in1, 1, fixed_point_position); |
| 71 | Tensor dst = create_tensor<Tensor>(shape, dt_out, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | |
| 73 | // Create and configure function |
| 74 | NEPixelWiseMultiplication multiply; |
| 75 | multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy); |
| 76 | |
| 77 | // Allocate tensors |
| 78 | src1.allocator()->allocate(); |
| 79 | src2.allocator()->allocate(); |
| 80 | dst.allocator()->allocate(); |
| 81 | |
| 82 | BOOST_TEST(!src1.info()->is_resizable()); |
| 83 | BOOST_TEST(!src2.info()->is_resizable()); |
| 84 | BOOST_TEST(!dst.info()->is_resizable()); |
| 85 | |
| 86 | // Fill tensors |
| 87 | library->fill_tensor_uniform(NEAccessor(src1), 0); |
| 88 | library->fill_tensor_uniform(NEAccessor(src2), 1); |
| 89 | |
| 90 | // Compute function |
| 91 | multiply.run(); |
| 92 | |
| 93 | return dst; |
| 94 | } |
| 95 | |
| 96 | void validate_configuration(const Tensor &src1, const Tensor &src2, Tensor &dst, TensorShape shape, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) |
| 97 | { |
| 98 | BOOST_TEST(src1.info()->is_resizable()); |
| 99 | BOOST_TEST(src2.info()->is_resizable()); |
| 100 | BOOST_TEST(dst.info()->is_resizable()); |
| 101 | |
| 102 | // Create and configure function |
| 103 | NEPixelWiseMultiplication multiply; |
| 104 | multiply.configure(&src1, &src2, &dst, scale, convert_policy, rounding_policy); |
| 105 | |
| 106 | // Validate valid region |
| 107 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 108 | validate(src1.info()->valid_region(), valid_region); |
| 109 | validate(src2.info()->valid_region(), valid_region); |
| 110 | validate(dst.info()->valid_region(), valid_region); |
| 111 | |
| 112 | // Validate padding |
Moritz Pflanzer | 2509fba | 2017-06-23 14:15:03 +0100 | [diff] [blame] | 113 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 114 | validate(src1.info()->padding(), padding); |
| 115 | validate(src2.info()->padding(), padding); |
| 116 | validate(dst.info()->padding(), padding); |
| 117 | } |
| 118 | } // namespace |
| 119 | |
| 120 | #ifndef DOXYGEN_SKIP_THIS |
| 121 | BOOST_AUTO_TEST_SUITE(NEON) |
| 122 | BOOST_AUTO_TEST_SUITE(PixelWiseMultiplication) |
| 123 | |
| 124 | BOOST_AUTO_TEST_SUITE(U8) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 125 | BOOST_AUTO_TEST_SUITE(Scale255) |
| 126 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 127 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * (1.f / 255.f) * ConvertPolicies() |
| 128 | * RoundingPolicy::TO_NEAREST_UP, |
| 129 | shape, scale, convert_policy, rounding_policy) |
| 130 | { |
| 131 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 132 | Tensor src1 = create_tensor<Tensor>(shape, DataType::U8); |
| 133 | Tensor src2 = create_tensor<Tensor>(shape, DataType::U8); |
| 134 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | |
| 136 | validate_configuration(src1, src2, dst, shape, scale, convert_policy, rounding_policy); |
| 137 | } |
| 138 | |
| 139 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 140 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * (1.f / 255.f) * ConvertPolicies() * RoundingPolicy::TO_NEAREST_UP, |
| 141 | shape, scale, convert_policy, rounding_policy) |
| 142 | { |
| 143 | // Compute function |
| 144 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, DataType::U8, scale, convert_policy, |
| 145 | rounding_policy); |
| 146 | |
| 147 | // Compute reference |
| 148 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, |
| 149 | DataType::U8, scale, convert_policy, rounding_policy); |
| 150 | |
| 151 | // Validate output |
| 152 | // Allow tolerance value of 1.f to counteract imprecision due to 32-bit float conversion |
| 153 | validate(NEAccessor(dst), ref_dst, 1.f, 0.f, std::numeric_limits<uint8_t>::max()); |
| 154 | } |
| 155 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 156 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * (1.f / 255.f) * ConvertPolicies() * RoundingPolicy::TO_NEAREST_UP, |
| 157 | shape, scale, convert_policy, rounding_policy) |
| 158 | { |
| 159 | // Compute function |
| 160 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, DataType::U8, scale, convert_policy, |
| 161 | rounding_policy); |
| 162 | |
| 163 | // Compute reference |
| 164 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, |
| 165 | DataType::U8, scale, convert_policy, rounding_policy); |
| 166 | |
| 167 | // Validate output |
| 168 | // Allow tolerance value of 1.f to counteract imprecision due to 32-bit float conversion |
| 169 | validate(NEAccessor(dst), ref_dst, 1.f, 0.f, std::numeric_limits<uint8_t>::max()); |
| 170 | } |
| 171 | BOOST_AUTO_TEST_SUITE_END() |
| 172 | |
| 173 | BOOST_AUTO_TEST_SUITE(ScaleOther) |
| 174 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 175 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) |
| 176 | * ConvertPolicies() |
| 177 | * RoundingPolicy::TO_ZERO, |
| 178 | shape, scale, convert_policy, rounding_policy) |
| 179 | { |
| 180 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 181 | Tensor src1 = create_tensor<Tensor>(shape, DataType::U8); |
| 182 | Tensor src2 = create_tensor<Tensor>(shape, DataType::U8); |
| 183 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 184 | |
| 185 | validate_configuration(src1, src2, dst, shape, scale, convert_policy, rounding_policy); |
| 186 | } |
| 187 | |
| 188 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 189 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) * ConvertPolicies() |
| 190 | * RoundingPolicy::TO_ZERO, |
| 191 | shape, scale, convert_policy, rounding_policy) |
| 192 | { |
| 193 | // Compute function |
| 194 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, DataType::U8, scale, convert_policy, |
| 195 | rounding_policy); |
| 196 | |
| 197 | // Compute reference |
| 198 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, |
| 199 | DataType::U8, scale, convert_policy, rounding_policy); |
| 200 | |
| 201 | // Validate output |
| 202 | validate(NEAccessor(dst), ref_dst); |
| 203 | } |
| 204 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 205 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) * ConvertPolicies() |
| 206 | * RoundingPolicy::TO_ZERO, |
| 207 | shape, scale, convert_policy, rounding_policy) |
| 208 | { |
| 209 | // Compute function |
| 210 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, DataType::U8, scale, convert_policy, |
| 211 | rounding_policy); |
| 212 | |
| 213 | // Compute reference |
| 214 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::U8, DataType::U8, |
| 215 | DataType::U8, scale, convert_policy, rounding_policy); |
| 216 | |
| 217 | // Validate output |
| 218 | validate(NEAccessor(dst), ref_dst); |
| 219 | } |
| 220 | BOOST_AUTO_TEST_SUITE_END() |
| 221 | BOOST_AUTO_TEST_SUITE_END() |
| 222 | |
| 223 | BOOST_AUTO_TEST_SUITE(S16) |
| 224 | BOOST_AUTO_TEST_SUITE(Scale255) |
| 225 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 226 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * (1.f / 255.f) * ConvertPolicies() |
| 227 | * RoundingPolicy::TO_NEAREST_UP, |
| 228 | shape, dt, scale, convert_policy, rounding_policy) |
| 229 | { |
| 230 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 231 | Tensor src1 = create_tensor<Tensor>(shape, dt); |
| 232 | Tensor src2 = create_tensor<Tensor>(shape, DataType::S16); |
| 233 | Tensor dst = create_tensor<Tensor>(shape, DataType::S16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 234 | |
| 235 | validate_configuration(src1, src2, dst, shape, scale, convert_policy, rounding_policy); |
| 236 | } |
| 237 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 238 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * (1.f / 255.f) * ConvertPolicies() |
| 239 | * RoundingPolicy::TO_NEAREST_UP, |
| 240 | shape, dt, scale, convert_policy, rounding_policy) |
| 241 | { |
| 242 | // Compute function |
| 243 | Tensor dst = compute_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, scale, convert_policy, rounding_policy); |
| 244 | |
| 245 | // Compute reference |
| 246 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, scale, convert_policy, rounding_policy); |
| 247 | |
| 248 | // Validate output |
| 249 | // Allow tolerance value of 2.f to counteract imprecision due to 32-bit float conversion |
| 250 | validate(NEAccessor(dst), ref_dst, 2.f, 0.f, std::numeric_limits<int16_t>::max()); |
| 251 | } |
| 252 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 253 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * (1.f / 255.f) * ConvertPolicies() |
| 254 | * RoundingPolicy::TO_NEAREST_UP, |
| 255 | shape, dt, scale, convert_policy, rounding_policy) |
| 256 | { |
| 257 | // Compute function |
| 258 | Tensor dst = compute_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, scale, convert_policy, rounding_policy); |
| 259 | |
| 260 | // Compute reference |
| 261 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, |
| 262 | scale, convert_policy, rounding_policy); |
| 263 | |
| 264 | // Validate output |
| 265 | // Allow tolerance value of 2.f to counteract imprecision due to 32-bit float conversion |
| 266 | validate(NEAccessor(dst), ref_dst, 2.f, 0.f, std::numeric_limits<int16_t>::max()); |
| 267 | } |
| 268 | BOOST_AUTO_TEST_SUITE_END() |
| 269 | |
| 270 | BOOST_AUTO_TEST_SUITE(ScaleOther) |
| 271 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 272 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) |
| 273 | * ConvertPolicies() |
| 274 | * RoundingPolicy::TO_ZERO, |
| 275 | shape, dt, scale, convert_policy, rounding_policy) |
| 276 | { |
| 277 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 278 | Tensor src1 = create_tensor<Tensor>(shape, dt); |
| 279 | Tensor src2 = create_tensor<Tensor>(shape, DataType::S16); |
| 280 | Tensor dst = create_tensor<Tensor>(shape, DataType::S16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 281 | |
| 282 | validate_configuration(src1, src2, dst, shape, scale, convert_policy, rounding_policy); |
| 283 | } |
| 284 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 285 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) * ConvertPolicies() |
| 286 | * RoundingPolicy::TO_ZERO, |
| 287 | shape, dt, scale, convert_policy, rounding_policy) |
| 288 | { |
| 289 | // Compute function |
| 290 | Tensor dst = compute_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, scale, convert_policy, rounding_policy); |
| 291 | |
| 292 | // Compute reference |
| 293 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, scale, convert_policy, rounding_policy); |
| 294 | |
| 295 | // Validate output |
| 296 | validate(NEAccessor(dst), ref_dst); |
| 297 | } |
| 298 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 299 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) * ConvertPolicies() |
| 300 | * RoundingPolicy::TO_ZERO, |
| 301 | shape, dt, scale, convert_policy, rounding_policy) |
| 302 | { |
| 303 | // Compute function |
| 304 | Tensor dst = compute_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, scale, convert_policy, rounding_policy); |
| 305 | |
| 306 | // Compute reference |
| 307 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, dt, DataType::S16, DataType::S16, |
| 308 | scale, convert_policy, rounding_policy); |
| 309 | |
| 310 | // Validate output |
| 311 | validate(NEAccessor(dst), ref_dst); |
| 312 | } |
| 313 | BOOST_AUTO_TEST_SUITE_END() |
| 314 | BOOST_AUTO_TEST_SUITE_END() |
| 315 | |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 316 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
| 317 | BOOST_AUTO_TEST_SUITE(F16) |
| 318 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 319 | |
| 320 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * (1.f / 255.f) * ConvertPolicies() * RoundingPolicy::TO_NEAREST_UP, |
| 321 | shape, scale, convert_policy, rounding_policy) |
| 322 | { |
| 323 | // Compute function |
| 324 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::F16, DataType::F16, DataType::F16, scale, convert_policy, rounding_policy); |
| 325 | |
| 326 | // Compute reference |
| 327 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::F16, DataType::F16, DataType::F16, scale, convert_policy, rounding_policy); |
| 328 | |
| 329 | // Validate output |
| 330 | // Allow tolerance value of 1.f to counteract imprecision due to 32-bit float conversion |
| 331 | validate(NEAccessor(dst), ref_dst, 1.f, 0.f, std::numeric_limits<int16_t>::max()); |
| 332 | } |
| 333 | |
| 334 | BOOST_AUTO_TEST_SUITE_END() |
| 335 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 336 | |
Michele Di Giorgio | ab0a77e | 2017-06-21 15:36:24 +0100 | [diff] [blame] | 337 | BOOST_AUTO_TEST_SUITE(Float) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 338 | BOOST_AUTO_TEST_SUITE(Scale255) |
| 339 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 340 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * (1.f / 255.f) * ConvertPolicies() |
| 341 | * RoundingPolicy::TO_NEAREST_UP, |
| 342 | shape, scale, convert_policy, rounding_policy) |
| 343 | { |
| 344 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 345 | Tensor src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 346 | Tensor src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 347 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 348 | |
| 349 | validate_configuration(src1, src2, dst, shape, scale, convert_policy, rounding_policy); |
| 350 | } |
| 351 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 352 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * (1.f / 255.f) * ConvertPolicies() |
| 353 | * RoundingPolicy::TO_NEAREST_UP, |
| 354 | shape, scale, convert_policy, rounding_policy) |
| 355 | { |
| 356 | // Compute function |
| 357 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, scale, convert_policy, rounding_policy); |
| 358 | |
| 359 | // Compute reference |
| 360 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, scale, convert_policy, rounding_policy); |
| 361 | |
| 362 | // Validate output |
| 363 | // Allow tolerance value of 1.f to counteract imprecision due to 32-bit float conversion |
| 364 | validate(NEAccessor(dst), ref_dst, 1.f, 0.f, std::numeric_limits<int16_t>::max()); |
| 365 | } |
| 366 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 367 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * (1.f / 255.f) * ConvertPolicies() |
| 368 | * RoundingPolicy::TO_NEAREST_UP, |
| 369 | shape, scale, convert_policy, rounding_policy) |
| 370 | { |
| 371 | // Compute function |
| 372 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, scale, convert_policy, rounding_policy); |
| 373 | |
| 374 | // Compute reference |
| 375 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, |
| 376 | scale, convert_policy, rounding_policy); |
| 377 | |
| 378 | // Validate output |
| 379 | // Allow tolerance value of 1.f to counteract imprecision due to 32-bit float conversion |
| 380 | validate(NEAccessor(dst), ref_dst, 1.f, 0.f, std::numeric_limits<int16_t>::max()); |
| 381 | } |
| 382 | BOOST_AUTO_TEST_SUITE_END() |
| 383 | |
| 384 | BOOST_AUTO_TEST_SUITE(ScaleOther) |
| 385 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 386 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) |
| 387 | * ConvertPolicies() |
| 388 | * RoundingPolicy::TO_ZERO, |
| 389 | shape, scale, convert_policy, rounding_policy) |
| 390 | { |
| 391 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 392 | Tensor src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 393 | Tensor src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 394 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 395 | |
| 396 | validate_configuration(src1, src2, dst, shape, scale, convert_policy, rounding_policy); |
| 397 | } |
| 398 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 399 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) * ConvertPolicies() |
| 400 | * RoundingPolicy::TO_ZERO, |
| 401 | shape, scale, convert_policy, rounding_policy) |
| 402 | { |
| 403 | // Compute function |
| 404 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, scale, convert_policy, rounding_policy); |
| 405 | |
| 406 | // Compute reference |
| 407 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, scale, convert_policy, rounding_policy); |
| 408 | |
| 409 | // Validate output |
| 410 | validate(NEAccessor(dst), ref_dst); |
| 411 | } |
| 412 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 413 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ 1.f, 1.f / 32768.f }) * ConvertPolicies() |
| 414 | * RoundingPolicy::TO_ZERO, |
| 415 | shape, scale, convert_policy, rounding_policy) |
| 416 | { |
| 417 | // Compute function |
| 418 | Tensor dst = compute_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, scale, convert_policy, rounding_policy); |
| 419 | |
| 420 | // Compute reference |
| 421 | RawTensor ref_dst = Reference::compute_reference_pixel_wise_multiplication(shape, DataType::F32, DataType::F32, DataType::F32, |
| 422 | scale, convert_policy, rounding_policy); |
| 423 | |
| 424 | // Validate output |
| 425 | validate(NEAccessor(dst), ref_dst); |
| 426 | } |
| 427 | BOOST_AUTO_TEST_SUITE_END() |
| 428 | BOOST_AUTO_TEST_SUITE_END() |
| 429 | |
Michele Di Giorgio | ab0a77e | 2017-06-21 15:36:24 +0100 | [diff] [blame] | 430 | BOOST_AUTO_TEST_SUITE(Quantized) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 431 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 432 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * DataType::QS8 *ConvertPolicies() * RoundingPolicy::TO_ZERO * boost::unit_test::data::xrange<int>(1, 7), |
| 433 | shape, dt, convert_policy, rounding_policy, fixed_point_position) |
| 434 | { |
| 435 | // Compute function |
| 436 | Tensor dst = compute_pixel_wise_multiplication(shape, dt, dt, dt, 1.f, convert_policy, rounding_policy, fixed_point_position); |
| 437 | |
| 438 | // Compute reference |
| 439 | RawTensor ref_dst = Reference::compute_reference_fixed_point_pixel_wise_multiplication(shape, dt, dt, dt, 1.f, fixed_point_position, convert_policy, rounding_policy); |
| 440 | |
| 441 | // Validate output |
| 442 | validate(NEAccessor(dst), ref_dst); |
| 443 | } |
| 444 | BOOST_AUTO_TEST_SUITE_END() |
| 445 | |
| 446 | BOOST_AUTO_TEST_SUITE_END() |
| 447 | BOOST_AUTO_TEST_SUITE_END() |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 448 | #endif /* DOXYGEN_SKIP_THIS */ |