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 | #ifndef __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_H__ |
| 25 | #define __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_H__ |
| 26 | |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/Array.h" |
Moritz Pflanzer | f4af76e | 2017-09-06 07:42:43 +0100 | [diff] [blame] | 28 | #include "tests/RawTensor.h" |
| 29 | #include "tests/Types.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 31 | #include <map> |
Georgios Pinitas | d4f8c27 | 2017-06-30 16:16:19 +0100 | [diff] [blame] | 32 | #include <vector> |
| 33 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | namespace validation |
| 39 | { |
| 40 | /** Interface for reference implementations. */ |
| 41 | class Reference |
| 42 | { |
| 43 | public: |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 44 | /** Compute reference Harris corners. |
| 45 | * |
| 46 | * @param[in] shape Shape of input tensor |
| 47 | * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). |
| 48 | * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage |
| 49 | * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation |
| 50 | * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7 |
| 51 | * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7. |
| 52 | * @param[in] border_mode Border mode to use |
| 53 | * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT. |
| 54 | * |
| 55 | * @return Computed corners' keypoints. |
| 56 | */ |
| 57 | static KeyPointArray compute_reference_harris_corners(const TensorShape &shape, float threshold, float min_dist, float sensitivity, |
| 58 | int32_t gradient_size, int32_t block_size, BorderMode border_mode, uint8_t constant_border_value); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | /** Compute reference absolute difference. |
| 60 | * |
| 61 | * @param[in] shape Shape of the input and output tensors. |
| 62 | * @param[in] dt_in0 Data type of first input tensor. |
| 63 | * @param[in] dt_in1 Data type of second input tensor. |
| 64 | * @param[in] dt_out Data type of the output tensor. |
| 65 | * |
| 66 | * @return Computed raw tensor. |
| 67 | */ |
| 68 | static RawTensor compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out); |
| 69 | /** Compute reference accumulate. |
| 70 | * |
| 71 | * @param[in] shape Shape of the input and output tensors. |
| 72 | * |
| 73 | * @return Computed raw tensor. |
| 74 | */ |
| 75 | static RawTensor compute_reference_accumulate(const TensorShape &shape); |
| 76 | /** Compute reference accumulate. |
| 77 | * |
| 78 | * @param[in] shape Shape of the input and output tensors. |
| 79 | * @param[in] shift A uint32_t value within the range of [0, 15] |
| 80 | * |
| 81 | * @return Computed raw tensor. |
| 82 | */ |
| 83 | static RawTensor compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift); |
| 84 | /** Compute reference accumulate. |
| 85 | * |
| 86 | * @param[in] shape Shape of the input and output tensors. |
| 87 | * @param[in] alpha A float value within the range of [0, 1] |
| 88 | * |
| 89 | * @return Computed raw tensor. |
| 90 | */ |
| 91 | static RawTensor compute_reference_accumulate_weighted(const TensorShape &shape, float alpha); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | /** Compute reference pixel-wise multiplication |
| 93 | * |
| 94 | * @param[in] shape Shape of the input and output tensors. |
| 95 | * @param[in] dt_in0 Data type of first input tensor. |
| 96 | * @param[in] dt_in1 Data type of second input tensor. |
| 97 | * @param[in] dt_out Data type of the output tensor. |
| 98 | * @param[in] scale Non-negative scale. |
| 99 | * @param[in] convert_policy Overflow policy of the operation. |
| 100 | * @param[in] rounding_policy Rounding policy of the operation. |
| 101 | * |
| 102 | * @return Computed raw tensor. |
| 103 | */ |
| 104 | static RawTensor compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy, |
| 105 | RoundingPolicy rounding_policy); |
| 106 | /** Compute reference pixel-wise multiplication. |
| 107 | * |
| 108 | * @param[in] shape Shape of the input and output tensors. |
| 109 | * @param[in] dt_in0 Data type of first input tensor. |
| 110 | * @param[in] dt_in1 Data type of second input tensor. |
| 111 | * @param[in] dt_out Data type of the output tensor. |
| 112 | * @param[in] scale Scale to apply after multiplication. Must be positive. |
| 113 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number. |
| 114 | * @param[in] convert_policy Overflow policy of the operation. |
| 115 | * @param[in] rounding_policy Rounding policy of the operation. |
| 116 | * |
| 117 | * @return Computed raw tensor. |
| 118 | */ |
| 119 | static RawTensor 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, |
| 120 | ConvertPolicy convert_policy, RoundingPolicy rounding_policy); |
Isabella Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame] | 121 | /** Compute reference Warp Perspective. |
| 122 | * |
| 123 | * @param[in] shape Shape of the input and output tensors. |
| 124 | * @param[out] valid_mask Valid mask tensor. |
| 125 | * @param[in] matrix The perspective matrix. Must be 3x3 of type float. |
| 126 | * @param[in] policy The interpolation type. |
| 127 | * @param[in] border_mode Strategy to use for borders. |
| 128 | * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT. |
| 129 | * |
| 130 | * @return Computed raw tensor. |
| 131 | */ |
| 132 | static RawTensor compute_reference_warp_perspective(const TensorShape &shape, RawTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, |
| 133 | uint8_t constant_border_value); |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 134 | /** Compute reference roi pooling layer. |
| 135 | * |
| 136 | * @param[in] shape Shape of the input tensor. |
| 137 | * @param[in] dt Data type of input and output tensors. |
| 138 | * @param[in] rois Region of interest vector. |
| 139 | * @param[in] pool_info ROI Pooling Layer information. |
| 140 | */ |
| 141 | static RawTensor compute_reference_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 142 | /** Compute reference fixed point operation. |
| 143 | * |
| 144 | * @param[in] shape Shape of the input and output tensors. |
| 145 | * @param[in] dt_in Data type of the input tensor. |
| 146 | * @param[in] dt_out Data type of the output tensor. |
| 147 | * @param[in] op Fixed point operation to perform. |
| 148 | * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers |
| 149 | * |
| 150 | * @return Computed raw tensor. |
| 151 | */ |
| 152 | static RawTensor compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position); |
| 153 | |
| 154 | protected: |
| 155 | Reference() = default; |
| 156 | ~Reference() = default; |
| 157 | }; |
| 158 | } // namespace validation |
| 159 | } // namespace test |
| 160 | } // namespace arm_compute |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 161 | #endif /* __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_H__ */ |