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_CPP_H__ |
| 25 | #define __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_CPP_H__ |
| 26 | |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 27 | #include "RawTensor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "Reference.h" |
| 29 | |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 30 | #include <map> |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 31 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include <ostream> |
Georgios Pinitas | d4f8c27 | 2017-06-30 16:16:19 +0100 | [diff] [blame] | 33 | #include <vector> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | class Tensor; |
| 38 | |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | /** C++ reference implementation. */ |
| 44 | class ReferenceCPP final : public Reference |
| 45 | { |
| 46 | public: |
Giorgio Arena | 50f9fd7 | 2017-06-19 17:05:30 +0100 | [diff] [blame] | 47 | /** Function to compute reference sobel 3x3. |
| 48 | * |
| 49 | * @param[in] src Input tensor. |
| 50 | * @param[in] dst_x Result tensor along x axis |
| 51 | * @param[in] dst_y Result tensor along y axis |
| 52 | * @param[in] border_mode Border mode to use for input tensor |
| 53 | * @param[in] constant_border_value Constant value to use if @p border_mode is constant |
| 54 | * |
| 55 | */ |
| 56 | static void sobel_3x3(RawTensor &src, RawTensor &dst_x, RawTensor &dst_y, BorderMode border_mode, uint8_t constant_border_value); |
| 57 | /** Function to compute reference sobel 5x5. |
| 58 | * |
| 59 | * @param[in] src Input tensor. |
| 60 | * @param[in] dst_x Result tensor along x axis |
| 61 | * @param[in] dst_y Result tensor along y axis |
| 62 | * @param[in] border_mode Border mode to use for input tensor |
| 63 | * @param[in] constant_border_value Constant value to use if @p border_mode is constant |
| 64 | * |
| 65 | */ |
| 66 | static void sobel_5x5(RawTensor &src, RawTensor &dst_x, RawTensor &dst_y, BorderMode border_mode, uint8_t constant_border_value); |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 67 | /** Function to compute reference Harris corners. |
| 68 | * |
| 69 | * @param[in] src Input tensor |
| 70 | * @param[in] Gx Tensor used to compute Sobel along the x axis |
| 71 | * @param[in] Gy Tensor used to compute Sobel along the y axis |
| 72 | * @param[in] candidates Tensor used to store candidate corners |
| 73 | * @param[in] non_maxima Tensor used to store non_maxima suppressed candidate corners |
| 74 | * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). |
| 75 | * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage |
| 76 | * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation |
| 77 | * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7 |
| 78 | * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7. |
| 79 | * @param[out] corners Array of keypoints to store the results. |
| 80 | * @param[in] border_mode Border mode to use |
| 81 | * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT. |
| 82 | * |
| 83 | */ |
| 84 | static void harris_corners(RawTensor &src, RawTensor &Gx, RawTensor &Gy, const RawTensor &candidates, const RawTensor &non_maxima, float threshold, float min_dist, float sensitivity, |
| 85 | int32_t gradient_size, int32_t block_size, KeyPointArray &corners, BorderMode border_mode, uint8_t constant_border_value); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | /** Function to compute the integral image of a tensor. |
| 87 | * |
| 88 | * @param[in] src Input tensor. |
| 89 | * @param[out] dst Result tensor. |
| 90 | */ |
| 91 | static void integral_image(const RawTensor &src, RawTensor &dst); |
| 92 | /** Function to compute the absolute difference between two tensors. |
| 93 | * |
| 94 | * @param[in] src1 First tensor. |
| 95 | * @param[in] src2 Second tensor. |
| 96 | * @param[out] dst Result tensor. |
| 97 | */ |
| 98 | static void absolute_difference(const RawTensor &src1, const RawTensor &src2, RawTensor &dst); |
| 99 | /** Function to accumulate an input tensor into an output tensor. |
| 100 | * |
| 101 | * @param[in] src Input tensor. |
| 102 | * @param[in, out] dst Result tensor. |
| 103 | */ |
| 104 | static void accumulate(const RawTensor &src, RawTensor &dst); |
| 105 | /** Function to accumulate a squared value from an input tensor to an output tensor. |
| 106 | * |
| 107 | * @param[in] src Input tensor. |
| 108 | * @param[in, out] dst Result tensor. |
| 109 | * @param[in] shift A uint32_t value within the range of [0, 15] |
| 110 | */ |
| 111 | static void accumulate_squared(const RawTensor &src, RawTensor &dst, uint32_t shift); |
| 112 | /** Function to accumulate a weighted value from an input tensor to an output tensor. |
| 113 | * |
| 114 | * @param[in] src Input tensor. |
| 115 | * @param[in, out] dst Result tensor. |
| 116 | * @param[in] alpha A float value within the range of [0, 1] |
| 117 | */ |
| 118 | static void accumulate_weighted(const RawTensor &src, RawTensor &dst, float alpha); |
SiCong Li | 5a53664 | 2017-06-19 14:47:05 +0100 | [diff] [blame] | 119 | /** Function to compute gaussian3x3 filtered result tensor. |
| 120 | * |
| 121 | * @param[in] src Input tensor. |
| 122 | * @param[out] dst Result tensor. |
| 123 | * @param[in] border_mode Border mode |
| 124 | * @param[in] constant_border_value Constant border value if @p border_mode is BorderMode::CONSTANT |
| 125 | */ |
| 126 | static void gaussian3x3(const RawTensor &src, RawTensor &dst, BorderMode border_mode, uint8_t constant_border_value); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 127 | /** Function to compute gaussian5x5 filtered result tensor. |
| 128 | * |
| 129 | * @param[in] src Input tensor. |
| 130 | * @param[out] dst Result tensor. |
| 131 | * @param[in] border_mode Border mode |
| 132 | * @param[in] constant_border_value Constant border value if @p border_mode is BorderMode::CONSTANT |
| 133 | */ |
| 134 | static void gaussian5x5(const RawTensor &src, RawTensor &dst, BorderMode border_mode, uint8_t constant_border_value); |
Isabella Gottardi | 3b77e9d | 2017-06-22 11:05:41 +0100 | [diff] [blame] | 135 | /** Compute non linear filter function. |
| 136 | * |
| 137 | * @param[in] src First input tensor |
| 138 | * @param[out] dst Output tensor |
| 139 | * @param[in] function Non linear function to perform |
| 140 | * @param[in] mask_size Mask size. Supported sizes: 3, 5 |
| 141 | * @param[in] pattern Matrix pattern |
| 142 | * @param[in] mask The given mask. |
| 143 | * @param[in] border_mode Strategy to use for borders. |
| 144 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. |
| 145 | */ |
| 146 | static void non_linear_filter(const RawTensor &src, RawTensor &dst, NonLinearFilterFunction function, unsigned int mask_size, |
| 147 | MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value = 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 148 | /** Element-wise multiplication of @p src1, @p src2 and @p scale |
| 149 | * |
| 150 | * @param[in] src1 First tensor. |
| 151 | * @param[in] src2 Second tensor. |
| 152 | * @param[out] dst Result tensor. |
| 153 | * @param[in] scale A non-negative float multiplied to each product. |
| 154 | * @param[in] convert_policy Overflow policy. |
| 155 | * @param[in] rounding_policy Rounding policy. |
| 156 | */ |
| 157 | static void pixel_wise_multiplication(const RawTensor &src1, const RawTensor &src2, RawTensor &dst, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); |
| 158 | /** Fixed-point Pixel-wise multiplication of @p src1 by @p src2 |
| 159 | * |
| 160 | * @param[in] src1 First tensor. |
| 161 | * @param[in] src2 Second tensor. |
| 162 | * @param[out] dst Result tensor. |
| 163 | * @param[in] scale A non-negative float multiplied to each product. |
| 164 | * @param[in] convert_policy Overflow policy. |
| 165 | * @param[in] rounding_policy Rounding policy. |
| 166 | */ |
| 167 | static void fixed_point_pixel_wise_multiplication(const RawTensor &src1, const RawTensor &src2, RawTensor &dst, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); |
| 168 | /** Threshold of@p src to @p dst |
| 169 | * |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 170 | * @param[in] src Input tensor. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 171 | * @param[out] dst Result tensor. |
| 172 | * @param[in] threshold Threshold. When the threhold type is RANGE, this is used as the lower threshold. |
| 173 | * @param[in] false_value value to set when the condition is not respected. |
| 174 | * @param[in] true_value value to set when the condition is respected. |
| 175 | * @param[in] type Thresholding type. Either RANGE or BINARY. |
| 176 | * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE. |
| 177 | */ |
| 178 | static void threshold(const RawTensor &src, RawTensor &dst, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper); |
Isabella Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame] | 179 | /** Warp perspective of@p src to @p dst |
| 180 | * |
| 181 | * @param[in] src First tensor. |
| 182 | * @param[out] dst Result tensor. |
| 183 | * @param[out] valid_mask Valid mask tensor. |
| 184 | * @param[in] matrix The perspective matrix. Must be 3x3 of type float. |
| 185 | * @param[in] policy The interpolation type. |
| 186 | * @param[in] border_mode Strategy to use for borders. |
| 187 | * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT. |
| 188 | */ |
| 189 | static void warp_perspective(const RawTensor &src, RawTensor &dst, RawTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value); |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 190 | /** ROI Pooling layer of @p src based on the information from @p pool_info and @p rois. |
| 191 | * |
| 192 | * @param[in] src Input tensor. |
| 193 | * @param[out] dst Result tensor. |
| 194 | * @param[in] rois Region of Interest points. |
| 195 | * @param[in] pool_info ROI Pooling Layer information. |
| 196 | */ |
| 197 | static void roi_pooling_layer(const RawTensor &src, RawTensor &dst, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 198 | /** Fixed point operations of @p src |
| 199 | * |
| 200 | * @param[in] src Input tensor. |
| 201 | * @param[out] dst Result tensor. |
| 202 | * @param[in] op Fixed point operation to perform. |
| 203 | */ |
| 204 | static void fixed_point_operation(const RawTensor &src, RawTensor &dst, FixedPointOp op); |
| 205 | |
| 206 | private: |
| 207 | ReferenceCPP() = delete; |
| 208 | ~ReferenceCPP() = delete; |
| 209 | }; |
| 210 | } // namespace validation |
| 211 | } // namespace test |
| 212 | } // namespace arm_compute |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 213 | #endif /* __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_CPP_H__ */ |