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