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