Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Ioan-Cristian Szabo | 91d20d9 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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_VALIDATE_H__ |
| 25 | #define __ARM_COMPUTE_VALIDATE_H__ |
| 26 | |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/HOGInfo.h" |
| 29 | #include "arm_compute/core/IKernel.h" |
| 30 | #include "arm_compute/core/IMultiHOG.h" |
| 31 | #include "arm_compute/core/IMultiImage.h" |
| 32 | #include "arm_compute/core/ITensor.h" |
| 33 | #include "arm_compute/core/MultiImageInfo.h" |
| 34 | #include "arm_compute/core/Window.h" |
| 35 | |
| 36 | #include <algorithm> |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace detail |
| 41 | { |
| 42 | /* Check whether two dimension objects differ. |
| 43 | * |
| 44 | * @param[in] dim1 First object to be compared. |
| 45 | * @param[in] dim2 Second object to be compared. |
| 46 | * @param[in] upper_dim The dimension from which to check. |
| 47 | * |
| 48 | * @return Return true if the two objects are different. |
| 49 | */ |
| 50 | template <typename T> |
| 51 | inline bool have_different_dimensions(const Dimensions<T> &dim1, const Dimensions<T> &dim2, unsigned int upper_dim) |
| 52 | { |
| 53 | for(unsigned int i = upper_dim; i < arm_compute::Dimensions<T>::num_max_dimensions; ++i) |
| 54 | { |
| 55 | if(dim1[i] != dim2[i]) |
| 56 | { |
| 57 | return true; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | /** Functor to compare two @ref Dimensions objects and throw an error on mismatch. |
| 65 | * |
| 66 | * @param[in] dim Object to compare against. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 67 | * @param[in] function Function in which the error occurred. |
| 68 | * @param[in] file File in which the error occurred. |
| 69 | * @param[in] line Line in which the error occurred. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | */ |
| 71 | template <typename T> |
| 72 | class compare_dimension |
| 73 | { |
| 74 | public: |
| 75 | compare_dimension(const Dimensions<T> &dim, const char *function, const char *file, int line) |
| 76 | : _dim{ dim }, _function{ function }, _file{ file }, _line{ line } |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | /** Compare the given object against the stored one. |
| 81 | * |
| 82 | * @param[in] dim To be compared object. |
| 83 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 84 | arm_compute::Status operator()(const Dimensions<T> &dim) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 86 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(have_different_dimensions(_dim, dim, 0), _function, _file, _line, |
| 87 | "Objects have different dimensions"); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 88 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | private: |
| 92 | const Dimensions<T> &_dim; |
| 93 | const char *const _function; |
| 94 | const char *const _file; |
| 95 | const int _line; |
| 96 | }; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 97 | |
| 98 | template <typename F> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 99 | inline arm_compute::Status for_each_error(F &&) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 100 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 101 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | template <typename F, typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 105 | inline arm_compute::Status for_each_error(F &&func, T &&arg, Ts &&... args) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 106 | { |
| 107 | ARM_COMPUTE_RETURN_ON_ERROR(func(arg)); |
| 108 | ARM_COMPUTE_RETURN_ON_ERROR(for_each_error(func, args...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 109 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | template <typename T> |
| 113 | struct get_tensor_info_t; |
| 114 | template <> |
| 115 | struct get_tensor_info_t<ITensorInfo *> |
| 116 | { |
| 117 | ITensorInfo *operator()(const ITensor *tensor) |
| 118 | { |
| 119 | return tensor->info(); |
| 120 | } |
| 121 | }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 122 | } // namespace detail |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 123 | |
| 124 | /** Create an error if one of the pointers is a nullptr. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 125 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 126 | * @param[in] function Function in which the error occurred. |
| 127 | * @param[in] file Name of the file where the error occurred. |
| 128 | * @param[in] line Line on which the error occurred. |
| 129 | * @param[in] pointers Pointers to check against nullptr. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 130 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 131 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 132 | */ |
| 133 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 134 | inline arm_compute::Status error_on_nullptr(const char *function, const char *file, const int line, Ts &&... pointers) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 136 | const std::array<const void *, sizeof...(Ts)> pointers_array{ { std::forward<Ts>(pointers)... } }; |
| 137 | bool has_nullptr = std::any_of(pointers_array.begin(), pointers_array.end(), [&](const void *ptr) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 138 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 139 | return (ptr == nullptr); |
| 140 | }); |
| 141 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(has_nullptr, function, file, line, "Nullptr object!"); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 142 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 143 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 144 | #define ARM_COMPUTE_ERROR_ON_NULLPTR(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 145 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_nullptr(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 146 | #define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...) \ |
| 147 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 148 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 149 | /** Return an error if the passed window is invalid. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 150 | * |
| 151 | * The subwindow is invalid if: |
| 152 | * - It is not a valid window. |
| 153 | * - Its dimensions don't match the full window's ones |
| 154 | * - The step for each of its dimension is not identical to the corresponding one of the full window. |
| 155 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 156 | * @param[in] function Function in which the error occurred. |
| 157 | * @param[in] file Name of the file where the error occurred. |
| 158 | * @param[in] line Line on which the error occurred. |
| 159 | * @param[in] full Full size window |
| 160 | * @param[in] win Window to validate. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 161 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 162 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 163 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 164 | arm_compute::Status error_on_mismatching_windows(const char *function, const char *file, const int line, |
| 165 | const Window &full, const Window &win); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 166 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 167 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_windows(__func__, __FILE__, __LINE__, f, w)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 168 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_WINDOWS(f, w) \ |
| 169 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_windows(__func__, __FILE__, __LINE__, f, w)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 170 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 171 | /** Return an error if the passed subwindow is invalid. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 172 | * |
| 173 | * The subwindow is invalid if: |
| 174 | * - It is not a valid window. |
| 175 | * - It is not fully contained inside the full window |
| 176 | * - The step for each of its dimension is not identical to the corresponding one of the full window. |
| 177 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 178 | * @param[in] function Function in which the error occurred. |
| 179 | * @param[in] file Name of the file where the error occurred. |
| 180 | * @param[in] line Line on which the error occurred. |
| 181 | * @param[in] full Full size window |
| 182 | * @param[in] sub Sub-window to validate. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 183 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 184 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 185 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 186 | arm_compute::Status error_on_invalid_subwindow(const char *function, const char *file, const int line, |
| 187 | const Window &full, const Window &sub); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 188 | #define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 189 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_invalid_subwindow(__func__, __FILE__, __LINE__, f, s)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 190 | #define ARM_COMPUTE_RETURN_ERROR_ON_INVALID_SUBWINDOW(f, s) \ |
| 191 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_invalid_subwindow(__func__, __FILE__, __LINE__, f, s)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 192 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 193 | /** Return an error if the window can't be collapsed at the given dimension. |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 194 | * |
| 195 | * The window cannot be collapsed if the given dimension not equal to the full window's dimension or not start from 0. |
| 196 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 197 | * @param[in] function Function in which the error occurred. |
| 198 | * @param[in] file Name of the file where the error occurred. |
| 199 | * @param[in] line Line on which the error occurred. |
| 200 | * @param[in] full Full size window |
| 201 | * @param[in] window Window to be collapsed. |
| 202 | * @param[in] dim Dimension need to be checked. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 203 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 204 | * @return Status |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 205 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 206 | arm_compute::Status error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line, |
| 207 | const Window &full, const Window &window, const int dim); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 208 | #define ARM_COMPUTE_ERROR_ON_WINDOW_NOT_COLLAPSABLE_AT_DIMENSION(f, w, d) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 209 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_window_not_collapsable_at_dimension(__func__, __FILE__, __LINE__, f, w, d)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 210 | #define ARM_COMPUTE_RETURN_ERROR_ON_WINDOW_NOT_COLLAPSABLE_AT_DIMENSION(f, w, d) \ |
| 211 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_window_not_collapsable_at_dimension(__func__, __FILE__, __LINE__, f, w, d)) |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 212 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 213 | /** Return an error if the passed coordinates have too many dimensions. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 214 | * |
| 215 | * The coordinates have too many dimensions if any of the dimensions greater or equal to max_dim is different from 0. |
| 216 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 217 | * @param[in] function Function in which the error occurred. |
| 218 | * @param[in] file Name of the file where the error occurred. |
| 219 | * @param[in] line Line on which the error occurred. |
| 220 | * @param[in] pos Coordinates to validate |
| 221 | * @param[in] max_dim Maximum number of dimensions allowed. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 222 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 223 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 224 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 225 | arm_compute::Status error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line, |
| 226 | const Coordinates &pos, unsigned int max_dim); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 227 | #define ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE(p, md) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 228 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_coordinates_dimensions_gte(__func__, __FILE__, __LINE__, p, md)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 229 | #define ARM_COMPUTE_RETURN_ERROR_ON_COORDINATES_DIMENSIONS_GTE(p, md) \ |
| 230 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_coordinates_dimensions_gte(__func__, __FILE__, __LINE__, p, md)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 231 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 232 | /** Return an error if the passed window has too many dimensions. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 233 | * |
| 234 | * The window has too many dimensions if any of the dimension greater or equal to max_dim is different from 0. |
| 235 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 236 | * @param[in] function Function in which the error occurred. |
| 237 | * @param[in] file Name of the file where the error occurred. |
| 238 | * @param[in] line Line on which the error occurred. |
| 239 | * @param[in] win Window to validate |
| 240 | * @param[in] max_dim Maximum number of dimensions allowed. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 241 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 242 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 243 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 244 | arm_compute::Status error_on_window_dimensions_gte(const char *function, const char *file, const int line, |
| 245 | const Window &win, unsigned int max_dim); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 246 | #define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 247 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_window_dimensions_gte(__func__, __FILE__, __LINE__, w, md)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 248 | #define ARM_COMPUTE_RETURN_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md) \ |
| 249 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_window_dimensions_gte(__func__, __FILE__, __LINE__, w, md)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 250 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 251 | /** Return an error if the passed dimension objects differ. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 252 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 253 | * @param[in] function Function in which the error occurred. |
| 254 | * @param[in] file Name of the file where the error occurred. |
| 255 | * @param[in] line Line on which the error occurred. |
| 256 | * @param[in] dim1 The first object to be compared. |
| 257 | * @param[in] dim2 The second object to be compared. |
| 258 | * @param[in] dims (Optional) Further allowed objects. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 259 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 260 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 261 | */ |
| 262 | template <typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 263 | arm_compute::Status error_on_mismatching_dimensions(const char *function, const char *file, int line, |
| 264 | const Dimensions<T> &dim1, const Dimensions<T> &dim2, Ts &&... dims) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 265 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 266 | ARM_COMPUTE_RETURN_ON_ERROR(detail::for_each_error(detail::compare_dimension<T>(dim1, function, file, line), dim2, std::forward<Ts>(dims)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 267 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 268 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 269 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 270 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_dimensions(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 271 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...) \ |
| 272 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_dimensions(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 273 | |
Ioan-Cristian Szabo | 9414f64 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 274 | /** Return an error if the passed tensor objects are not even. |
| 275 | * |
| 276 | * @param[in] function Function in which the error occurred. |
| 277 | * @param[in] file Name of the file where the error occurred. |
| 278 | * @param[in] line Line on which the error occurred. |
| 279 | * @param[in] format Format to check if odd shape is allowed |
| 280 | * @param[in] tensor1 The first object to be compared for odd shape. |
| 281 | * @param[in] tensors (Optional) Further allowed objects. |
| 282 | * |
| 283 | * @return Status |
| 284 | */ |
| 285 | template <typename... Ts> |
| 286 | arm_compute::Status error_on_tensors_not_even(const char *function, const char *file, int line, |
| 287 | const Format &format, const ITensor *tensor1, Ts... tensors) |
| 288 | { |
| 289 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor1 == nullptr, function, file, line); |
| 290 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensors)...)); |
| 291 | const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_info_array{ { tensor1, std::forward<Ts>(tensors)... } }; |
| 292 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensors_info_array.cbegin(), tensors_info_array.cend(), [&](const ITensor * tensor) |
| 293 | { |
| 294 | const TensorShape correct_shape = adjust_odd_shape(tensor->info()->tensor_shape(), format); |
| 295 | return detail::have_different_dimensions(tensor->info()->tensor_shape(), correct_shape, 2); |
| 296 | }), |
| 297 | function, file, line, "Tensor shape has odd dimensions"); |
| 298 | return arm_compute::Status{}; |
| 299 | } |
| 300 | |
| 301 | #define ARM_COMPUTE_ERROR_ON_TENSORS_NOT_EVEN(...) \ |
| 302 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_tensors_not_even(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 303 | #define ARM_COMPUTE_RETURN_ERROR_ON_TENSORS_NOT_EVEN(...) \ |
| 304 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_tensors_not_even(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 305 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 306 | /** Return an error if the passed two tensor infos have different shapes from the given dimension |
| 307 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 308 | * @param[in] function Function in which the error occurred. |
| 309 | * @param[in] file Name of the file where the error occurred. |
| 310 | * @param[in] line Line on which the error occurred. |
| 311 | * @param[in] tensor_info_1 The first tensor info to be compared. |
| 312 | * @param[in] tensor_info_2 The second tensor info to be compared. |
| 313 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 314 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 315 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 316 | */ |
| 317 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 318 | inline arm_compute::Status error_on_mismatching_shapes(const char *function, const char *file, const int line, |
| 319 | const ITensorInfo *tensor_info_1, const ITensorInfo *tensor_info_2, Ts... tensor_infos) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 320 | { |
| 321 | return error_on_mismatching_shapes(function, file, line, 0U, tensor_info_1, tensor_info_2, std::forward<Ts>(tensor_infos)...); |
| 322 | } |
| 323 | /** Return an error if the passed two tensors have different shapes from the given dimension |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 324 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 325 | * @param[in] function Function in which the error occurred. |
| 326 | * @param[in] file Name of the file where the error occurred. |
| 327 | * @param[in] line Line on which the error occurred. |
| 328 | * @param[in] tensor_1 The first tensor to be compared. |
| 329 | * @param[in] tensor_2 The second tensor to be compared. |
| 330 | * @param[in] tensors (Optional) Further allowed tensors. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 331 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 332 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 333 | */ |
| 334 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 335 | inline arm_compute::Status error_on_mismatching_shapes(const char *function, const char *file, const int line, |
| 336 | const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 337 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 338 | return error_on_mismatching_shapes(function, file, line, 0U, tensor_1, tensor_2, std::forward<Ts>(tensors)...); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 339 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 340 | /** Return an error if the passed two tensors have different shapes from the given dimension |
| 341 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 342 | * @param[in] function Function in which the error occurred. |
| 343 | * @param[in] file Name of the file where the error occurred. |
| 344 | * @param[in] line Line on which the error occurred. |
| 345 | * @param[in] upper_dim The dimension from which to check. |
| 346 | * @param[in] tensor_info_1 The first tensor info to be compared. |
| 347 | * @param[in] tensor_info_2 The second tensor info to be compared. |
| 348 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 349 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 350 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 351 | */ |
| 352 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 353 | inline arm_compute::Status error_on_mismatching_shapes(const char *function, const char *file, const int line, |
| 354 | unsigned int upper_dim, const ITensorInfo *tensor_info_1, const ITensorInfo *tensor_info_2, Ts... tensor_infos) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 355 | { |
| 356 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info_1 == nullptr, function, file, line); |
| 357 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info_2 == nullptr, function, file, line); |
| 358 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensor_infos)...)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 359 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 360 | const std::array < const ITensorInfo *, 2 + sizeof...(Ts) > tensors_info_array{ { tensor_info_1, tensor_info_2, std::forward<Ts>(tensor_infos)... } }; |
| 361 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(std::next(tensors_info_array.cbegin()), tensors_info_array.cend(), [&](const ITensorInfo * tensor_info) |
| 362 | { |
| 363 | return detail::have_different_dimensions((*tensors_info_array.cbegin())->tensor_shape(), tensor_info->tensor_shape(), upper_dim); |
| 364 | }), |
| 365 | function, file, line, "Tensors have different shapes"); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 366 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 367 | } |
| 368 | /** Return an error if the passed two tensors have different shapes from the given dimension |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 369 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 370 | * @param[in] function Function in which the error occurred. |
| 371 | * @param[in] file Name of the file where the error occurred. |
| 372 | * @param[in] line Line on which the error occurred. |
| 373 | * @param[in] upper_dim The dimension from which to check. |
| 374 | * @param[in] tensor_1 The first tensor to be compared. |
| 375 | * @param[in] tensor_2 The second tensor to be compared. |
| 376 | * @param[in] tensors (Optional) Further allowed tensors. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 377 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 378 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 379 | */ |
| 380 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 381 | inline arm_compute::Status error_on_mismatching_shapes(const char *function, const char *file, const int line, |
| 382 | unsigned int upper_dim, const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 383 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 384 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_1 == nullptr, function, file, line); |
| 385 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_2 == nullptr, function, file, line); |
| 386 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensors)...)); |
| 387 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_shapes(function, file, line, upper_dim, tensor_1->info(), tensor_2->info(), |
| 388 | detail::get_tensor_info_t<ITensorInfo *>()(tensors)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 389 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 390 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 391 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 392 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_shapes(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 393 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...) \ |
| 394 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_shapes(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 395 | |
Michalis Spyrou | 7a56925 | 2018-03-01 12:03:14 +0000 | [diff] [blame] | 396 | /** Return an error if the passed tensor infos have different data layouts |
| 397 | * |
| 398 | * @param[in] function Function in which the error occurred. |
| 399 | * @param[in] file Name of the file where the error occurred. |
| 400 | * @param[in] line Line on which the error occurred. |
| 401 | * @param[in] tensor_info The first tensor info to be compared. |
| 402 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
| 403 | * |
| 404 | * @return Status |
| 405 | */ |
| 406 | template <typename... Ts> |
| 407 | inline arm_compute::Status error_on_mismatching_data_layouts(const char *function, const char *file, const int line, |
| 408 | const ITensorInfo *tensor_info, Ts... tensor_infos) |
| 409 | { |
| 410 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line); |
| 411 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensor_infos)...)); |
| 412 | |
| 413 | DataLayout &&tensor_data_layout = tensor_info->data_layout(); |
| 414 | const std::array<const ITensorInfo *, sizeof...(Ts)> tensors_infos_array{ { std::forward<Ts>(tensor_infos)... } }; |
| 415 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensors_infos_array.begin(), tensors_infos_array.end(), [&](const ITensorInfo * tensor_info_obj) |
| 416 | { |
| 417 | return tensor_info_obj->data_layout() != tensor_data_layout; |
| 418 | }), |
| 419 | function, file, line, "Tensors have different data layouts"); |
| 420 | return arm_compute::Status{}; |
| 421 | } |
| 422 | /** Return an error if the passed tensors have different data layouts |
| 423 | * |
| 424 | * @param[in] function Function in which the error occurred. |
| 425 | * @param[in] file Name of the file where the error occurred. |
| 426 | * @param[in] line Line on which the error occurred. |
| 427 | * @param[in] tensor The first tensor to be compared. |
| 428 | * @param[in] tensors (Optional) Further allowed tensors. |
| 429 | * |
| 430 | * @return Status |
| 431 | */ |
| 432 | template <typename... Ts> |
| 433 | inline arm_compute::Status error_on_mismatching_data_layouts(const char *function, const char *file, const int line, |
| 434 | const ITensor *tensor, Ts... tensors) |
| 435 | { |
| 436 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 437 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensors)...)); |
| 438 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_data_layouts(function, file, line, tensor->info(), |
| 439 | detail::get_tensor_info_t<ITensorInfo *>()(tensors)...)); |
| 440 | return arm_compute::Status{}; |
| 441 | } |
| 442 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_LAYOUT(...) \ |
| 443 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_data_layouts(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 444 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...) \ |
| 445 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_data_layouts(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 446 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 447 | /** Return an error if the passed two tensor infos have different data types |
| 448 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 449 | * @param[in] function Function in which the error occurred. |
| 450 | * @param[in] file Name of the file where the error occurred. |
| 451 | * @param[in] line Line on which the error occurred. |
| 452 | * @param[in] tensor_info The first tensor info to be compared. |
| 453 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 454 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 455 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 456 | */ |
| 457 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 458 | inline arm_compute::Status error_on_mismatching_data_types(const char *function, const char *file, const int line, |
| 459 | const ITensorInfo *tensor_info, Ts... tensor_infos) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 460 | { |
| 461 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line); |
| 462 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensor_infos)...)); |
| 463 | |
| 464 | DataType &&tensor_data_type = tensor_info->data_type(); |
| 465 | const std::array<const ITensorInfo *, sizeof...(Ts)> tensors_infos_array{ { std::forward<Ts>(tensor_infos)... } }; |
| 466 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensors_infos_array.begin(), tensors_infos_array.end(), [&](const ITensorInfo * tensor_info_obj) |
| 467 | { |
| 468 | return tensor_info_obj->data_type() != tensor_data_type; |
| 469 | }), |
| 470 | function, file, line, "Tensors have different data types"); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 471 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 472 | } |
| 473 | /** Return an error if the passed two tensors have different data types |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 474 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 475 | * @param[in] function Function in which the error occurred. |
| 476 | * @param[in] file Name of the file where the error occurred. |
| 477 | * @param[in] line Line on which the error occurred. |
| 478 | * @param[in] tensor The first tensor to be compared. |
| 479 | * @param[in] tensors (Optional) Further allowed tensors. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 480 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 481 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 482 | */ |
| 483 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 484 | inline arm_compute::Status error_on_mismatching_data_types(const char *function, const char *file, const int line, |
| 485 | const ITensor *tensor, Ts... tensors) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 486 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 487 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 488 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_nullptr(function, file, line, std::forward<Ts>(tensors)...)); |
| 489 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_data_types(function, file, line, tensor->info(), |
| 490 | detail::get_tensor_info_t<ITensorInfo *>()(tensors)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 491 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 492 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 493 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 494 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_data_types(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 495 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...) \ |
| 496 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_data_types(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 497 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 498 | /** Return an error if the passed tensor infos have different fixed point data types or different fixed point positions |
| 499 | * |
| 500 | * @note: If the first tensor doesn't have fixed point data type, the function returns without throwing an error |
| 501 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 502 | * @param[in] function Function in which the error occurred. |
| 503 | * @param[in] file Name of the file where the error occurred. |
| 504 | * @param[in] line Line on which the error occurred. |
| 505 | * @param[in] tensor_info_1 The first tensor info to be compared. |
| 506 | * @param[in] tensor_info_2 The second tensor info to be compared. |
| 507 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 508 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 509 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 510 | */ |
| 511 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 512 | inline arm_compute::Status error_on_mismatching_fixed_point(const char *function, const char *file, const int line, |
| 513 | const ITensorInfo *tensor_info_1, const ITensorInfo *tensor_info_2, Ts... tensor_infos) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 514 | { |
| 515 | DataType &&first_data_type = tensor_info_1->data_type(); |
| 516 | const int first_fixed_point_position = tensor_info_1->fixed_point_position(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 517 | |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 518 | if(!is_data_type_fixed_point(first_data_type)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 519 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 520 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | const std::array < const ITensorInfo *, 1 + sizeof...(Ts) > tensor_infos_array{ { tensor_info_2, std::forward<Ts>(tensor_infos)... } }; |
| 524 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensor_infos_array.begin(), tensor_infos_array.end(), [&](const ITensorInfo * tensor_info) |
| 525 | { |
| 526 | return tensor_info->data_type() != first_data_type; |
| 527 | }), |
| 528 | function, file, line, "Tensors have different fixed point data types"); |
| 529 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensor_infos_array.begin(), tensor_infos_array.end(), [&](const ITensorInfo * tensor_info) |
| 530 | { |
| 531 | return tensor_info->fixed_point_position() != first_fixed_point_position; |
| 532 | }), |
| 533 | function, file, line, "Tensors have different fixed point positions"); |
| 534 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 535 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 536 | } |
| 537 | /** Return an error if the passed tensor have different fixed point data types or different fixed point positions |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 538 | * |
| 539 | * @note: If the first tensor doesn't have fixed point data type, the function returns without throwing an error |
| 540 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 541 | * @param[in] function Function in which the error occurred. |
| 542 | * @param[in] file Name of the file where the error occurred. |
| 543 | * @param[in] line Line on which the error occurred. |
| 544 | * @param[in] tensor_1 The first tensor to be compared. |
| 545 | * @param[in] tensor_2 The second tensor to be compared. |
| 546 | * @param[in] tensors (Optional) Further allowed tensors. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 547 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 548 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 549 | */ |
| 550 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 551 | inline arm_compute::Status error_on_mismatching_fixed_point(const char *function, const char *file, const int line, |
| 552 | const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 553 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 554 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_fixed_point(function, file, line, tensor_1->info(), tensor_2->info(), |
| 555 | detail::get_tensor_info_t<ITensorInfo *>()(tensors)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 556 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 557 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 558 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 559 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 560 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT(...) \ |
| 561 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 562 | |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 563 | /** Return an error if the passed tensor infos have different asymmetric quantized data types or different quantization info |
| 564 | * |
| 565 | * @note: If the first tensor info doesn't have asymmetric quantized data type, the function returns without throwing an error |
| 566 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 567 | * @param[in] function Function in which the error occurred. |
| 568 | * @param[in] file Name of the file where the error occurred. |
| 569 | * @param[in] line Line on which the error occurred. |
| 570 | * @param[in] tensor_info_1 The first tensor info to be compared. |
| 571 | * @param[in] tensor_info_2 The second tensor info to be compared. |
| 572 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 573 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 574 | * @return Status |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 575 | */ |
| 576 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 577 | inline arm_compute::Status error_on_mismatching_quantization_info(const char *function, const char *file, const int line, |
| 578 | const ITensorInfo *tensor_info_1, const ITensorInfo *tensor_info_2, Ts... tensor_infos) |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 579 | { |
| 580 | DataType &&first_data_type = tensor_info_1->data_type(); |
| 581 | const QuantizationInfo first_quantization_info = tensor_info_1->quantization_info(); |
| 582 | |
| 583 | if(!is_data_type_quantized_asymmetric(first_data_type)) |
| 584 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 585 | return arm_compute::Status{}; |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | const std::array < const ITensorInfo *, 1 + sizeof...(Ts) > tensor_infos_array{ { tensor_info_2, std::forward<Ts>(tensor_infos)... } }; |
| 589 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensor_infos_array.begin(), tensor_infos_array.end(), [&](const ITensorInfo * tensor_info) |
| 590 | { |
| 591 | return tensor_info->data_type() != first_data_type; |
| 592 | }), |
| 593 | function, file, line, "Tensors have different asymmetric quantized data types"); |
| 594 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensor_infos_array.begin(), tensor_infos_array.end(), [&](const ITensorInfo * tensor_info) |
| 595 | { |
| 596 | return tensor_info->quantization_info() != first_quantization_info; |
| 597 | }), |
| 598 | function, file, line, "Tensors have different quantization information"); |
| 599 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 600 | return arm_compute::Status{}; |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 601 | } |
| 602 | /** Return an error if the passed tensor have different asymmetric quantized data types or different quantization info |
| 603 | * |
| 604 | * @note: If the first tensor doesn't have asymmetric quantized data type, the function returns without throwing an error |
| 605 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 606 | * @param[in] function Function in which the error occurred. |
| 607 | * @param[in] file Name of the file where the error occurred. |
| 608 | * @param[in] line Line on which the error occurred. |
| 609 | * @param[in] tensor_1 The first tensor to be compared. |
| 610 | * @param[in] tensor_2 The second tensor to be compared. |
| 611 | * @param[in] tensors (Optional) Further allowed tensors. |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 612 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 613 | * @return Status |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 614 | */ |
| 615 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 616 | inline arm_compute::Status error_on_mismatching_quantization_info(const char *function, const char *file, const int line, |
| 617 | const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors) |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 618 | { |
| 619 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_quantization_info(function, file, line, tensor_1->info(), tensor_2->info(), |
| 620 | detail::get_tensor_info_t<ITensorInfo *>()(tensors)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 621 | return arm_compute::Status{}; |
Daniil Efremov | eed841c | 2017-11-09 19:05:25 +0700 | [diff] [blame] | 622 | } |
| 623 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...) \ |
| 624 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_quantization_info(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 625 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...) \ |
| 626 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_quantization_info(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 627 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 628 | /** Throw an error if the format of the passed tensor/multi-image does not match any of the formats provided. |
| 629 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 630 | * @param[in] function Function in which the error occurred. |
| 631 | * @param[in] file Name of the file where the error occurred. |
| 632 | * @param[in] line Line on which the error occurred. |
| 633 | * @param[in] object Tensor/multi-image to validate. |
| 634 | * @param[in] format First format allowed. |
| 635 | * @param[in] formats (Optional) Further allowed formats. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 636 | */ |
| 637 | template <typename T, typename F, typename... Fs> |
| 638 | void error_on_format_not_in(const char *function, const char *file, const int line, |
| 639 | const T *object, F &&format, Fs &&... formats) |
| 640 | { |
| 641 | ARM_COMPUTE_ERROR_ON_LOC(object == nullptr, function, file, line); |
| 642 | |
| 643 | Format &&object_format = object->info()->format(); |
| 644 | ARM_COMPUTE_UNUSED(object_format); |
| 645 | |
| 646 | ARM_COMPUTE_ERROR_ON_LOC(object_format == Format::UNKNOWN, function, file, line); |
| 647 | |
| 648 | const std::array<F, sizeof...(Fs)> formats_array{ { std::forward<Fs>(formats)... } }; |
| 649 | ARM_COMPUTE_UNUSED(formats_array); |
| 650 | |
| 651 | ARM_COMPUTE_ERROR_ON_LOC_MSG(object_format != format && std::none_of(formats_array.begin(), formats_array.end(), [&](const F & f) |
| 652 | { |
| 653 | return f == object_format; |
| 654 | }), |
| 655 | function, file, line, "Format %s not supported by this kernel", string_from_format(object_format).c_str()); |
| 656 | } |
| 657 | #define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t, ...) ::arm_compute::error_on_format_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__) |
| 658 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 659 | /** Return an error if the data type of the passed tensor info does not match any of the data types provided. |
| 660 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 661 | * @param[in] function Function in which the error occurred. |
| 662 | * @param[in] file Name of the file where the error occurred. |
| 663 | * @param[in] line Line on which the error occurred. |
| 664 | * @param[in] tensor_info Tensor info to validate. |
| 665 | * @param[in] dt First data type allowed. |
| 666 | * @param[in] dts (Optional) Further allowed data types. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 667 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 668 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 669 | */ |
| 670 | template <typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 671 | inline arm_compute::Status error_on_data_type_not_in(const char *function, const char *file, const int line, |
| 672 | const ITensorInfo *tensor_info, T &&dt, Ts &&... dts) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 673 | { |
| 674 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line); |
| 675 | |
| 676 | const DataType &tensor_dt = tensor_info->data_type(); //NOLINT |
| 677 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_dt == DataType::UNKNOWN, function, file, line); |
| 678 | |
| 679 | const std::array<T, sizeof...(Ts)> dts_array{ { std::forward<Ts>(dts)... } }; |
| 680 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(tensor_dt != dt && std::none_of(dts_array.begin(), dts_array.end(), [&](const T & d) |
| 681 | { |
| 682 | return d == tensor_dt; |
| 683 | }), |
| 684 | function, file, line, "ITensor data type %s not supported by this kernel", string_from_data_type(tensor_dt).c_str()); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 685 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 686 | } |
| 687 | /** Return an error if the data type of the passed tensor does not match any of the data types provided. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 688 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 689 | * @param[in] function Function in which the error occurred. |
| 690 | * @param[in] file Name of the file where the error occurred. |
| 691 | * @param[in] line Line on which the error occurred. |
| 692 | * @param[in] tensor Tensor to validate. |
| 693 | * @param[in] dt First data type allowed. |
| 694 | * @param[in] dts (Optional) Further allowed data types. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 695 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 696 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 697 | */ |
| 698 | template <typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 699 | inline arm_compute::Status error_on_data_type_not_in(const char *function, const char *file, const int line, |
| 700 | const ITensor *tensor, T &&dt, Ts &&... dts) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 701 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 702 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 703 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_data_type_not_in(function, file, line, tensor->info(), std::forward<T>(dt), std::forward<Ts>(dts)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 704 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 705 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 706 | #define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t, ...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 707 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_data_type_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 708 | #define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(t, ...) \ |
| 709 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_data_type_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 710 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 711 | /** Return an error if the data type or the number of channels of the passed tensor info does not match any of the data types and number of channels provided. |
| 712 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 713 | * @param[in] function Function in which the error occurred. |
| 714 | * @param[in] file Name of the file where the error occurred. |
| 715 | * @param[in] line Line on which the error occurred. |
| 716 | * @param[in] tensor_info Tensor info to validate. |
| 717 | * @param[in] num_channels Number of channels to check |
| 718 | * @param[in] dt First data type allowed. |
| 719 | * @param[in] dts (Optional) Further allowed data types. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 720 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 721 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 722 | */ |
| 723 | template <typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 724 | inline arm_compute::Status error_on_data_type_channel_not_in(const char *function, const char *file, const int line, |
| 725 | const ITensorInfo *tensor_info, size_t num_channels, T &&dt, Ts &&... dts) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 726 | { |
| 727 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_data_type_not_in(function, file, line, tensor_info, std::forward<T>(dt), std::forward<Ts>(dts)...)); |
| 728 | const size_t tensor_nc = tensor_info->num_channels(); |
| 729 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(tensor_nc != num_channels, function, file, line, "Number of channels %d. Required number of channels %d", tensor_nc, num_channels); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 730 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 731 | } |
| 732 | /** Return an error if the data type or the number of channels of the passed tensor does not match any of the data types and number of channels provided. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 733 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 734 | * @param[in] function Function in which the error occurred. |
| 735 | * @param[in] file Name of the file where the error occurred. |
| 736 | * @param[in] line Line on which the error occurred. |
| 737 | * @param[in] tensor Tensor to validate. |
| 738 | * @param[in] num_channels Number of channels to check |
| 739 | * @param[in] dt First data type allowed. |
| 740 | * @param[in] dts (Optional) Further allowed data types. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 741 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 742 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 743 | */ |
| 744 | template <typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 745 | inline arm_compute::Status error_on_data_type_channel_not_in(const char *function, const char *file, const int line, |
| 746 | const ITensor *tensor, size_t num_channels, T &&dt, Ts &&... dts) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 747 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 748 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 749 | ARM_COMPUTE_RETURN_ON_ERROR(error_on_data_type_channel_not_in(function, file, line, tensor->info(), num_channels, std::forward<T>(dt), std::forward<Ts>(dts)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 750 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 751 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 752 | #define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c, ...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 753 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_data_type_channel_not_in(__func__, __FILE__, __LINE__, t, c, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 754 | #define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c, ...) \ |
| 755 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_data_type_channel_not_in(__func__, __FILE__, __LINE__, t, c, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 756 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 757 | /** Return an error if the tensor is not 2D. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 758 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 759 | * @param[in] function Function in which the error occurred. |
| 760 | * @param[in] file Name of the file where the error occurred. |
| 761 | * @param[in] line Line on which the error occurred. |
| 762 | * @param[in] tensor Tensor to validate. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 763 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 764 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 765 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 766 | arm_compute::Status error_on_tensor_not_2d(const char *function, const char *file, const int line, |
| 767 | const ITensor *tensor); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 768 | #define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 769 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_tensor_not_2d(__func__, __FILE__, __LINE__, t)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 770 | #define ARM_COMPUTE_RETURN_ERROR_ON_TENSOR_NOT_2D(t) \ |
| 771 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_tensor_not_2d(__func__, __FILE__, __LINE__, t)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 772 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 773 | /** Return an error if the channel is not in channels. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 774 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 775 | * @param[in] function Function in which the error occurred. |
| 776 | * @param[in] file Name of the file where the error occurred. |
| 777 | * @param[in] line Line on which the error occurred. |
| 778 | * @param[in] cn Input channel |
| 779 | * @param[in] channel First channel allowed. |
| 780 | * @param[in] channels (Optional) Further allowed channels. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 781 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 782 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 783 | */ |
| 784 | template <typename T, typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 785 | inline arm_compute::Status error_on_channel_not_in(const char *function, const char *file, const int line, |
| 786 | T cn, T &&channel, Ts &&... channels) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 787 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 788 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(cn == Channel::UNKNOWN, function, file, line); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 789 | |
| 790 | const std::array<T, sizeof...(Ts)> channels_array{ { std::forward<Ts>(channels)... } }; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 791 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(channel != cn && std::none_of(channels_array.begin(), channels_array.end(), [&](const T & f) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 792 | { |
| 793 | return f == cn; |
| 794 | }), |
| 795 | function, file, line); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 796 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 797 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 798 | #define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN(c, ...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 799 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_channel_not_in(__func__, __FILE__, __LINE__, c, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 800 | #define ARM_COMPUTE_RETURN_ERROR_ON_CHANNEL_NOT_IN(c, ...) \ |
| 801 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_channel_not_in(__func__, __FILE__, __LINE__, c, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 802 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 803 | /** Return an error if the channel is not in format. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 804 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 805 | * @param[in] function Function in which the error occurred. |
| 806 | * @param[in] file Name of the file where the error occurred. |
| 807 | * @param[in] line Line on which the error occurred. |
| 808 | * @param[in] fmt Input channel |
| 809 | * @param[in] cn First channel allowed. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 810 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 811 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 812 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 813 | arm_compute::Status error_on_channel_not_in_known_format(const char *function, const char *file, const int line, |
| 814 | Format fmt, Channel cn); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 815 | #define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(f, c) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 816 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_channel_not_in_known_format(__func__, __FILE__, __LINE__, f, c)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 817 | #define ARM_COMPUTE_RETURN_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(f, c) \ |
| 818 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_channel_not_in_known_format(__func__, __FILE__, __LINE__, f, c)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 819 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 820 | /** Return an error if the @ref IMultiHOG container is invalid |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 821 | * |
| 822 | * An @ref IMultiHOG container is invalid if: |
| 823 | * |
| 824 | * -# it is a nullptr |
| 825 | * -# it doesn't contain models |
| 826 | * -# it doesn't have the HOG data objects with the same phase_type, normalization_type and l2_hyst_threshold (if normalization_type == L2HYS_NORM) |
| 827 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 828 | * @param[in] function Function in which the error occurred. |
| 829 | * @param[in] file Name of the file where the error occurred. |
| 830 | * @param[in] line Line on which the error occurred. |
| 831 | * @param[in] multi_hog IMultiHOG container to validate |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 832 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 833 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 834 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 835 | arm_compute::Status error_on_invalid_multi_hog(const char *function, const char *file, const int line, |
| 836 | const IMultiHOG *multi_hog); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 837 | #define ARM_COMPUTE_ERROR_ON_INVALID_MULTI_HOG(m) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 838 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_invalid_multi_hog(__func__, __FILE__, __LINE__, m)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 839 | #define ARM_COMPUTE_RETURN_ERROR_ON_INVALID_MULTI_HOG(m) \ |
| 840 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_invalid_multi_hog(__func__, __FILE__, __LINE__, m)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 841 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 842 | /** Return an error if the kernel is not configured. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 843 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 844 | * @param[in] function Function in which the error occurred. |
| 845 | * @param[in] file Name of the file where the error occurred. |
| 846 | * @param[in] line Line on which the error occurred. |
| 847 | * @param[in] kernel Kernel to validate. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 848 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 849 | arm_compute::Status error_on_unconfigured_kernel(const char *function, const char *file, const int line, |
| 850 | const IKernel *kernel); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 851 | #define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 852 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_unconfigured_kernel(__func__, __FILE__, __LINE__, k)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 853 | #define ARM_COMPUTE_RETURN_ERROR_ON_UNCONFIGURED_KERNEL(k) \ |
| 854 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unconfigured_kernel(__func__, __FILE__, __LINE__, k)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 855 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 856 | /** Return an error if if the coordinates and shape of the subtensor are within the parent tensor. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 857 | * |
| 858 | * @param[in] function Function in which the error occurred. |
| 859 | * @param[in] file Name of the file where the error occurred. |
| 860 | * @param[in] line Line on which the error occurred. |
| 861 | * @param[in] parent_shape Parent tensor shape |
| 862 | * @param[in] coords Coordinates inside the parent tensor where the first element of the subtensor is |
| 863 | * @param[in] shape Shape of the subtensor |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 864 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 865 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 866 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 867 | arm_compute::Status error_on_invalid_subtensor(const char *function, const char *file, const int line, |
| 868 | const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 869 | #define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(p, c, s) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 870 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, p, c, s)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 871 | #define ARM_COMPUTE_RETURN_ERROR_ON_INVALID_SUBTENSOR(p, c, s) \ |
| 872 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, p, c, s)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 873 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 874 | /** Return an error if the valid region of a subtensor is not inside the valid region of the parent tensor. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 875 | * |
| 876 | * @param[in] function Function in which the error occurred. |
| 877 | * @param[in] file Name of the file where the error occurred. |
| 878 | * @param[in] line Line on which the error occurred. |
| 879 | * @param[in] parent_valid_region Parent valid region. |
| 880 | * @param[in] valid_region Valid region of subtensor. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 881 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 882 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 883 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 884 | arm_compute::Status error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line, |
| 885 | const ValidRegion &parent_valid_region, const ValidRegion &valid_region); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 886 | #define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(pv, sv) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 887 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_invalid_subtensor_valid_region(__func__, __FILE__, __LINE__, pv, sv)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 888 | #define ARM_COMPUTE_RETURN_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(pv, sv) \ |
| 889 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_invalid_subtensor_valid_region(__func__, __FILE__, __LINE__, pv, sv)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 890 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 891 | /** Return an error if the input fixed-point positions are different. |
| 892 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 893 | * @param[in] function Function in which the error occurred. |
| 894 | * @param[in] file Name of the file where the error occurred. |
| 895 | * @param[in] line Line on which the error occurred. |
| 896 | * @param[in] tensor_info_1 The first tensor info to be compared. |
| 897 | * @param[in] tensor_info_2 The second tensor info to be compared. |
| 898 | * @param[in] tensor_infos (Optional) Further allowed tensor infos. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 899 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 900 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 901 | */ |
| 902 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 903 | inline arm_compute::Status error_on_mismatching_fixed_point_position(const char *function, const char *file, const int line, |
| 904 | const ITensorInfo *tensor_info_1, const ITensorInfo *tensor_info_2, Ts... tensor_infos) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 905 | { |
| 906 | const std::array < const ITensorInfo *, 1 + sizeof...(Ts) > tensor_info_array{ { tensor_info_2, std::forward<Ts>(tensor_infos)... } }; |
| 907 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(std::any_of(tensor_info_array.begin(), tensor_info_array.end(), [&](const ITensorInfo * tensor_info) |
| 908 | { |
| 909 | return tensor_info->fixed_point_position() != tensor_info_1->fixed_point_position(); |
| 910 | }), |
| 911 | function, file, line, "Tensors have different fixed-point positions"); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 912 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 913 | } |
| 914 | /** Return an error if the input fixed-point positions are different. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 915 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 916 | * @param[in] function Function in which the error occurred. |
| 917 | * @param[in] file Name of the file where the error occurred. |
| 918 | * @param[in] line Line on which the error occurred. |
| 919 | * @param[in] tensor_1 The first tensor to be compared. |
| 920 | * @param[in] tensor_2 The second tensor to be compared. |
| 921 | * @param[in] tensors (Optional) Further allowed tensors. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 922 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 923 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 924 | */ |
| 925 | template <typename... Ts> |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 926 | inline arm_compute::Status error_on_mismatching_fixed_point_position(const char *function, const char *file, const int line, |
| 927 | const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 928 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 929 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_fixed_point_position(function, file, line, tensor_1->info(), tensor_2->info(), |
| 930 | detail::get_tensor_info_t<ITensorInfo *>()(tensors)...)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 931 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 932 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 933 | #define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 934 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_mismatching_fixed_point_position(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 935 | #define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(...) \ |
| 936 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_mismatching_fixed_point_position(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 937 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 938 | /** Return an error if the fixed-point value is not representable in the specified Q format. |
| 939 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 940 | * @param[in] function Function in which the error occurred. |
| 941 | * @param[in] file Name of the file where the error occurred. |
| 942 | * @param[in] line Line on which the error occurred. |
| 943 | * @param[in] value The floating point value to be checked. |
| 944 | * @param[in] tensor_info Input tensor info that has information on data type and fixed-point position. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 945 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 946 | * @return Status |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 947 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 948 | inline arm_compute::Status error_on_value_not_representable_in_fixed_point(const char *function, const char *file, int line, |
| 949 | float value, const ITensorInfo *tensor_info) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 950 | { |
| 951 | const int fixed_point_position = tensor_info->fixed_point_position(); |
| 952 | const DataType dt = tensor_info->data_type(); |
| 953 | const unsigned int q_max_range = 0xFFFFFFFFu >> (((sizeof(unsigned int) - element_size_from_data_type(dt)) * 8) + 1); |
| 954 | const float max_range = q_max_range / (static_cast<float>(1 << fixed_point_position)); |
| 955 | |
| 956 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(value > max_range, function, file, line, |
| 957 | "Value %f is not representable in %s with fixed-point position %d", value, string_from_data_type(dt).c_str(), fixed_point_position); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 958 | return arm_compute::Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 959 | } |
| 960 | /** Return an error an error if the fixed-point value is not representable in the specified Q format. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 961 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 962 | * @param[in] function Function in which the error occurred. |
| 963 | * @param[in] file Name of the file where the error occurred. |
| 964 | * @param[in] line Line on which the error occurred. |
| 965 | * @param[in] value The floating point value to be checked. |
| 966 | * @param[in] tensor Input tensor that has information on data type and fixed-point position. |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 967 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 968 | * @return Status |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 969 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 970 | inline arm_compute::Status error_on_value_not_representable_in_fixed_point(const char *function, const char *file, int line, |
| 971 | float value, const ITensor *tensor) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 972 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 973 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 974 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_value_not_representable_in_fixed_point(function, file, line, value, tensor->info())); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 975 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 976 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 977 | #define ARM_COMPUTE_ERROR_ON_VALUE_NOT_REPRESENTABLE_IN_FIXED_POINT(...) \ |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 978 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_value_not_representable_in_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 979 | #define ARM_COMPUTE_RETURN_ERROR_ON_VALUE_NOT_REPRESENTABLE_IN_FIXED_POINT(...) \ |
| 980 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_value_not_representable_in_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 981 | } |
| 982 | #endif /* __ARM_COMPUTE_VALIDATE_H__*/ |