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 "Reference.h" |
| 25 | |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 26 | #include "AssetsLibrary.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "Globals.h" |
| 28 | #include "Helpers.h" |
| 29 | #include "ReferenceCPP.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "validation/Helpers.h" |
| 31 | |
| 32 | #include <random> |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 33 | #include <vector> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | using namespace arm_compute::test; |
| 36 | |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 37 | #ifndef DOXYGEN_SKIP_THIS |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
Giorgio Arena | 50f9fd7 | 2017-06-19 17:05:30 +0100 | [diff] [blame] | 44 | std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value) |
| 45 | { |
| 46 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 47 | RawTensor ref_src(shape, Format::U8); |
| 48 | RawTensor ref_dst_x(shape, Format::S16); |
| 49 | RawTensor ref_dst_y(shape, Format::S16); |
Giorgio Arena | 50f9fd7 | 2017-06-19 17:05:30 +0100 | [diff] [blame] | 50 | |
| 51 | // Fill reference |
| 52 | library->fill_tensor_uniform(ref_src, 0); |
| 53 | |
| 54 | // Compute reference |
| 55 | ReferenceCPP::sobel_3x3(ref_src, ref_dst_x, ref_dst_y, border_mode, constant_border_value); |
| 56 | |
| 57 | return std::make_pair(ref_dst_x, ref_dst_y); |
| 58 | } |
| 59 | std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value) |
| 60 | { |
| 61 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 62 | RawTensor ref_src(shape, Format::U8); |
| 63 | RawTensor ref_dst_x(shape, Format::S16); |
| 64 | RawTensor ref_dst_y(shape, Format::S16); |
Giorgio Arena | 50f9fd7 | 2017-06-19 17:05:30 +0100 | [diff] [blame] | 65 | |
| 66 | // Fill reference |
| 67 | library->fill_tensor_uniform(ref_src, 0); |
| 68 | |
| 69 | // Compute reference |
| 70 | ReferenceCPP::sobel_5x5(ref_src, ref_dst_x, ref_dst_y, border_mode, constant_border_value); |
| 71 | |
| 72 | return std::make_pair(ref_dst_x, ref_dst_y); |
| 73 | } |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 74 | void Reference::compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, void *min, void *max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc, |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 75 | uint32_t &min_count, uint32_t &max_count) |
| 76 | { |
| 77 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 78 | RawTensor ref_src(shape, dt_in); |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 79 | |
| 80 | // Fill reference |
| 81 | library->fill_tensor_uniform(ref_src, 0); |
| 82 | |
| 83 | // Compute reference |
| 84 | ReferenceCPP::min_max_location(ref_src, min, max, min_loc, max_loc, min_count, max_count); |
| 85 | } |
Giorgio Arena | f795986 | 2017-06-13 15:19:51 +0100 | [diff] [blame] | 86 | std::pair<float, float> Reference::compute_reference_mean_and_standard_deviation(const TensorShape &shape) |
| 87 | { |
| 88 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 89 | RawTensor ref_src(shape, DataType::U8); |
Giorgio Arena | f795986 | 2017-06-13 15:19:51 +0100 | [diff] [blame] | 90 | |
| 91 | // Create output variables |
| 92 | float mean; |
| 93 | float std_dev; |
| 94 | |
| 95 | // Fill reference |
| 96 | library->fill_tensor_uniform(ref_src, 0); |
| 97 | |
| 98 | // Compute reference |
| 99 | ReferenceCPP::mean_and_standard_deviation(ref_src, mean, std_dev); |
| 100 | |
| 101 | return std::make_pair(mean, std_dev); |
| 102 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | RawTensor Reference::compute_reference_integral_image(const TensorShape &shape) |
| 104 | { |
| 105 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 106 | RawTensor ref_src(shape, DataType::U8); |
| 107 | RawTensor ref_dst(shape, DataType::U32); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 108 | |
| 109 | // Fill reference |
| 110 | library->fill_tensor_uniform(ref_src, 0); |
| 111 | |
| 112 | // Compute reference |
| 113 | ReferenceCPP::integral_image(ref_src, ref_dst); |
| 114 | |
| 115 | return ref_dst; |
| 116 | } |
| 117 | RawTensor Reference::compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out) |
| 118 | { |
| 119 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 120 | RawTensor ref_src1(shape, dt_in0); |
| 121 | RawTensor ref_src2(shape, dt_in1); |
| 122 | RawTensor ref_dst(shape, dt_out); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 123 | |
| 124 | // Fill reference |
| 125 | library->fill_tensor_uniform(ref_src1, 0); |
| 126 | library->fill_tensor_uniform(ref_src2, 1); |
| 127 | |
| 128 | // Compute reference |
| 129 | ReferenceCPP::absolute_difference(ref_src1, ref_src2, ref_dst); |
| 130 | |
| 131 | return ref_dst; |
| 132 | } |
| 133 | |
| 134 | RawTensor Reference::compute_reference_accumulate(const TensorShape &shape) |
| 135 | { |
| 136 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 137 | RawTensor ref_src(shape, DataType::U8); |
| 138 | RawTensor ref_dst(shape, DataType::S16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 139 | |
| 140 | // Fill reference |
| 141 | library->fill_tensor_uniform(ref_src, 0); |
| 142 | library->fill_tensor_uniform(ref_dst, 1); |
| 143 | |
| 144 | // Compute reference |
| 145 | ReferenceCPP::accumulate(ref_src, ref_dst); |
| 146 | |
| 147 | return ref_dst; |
| 148 | } |
| 149 | |
| 150 | RawTensor Reference::compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift) |
| 151 | { |
| 152 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 153 | RawTensor ref_src(shape, DataType::U8); |
| 154 | RawTensor ref_dst(shape, DataType::S16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 155 | |
| 156 | // Fill reference |
| 157 | // ref_dst tensor filled with non-negative values |
| 158 | library->fill_tensor_uniform(ref_src, 0); |
| 159 | library->fill_tensor_uniform(ref_dst, 1, static_cast<int16_t>(0), std::numeric_limits<int16_t>::max()); |
| 160 | |
| 161 | // Compute reference |
| 162 | ReferenceCPP::accumulate_squared(ref_src, ref_dst, shift); |
| 163 | |
| 164 | return ref_dst; |
| 165 | } |
| 166 | |
| 167 | RawTensor Reference::compute_reference_accumulate_weighted(const TensorShape &shape, float alpha) |
| 168 | { |
| 169 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 170 | RawTensor ref_src(shape, DataType::U8); |
| 171 | RawTensor ref_dst(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 172 | |
| 173 | // Fill reference |
| 174 | library->fill_tensor_uniform(ref_src, 0); |
| 175 | library->fill_tensor_uniform(ref_dst, 1); |
| 176 | |
| 177 | // Compute reference |
| 178 | ReferenceCPP::accumulate_weighted(ref_src, ref_dst, alpha); |
| 179 | |
| 180 | return ref_dst; |
| 181 | } |
| 182 | |
Michele Di Giorgio | 81f0d15 | 2017-07-11 15:00:52 +0100 | [diff] [blame] | 183 | RawTensor Reference::compute_reference_arithmetic_addition(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy, int fixed_point_position) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 184 | { |
| 185 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 186 | RawTensor ref_src1(shape, dt_in0, 1, fixed_point_position); |
| 187 | RawTensor ref_src2(shape, dt_in1, 1, fixed_point_position); |
| 188 | RawTensor ref_dst(shape, dt_out, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 189 | |
| 190 | // Fill reference |
| 191 | library->fill_tensor_uniform(ref_src1, 0); |
| 192 | library->fill_tensor_uniform(ref_src2, 1); |
| 193 | |
| 194 | // Compute reference |
| 195 | ReferenceCPP::arithmetic_addition(ref_src1, ref_src2, ref_dst, convert_policy); |
| 196 | |
| 197 | return ref_dst; |
| 198 | } |
| 199 | |
Michele Di Giorgio | 81f0d15 | 2017-07-11 15:00:52 +0100 | [diff] [blame] | 200 | RawTensor Reference::compute_reference_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy, int fixed_point_position) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 201 | { |
| 202 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 203 | RawTensor ref_src1(shape, dt_in0, 1, fixed_point_position); |
| 204 | RawTensor ref_src2(shape, dt_in1, 1, fixed_point_position); |
| 205 | RawTensor ref_dst(shape, dt_out, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 206 | |
| 207 | // Fill reference |
| 208 | library->fill_tensor_uniform(ref_src1, 0); |
| 209 | library->fill_tensor_uniform(ref_src2, 1); |
| 210 | |
| 211 | // Compute reference |
| 212 | ReferenceCPP::arithmetic_subtraction(ref_src1, ref_src2, ref_dst, convert_policy); |
| 213 | |
| 214 | return ref_dst; |
| 215 | } |
| 216 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 217 | RawTensor Reference::compute_reference_bitwise_xor(const TensorShape &shape) |
| 218 | { |
| 219 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 220 | RawTensor ref_src1(shape, DataType::U8); |
| 221 | RawTensor ref_src2(shape, DataType::U8); |
| 222 | RawTensor ref_dst(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 223 | |
| 224 | // Fill reference |
| 225 | library->fill_tensor_uniform(ref_src1, 0); |
| 226 | library->fill_tensor_uniform(ref_src2, 1); |
| 227 | |
| 228 | // Compute reference |
| 229 | ReferenceCPP::bitwise_xor(ref_src1, ref_src2, ref_dst); |
| 230 | |
| 231 | return ref_dst; |
| 232 | } |
| 233 | |
| 234 | RawTensor Reference::compute_reference_bitwise_not(const TensorShape &shape) |
| 235 | { |
| 236 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 237 | RawTensor ref_src(shape, DataType::U8); |
| 238 | RawTensor ref_dst(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 239 | |
| 240 | // Fill reference |
| 241 | library->fill_tensor_uniform(ref_src, 0); |
| 242 | |
| 243 | // Compute reference |
| 244 | ReferenceCPP::bitwise_not(ref_src, ref_dst); |
| 245 | |
| 246 | return ref_dst; |
| 247 | } |
| 248 | |
SiCong Li | bacaf9a | 2017-06-19 13:41:45 +0100 | [diff] [blame] | 249 | RawTensor Reference::compute_reference_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 250 | { |
| 251 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 252 | RawTensor ref_src(shape, DataType::U8); |
| 253 | RawTensor ref_dst(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 254 | |
| 255 | // Fill reference |
| 256 | library->fill_tensor_uniform(ref_src, 0); |
| 257 | |
| 258 | // Compute reference |
SiCong Li | bacaf9a | 2017-06-19 13:41:45 +0100 | [diff] [blame] | 259 | ReferenceCPP::box3x3(ref_src, ref_dst, border_mode, constant_border_value); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 260 | |
| 261 | return ref_dst; |
| 262 | } |
| 263 | |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 264 | RawTensor Reference::compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, |
| 265 | uint32_t shift, uint32_t fixed_point_position_in, uint32_t fixed_point_position_out) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 266 | { |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 267 | RawTensor ref_src(shape, dt_in, 1, fixed_point_position_in); |
| 268 | RawTensor ref_dst(shape, dt_out, 1, fixed_point_position_out); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 269 | |
| 270 | // Fill reference |
| 271 | library->fill_tensor_uniform(ref_src, 0); |
| 272 | |
| 273 | // Compute reference |
| 274 | ReferenceCPP::depth_convert(ref_src, ref_dst, policy, shift); |
| 275 | |
| 276 | return ref_dst; |
| 277 | } |
| 278 | |
SiCong Li | 5a53664 | 2017-06-19 14:47:05 +0100 | [diff] [blame] | 279 | RawTensor Reference::compute_reference_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value) |
| 280 | { |
| 281 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 282 | RawTensor ref_src(shape, DataType::U8); |
| 283 | RawTensor ref_dst(shape, DataType::U8); |
SiCong Li | 5a53664 | 2017-06-19 14:47:05 +0100 | [diff] [blame] | 284 | |
| 285 | // Fill reference |
| 286 | library->fill_tensor_uniform(ref_src, 0); |
| 287 | |
| 288 | // Compute reference |
| 289 | ReferenceCPP::gaussian3x3(ref_src, ref_dst, border_mode, constant_border_value); |
| 290 | |
| 291 | return ref_dst; |
| 292 | } |
| 293 | |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 294 | RawTensor Reference::compute_reference_gaussian5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value) |
| 295 | { |
| 296 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 297 | RawTensor ref_src(shape, DataType::U8); |
| 298 | RawTensor ref_dst(shape, DataType::U8); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 299 | |
| 300 | // Fill reference |
| 301 | library->fill_tensor_uniform(ref_src, 0); |
| 302 | |
| 303 | // Compute reference |
| 304 | ReferenceCPP::gaussian5x5(ref_src, ref_dst, border_mode, constant_border_value); |
| 305 | |
| 306 | return ref_dst; |
| 307 | } |
| 308 | |
Isabella Gottardi | 3b77e9d | 2017-06-22 11:05:41 +0100 | [diff] [blame] | 309 | RawTensor Reference::compute_reference_non_linear_filter(const TensorShape &shape, NonLinearFilterFunction function, unsigned int mask_size, |
| 310 | MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value) |
| 311 | { |
| 312 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 313 | RawTensor ref_src(shape, DataType::U8); |
| 314 | RawTensor ref_dst(shape, DataType::U8); |
Isabella Gottardi | 3b77e9d | 2017-06-22 11:05:41 +0100 | [diff] [blame] | 315 | |
| 316 | // Fill reference |
| 317 | library->fill_tensor_uniform(ref_src, 0); |
| 318 | |
| 319 | // Compute reference |
| 320 | ReferenceCPP::non_linear_filter(ref_src, ref_dst, function, mask_size, pattern, mask, border_mode, constant_border_value); |
| 321 | |
| 322 | return ref_dst; |
| 323 | } |
| 324 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 325 | RawTensor Reference::compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy, |
| 326 | RoundingPolicy rounding_policy) |
| 327 | { |
| 328 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 329 | RawTensor ref_src1(shape, dt_in0); |
| 330 | RawTensor ref_src2(shape, dt_in1); |
| 331 | RawTensor ref_dst(shape, dt_out); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 332 | |
| 333 | // Fill reference |
| 334 | library->fill_tensor_uniform(ref_src1, 0); |
| 335 | library->fill_tensor_uniform(ref_src2, 1); |
| 336 | |
| 337 | // Compute reference |
| 338 | ReferenceCPP::pixel_wise_multiplication(ref_src1, ref_src2, ref_dst, scale, convert_policy, rounding_policy); |
| 339 | |
| 340 | return ref_dst; |
| 341 | } |
| 342 | |
| 343 | RawTensor Reference::compute_reference_fixed_point_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, int fixed_point_position, |
| 344 | ConvertPolicy convert_policy, RoundingPolicy rounding_policy) |
| 345 | { |
| 346 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 347 | RawTensor ref_src1(shape, dt_in0, 1, fixed_point_position); |
| 348 | RawTensor ref_src2(shape, dt_in1, 1, fixed_point_position); |
| 349 | RawTensor ref_dst(shape, dt_out, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 350 | |
| 351 | // Fill reference |
| 352 | library->fill_tensor_uniform(ref_src1, 0); |
| 353 | library->fill_tensor_uniform(ref_src2, 1); |
| 354 | |
| 355 | // Compute reference |
| 356 | ReferenceCPP::fixed_point_pixel_wise_multiplication(ref_src1, ref_src2, ref_dst, scale, convert_policy, rounding_policy); |
| 357 | |
| 358 | return ref_dst; |
| 359 | } |
| 360 | |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 361 | template <typename T> |
| 362 | RawTensor Reference::compute_reference_table_lookup(const TensorShape &shape, DataType dt_inout, std::map<T, T> &lut) |
| 363 | { |
| 364 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 365 | RawTensor ref_src(shape, dt_inout); |
| 366 | RawTensor ref_dst(shape, dt_inout); |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 367 | // Fill reference |
| 368 | library->fill_tensor_uniform(ref_src, 0); |
| 369 | |
| 370 | // Compute reference |
| 371 | ReferenceCPP::table_lookup(ref_src, ref_dst, lut); |
| 372 | |
| 373 | return ref_dst; |
| 374 | } |
| 375 | template RawTensor arm_compute::test::validation::Reference::compute_reference_table_lookup<uint8_t>(const TensorShape &shape, DataType dt_inout, std::map<uint8_t, uint8_t> &lut); |
| 376 | template RawTensor arm_compute::test::validation::Reference::compute_reference_table_lookup<int16_t>(const TensorShape &shape, DataType dt_inout, std::map<int16_t, int16_t> &lut); |
| 377 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 378 | RawTensor Reference::compute_reference_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper) |
| 379 | { |
| 380 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 381 | RawTensor ref_src(shape, DataType::U8); |
| 382 | RawTensor ref_dst(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 383 | |
| 384 | // Fill reference |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 385 | library->fill_tensor_uniform(ref_src, 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 386 | |
| 387 | // Compute reference |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 388 | ReferenceCPP::threshold(ref_src, ref_dst, threshold, false_value, true_value, type, upper); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 389 | |
| 390 | return ref_dst; |
| 391 | } |
| 392 | |
Isabella Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame^] | 393 | RawTensor Reference::compute_reference_warp_perspective(const TensorShape &shape, RawTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, |
| 394 | uint8_t constant_border_value) |
| 395 | { |
| 396 | // Create reference |
| 397 | RawTensor ref_src(shape, DataType::U8); |
| 398 | RawTensor ref_dst(shape, DataType::U8); |
| 399 | |
| 400 | // Fill reference |
| 401 | library->fill_tensor_uniform(ref_src, 0); |
| 402 | |
| 403 | // Compute reference |
| 404 | ReferenceCPP::warp_perspective(ref_src, ref_dst, valid_mask, matrix, policy, border_mode, constant_border_value); |
| 405 | |
| 406 | return ref_dst; |
| 407 | } |
| 408 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 409 | RawTensor Reference::compute_reference_batch_normalization_layer(const TensorShape &shape0, const TensorShape &shape1, DataType dt, float epsilon, int fixed_point_position) |
| 410 | { |
| 411 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 412 | RawTensor ref_src(shape0, dt, 1, fixed_point_position); |
| 413 | RawTensor ref_dst(shape0, dt, 1, fixed_point_position); |
| 414 | RawTensor ref_mean(shape1, dt, 1, fixed_point_position); |
| 415 | RawTensor ref_var(shape1, dt, 1, fixed_point_position); |
| 416 | RawTensor ref_beta(shape1, dt, 1, fixed_point_position); |
| 417 | RawTensor ref_gamma(shape1, dt, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 418 | |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 419 | // Fill tensors |
| 420 | switch(dt) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 421 | { |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 422 | case DataType::QS8: |
Michalis Spyrou | 172e570 | 2017-06-26 14:18:47 +0100 | [diff] [blame] | 423 | { |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 424 | const std::pair<int8_t, int8_t> bounds = get_batchnormalization_layer_test_bounds<int8_t>(fixed_point_position); |
| 425 | std::uniform_int_distribution<> distribution(bounds.first, bounds.second); |
| 426 | std::uniform_int_distribution<> distribution_var(0, bounds.second); |
| 427 | fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma); |
| 428 | fill_tensors(distribution_var, { 0 }, &ref_var); |
| 429 | break; |
Michalis Spyrou | 172e570 | 2017-06-26 14:18:47 +0100 | [diff] [blame] | 430 | } |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 431 | case DataType::QS16: |
Michalis Spyrou | 172e570 | 2017-06-26 14:18:47 +0100 | [diff] [blame] | 432 | { |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 433 | const std::pair<int16_t, int16_t> bounds = get_batchnormalization_layer_test_bounds<int16_t>(fixed_point_position); |
| 434 | std::uniform_int_distribution<> distribution(bounds.first, bounds.second); |
| 435 | std::uniform_int_distribution<> distribution_var(0, bounds.second); |
| 436 | fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma); |
| 437 | fill_tensors(distribution_var, { 0 }, &ref_var); |
| 438 | break; |
Michalis Spyrou | 172e570 | 2017-06-26 14:18:47 +0100 | [diff] [blame] | 439 | } |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 440 | case DataType::F16: |
| 441 | { |
| 442 | const std::pair<half_float::half, half_float::half> bounds = get_batchnormalization_layer_test_bounds<half_float::half>(); |
| 443 | std::uniform_real_distribution<> distribution(bounds.first, bounds.second); |
| 444 | std::uniform_real_distribution<> distribution_var(0, bounds.second); |
| 445 | fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma); |
| 446 | fill_tensors(distribution_var, { 0 }, &ref_var); |
| 447 | break; |
| 448 | } |
| 449 | case DataType::F32: |
| 450 | { |
| 451 | const std::pair<float, float> bounds = get_batchnormalization_layer_test_bounds<float>(); |
| 452 | std::uniform_real_distribution<> distribution(bounds.first, bounds.second); |
| 453 | std::uniform_real_distribution<> distribution_var(0, bounds.second); |
| 454 | fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma); |
| 455 | fill_tensors(distribution_var, { 0 }, &ref_var); |
| 456 | break; |
| 457 | } |
| 458 | default: |
| 459 | { |
| 460 | ARM_COMPUTE_ERROR("Not supported"); |
| 461 | break; |
| 462 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | // Compute reference |
| 466 | ReferenceCPP::batch_normalization_layer(ref_src, ref_dst, ref_mean, ref_var, ref_beta, ref_gamma, epsilon, fixed_point_position); |
| 467 | |
| 468 | return ref_dst; |
| 469 | } |
| 470 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 471 | RawTensor Reference::compute_reference_fully_connected_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, |
| 472 | DataType dt, bool transpose_weights, int fixed_point_position) |
| 473 | { |
| 474 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 475 | RawTensor ref_src(input_shape, dt, 1, fixed_point_position); |
| 476 | RawTensor ref_bias(bias_shape, dt, 1, fixed_point_position); |
| 477 | RawTensor ref_dst(output_shape, dt, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 478 | |
| 479 | // Swap the first and second dimension of weights' shape if transpose_weights is true |
| 480 | TensorShape ws = weights_shape; |
| 481 | if(transpose_weights) |
| 482 | { |
| 483 | const size_t dimx = ws.x(); |
| 484 | ws.set(0, ws.y()); |
| 485 | ws.set(1, dimx); |
| 486 | } |
| 487 | |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 488 | RawTensor ref_weights(ws, dt, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 489 | |
| 490 | // Fill reference |
Pablo Tello | dcdc85e | 2017-06-28 10:05:29 +0100 | [diff] [blame] | 491 | if(dt == DataType::F16 || dt == DataType::F32) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 492 | { |
| 493 | std::uniform_real_distribution<> distribution(-1.0f, 1.0f); |
| 494 | library->fill(ref_src, distribution, 0); |
| 495 | library->fill(ref_weights, distribution, 1); |
| 496 | library->fill(ref_bias, distribution, 2); |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | library->fill_tensor_uniform(ref_src, 0); |
| 501 | library->fill_tensor_uniform(ref_weights, 1); |
| 502 | library->fill_tensor_uniform(ref_bias, 2); |
| 503 | } |
| 504 | |
| 505 | // Compute reference |
| 506 | ReferenceCPP::fully_connected_layer(ref_src, ref_weights, ref_bias, ref_dst); |
| 507 | |
| 508 | return ref_dst; |
| 509 | } |
| 510 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 511 | RawTensor Reference::compute_reference_pooling_layer(const TensorShape &shape_in, const TensorShape &shape_out, DataType dt, PoolingLayerInfo pool_info, int fixed_point_position) |
| 512 | { |
| 513 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 514 | RawTensor ref_src(shape_in, dt, 1, fixed_point_position); |
| 515 | RawTensor ref_dst(shape_out, dt, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 516 | |
| 517 | // Fill reference |
| 518 | int min = 0; |
| 519 | int max = 0; |
| 520 | switch(dt) |
| 521 | { |
| 522 | case DataType::F32: |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 523 | case DataType::F16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 524 | min = -1; |
| 525 | max = 1; |
| 526 | break; |
| 527 | case DataType::QS8: |
| 528 | min = -(1 << fixed_point_position); |
| 529 | max = (1 << fixed_point_position); |
| 530 | break; |
| 531 | default: |
| 532 | ARM_COMPUTE_ERROR("DataType not supported."); |
| 533 | } |
| 534 | std::uniform_real_distribution<> distribution(min, max); |
| 535 | library->fill(ref_src, distribution, 0.0); |
| 536 | |
| 537 | // Compute reference |
| 538 | ReferenceCPP::pooling_layer(ref_src, ref_dst, pool_info, fixed_point_position); |
| 539 | |
| 540 | return ref_dst; |
| 541 | } |
| 542 | |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 543 | RawTensor Reference::compute_reference_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info) |
| 544 | { |
| 545 | TensorShape shape_dst; |
| 546 | shape_dst.set(0, pool_info.pooled_width()); |
| 547 | shape_dst.set(1, pool_info.pooled_height()); |
| 548 | shape_dst.set(2, shape.z()); |
| 549 | shape_dst.set(3, rois.size()); |
| 550 | |
| 551 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 552 | RawTensor ref_src(shape, dt); |
| 553 | RawTensor ref_dst(shape_dst, dt); |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 554 | |
| 555 | // Fill reference |
| 556 | std::uniform_real_distribution<> distribution(-1, 1); |
| 557 | library->fill(ref_src, distribution, 0.0); |
| 558 | |
| 559 | // Compute reference |
| 560 | ReferenceCPP::roi_pooling_layer(ref_src, ref_dst, rois, pool_info); |
| 561 | |
| 562 | return ref_dst; |
| 563 | } |
| 564 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 565 | RawTensor Reference::compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position) |
| 566 | { |
| 567 | // Create reference |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 568 | RawTensor ref_src(shape, dt_in, 1, fixed_point_position); |
| 569 | RawTensor ref_dst(shape, dt_out, 1, fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 570 | |
| 571 | // Fill reference |
| 572 | int min = 0; |
| 573 | int max = 0; |
| 574 | switch(op) |
| 575 | { |
| 576 | case(FixedPointOp::INV_SQRT): |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 577 | min = 1; |
| 578 | max = (dt_in == DataType::QS8) ? 0x7F : 0x7FFF; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 579 | break; |
| 580 | case(FixedPointOp::LOG): |
| 581 | min = (1 << (fixed_point_position - 1)); |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 582 | max = (dt_in == DataType::QS8) ? 0x3F : 0x3FFF; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 583 | break; |
| 584 | case(FixedPointOp::EXP): |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 585 | min = -(1 << (fixed_point_position - 1)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 586 | max = (1 << (fixed_point_position - 1)); |
| 587 | break; |
| 588 | case(FixedPointOp::RECIPROCAL): |
| 589 | min = 15; |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 590 | max = (dt_in == DataType::QS8) ? 0x7F : 0x7FFF; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 591 | break; |
| 592 | default: |
| 593 | ARM_COMPUTE_ERROR("Fixed point operation not supported"); |
| 594 | } |
| 595 | std::uniform_int_distribution<> distribution(min, max); |
| 596 | library->fill(ref_src, distribution, 0); |
| 597 | |
| 598 | // Compute reference |
| 599 | ReferenceCPP::fixed_point_operation(ref_src, ref_dst, op); |
| 600 | |
| 601 | return ref_dst; |
| 602 | } |
| 603 | |
| 604 | } // namespace validation |
| 605 | } // namespace test |
| 606 | } // namespace arm_compute |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 607 | #endif /* DOXYGEN_SKIP_THIS */ |