blob: dd71f2c714d0dceb13696964b0aedbd0d6f78141 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_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
38namespace arm_compute
39{
40namespace 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 */
50template <typename T>
51inline 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.
67 * @param[in] function Function in which the error occured.
68 * @param[in] file File in which the error occured.
69 * @param[in] line Line in which the error occured.
70 */
71template <typename T>
72class compare_dimension
73{
74public:
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 */
84 void operator()(const Dimensions<T> &dim)
85 {
86 ARM_COMPUTE_ERROR_ON_LOC_MSG(have_different_dimensions(_dim, dim, 0), _function, _file, _line,
87 "Objects have different dimensions");
88 }
89
90private:
91 const Dimensions<T> &_dim;
92 const char *const _function;
93 const char *const _file;
94 const int _line;
95};
96} // namespace detail
97/** Throw an error if one of the pointers is a nullptr.
98 *
99 * @param[in] function Function in which the error occurred.
100 * @param[in] file Name of the file where the error occurred.
101 * @param[in] line Line on which the error occurred.
102 * @param[in] pointers Pointers to check against nullptr.
103 */
104template <typename... Ts>
105void error_on_nullptr(const char *function, const char *file, const int line, Ts &&... pointers)
106{
107 auto is_nullptr = [&](const void *ptr)
108 {
109 ARM_COMPUTE_ERROR_ON_LOC(ptr == nullptr, function, file, line);
110 };
111
112 for_each(is_nullptr, std::forward<Ts>(pointers)...);
113}
114#define ARM_COMPUTE_ERROR_ON_NULLPTR(...) ::arm_compute::error_on_nullptr(__func__, __FILE__, __LINE__, __VA_ARGS__)
115
116/** Throw an error if the passed window is invalid.
117 *
118 * The subwindow is invalid if:
119 * - It is not a valid window.
120 * - Its dimensions don't match the full window's ones
121 * - The step for each of its dimension is not identical to the corresponding one of the full window.
122 *
123 * @param[in] function Function in which the error occurred.
124 * @param[in] file Name of the file where the error occurred.
125 * @param[in] line Line on which the error occurred.
126 * @param[in] full Full size window
127 * @param[in] win Window to validate.
128 */
129void error_on_mismatching_windows(const char *function, const char *file, const int line,
130 const Window &full, const Window &win);
131#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w) ::arm_compute::error_on_mismatching_windows(__func__, __FILE__, __LINE__, f, w)
132
133/** Throw an error if the passed subwindow is invalid.
134 *
135 * The subwindow is invalid if:
136 * - It is not a valid window.
137 * - It is not fully contained inside the full window
138 * - The step for each of its dimension is not identical to the corresponding one of the full window.
139 *
140 * @param[in] function Function in which the error occurred.
141 * @param[in] file Name of the file where the error occurred.
142 * @param[in] line Line on which the error occurred.
143 * @param[in] full Full size window
144 * @param[in] sub Sub-window to validate.
145 */
146void error_on_invalid_subwindow(const char *function, const char *file, const int line,
147 const Window &full, const Window &sub);
148#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s) ::arm_compute::error_on_invalid_subwindow(__func__, __FILE__, __LINE__, f, s)
149
150/** Throw an error if the passed coordinates have too many dimensions.
151 *
152 * The coordinates have too many dimensions if any of the dimensions greater or equal to max_dim is different from 0.
153 *
154 * @param[in] function Function in which the error occurred.
155 * @param[in] file Name of the file where the error occurred.
156 * @param[in] line Line on which the error occurred.
157 * @param[in] pos Coordinates to validate
158 * @param[in] max_dim Maximum number of dimensions allowed.
159 */
160void error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
161 const Coordinates &pos, unsigned int max_dim);
162#define ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE(p, md) ::arm_compute::error_on_coordinates_dimensions_gte(__func__, __FILE__, __LINE__, p, md)
163
164/** Throw an error if the passed window has too many dimensions.
165 *
166 * The window has too many dimensions if any of the dimension greater or equal to max_dim is different from 0.
167 *
168 * @param[in] function Function in which the error occurred.
169 * @param[in] file Name of the file where the error occurred.
170 * @param[in] line Line on which the error occurred.
171 * @param[in] win Window to validate
172 * @param[in] max_dim Maximum number of dimensions allowed.
173 */
174void error_on_window_dimensions_gte(const char *function, const char *file, const int line,
175 const Window &win, unsigned int max_dim);
176#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md) ::arm_compute::error_on_window_dimensions_gte(__func__, __FILE__, __LINE__, w, md)
177
178/** Throw an error if the passed dimension objects differ.
179 *
180 * @param[in] function Function in which the error occurred.
181 * @param[in] file Name of the file where the error occurred.
182 * @param[in] line Line on which the error occurred.
183 * @param[in] dim1 The first object to be compared.
184 * @param[in] dim2 The second object to be compared.
185 * @param[in] dims (Optional) Further allowed objects.
186 */
187template <typename T, typename... Ts>
188void error_on_mismatching_dimensions(const char *function, const char *file, int line,
189 const Dimensions<T> &dim1, const Dimensions<T> &dim2, Ts &&... dims)
190{
191 ARM_COMPUTE_UNUSED(function);
192 ARM_COMPUTE_UNUSED(file);
193 ARM_COMPUTE_UNUSED(line);
194
195 for_each(detail::compare_dimension<T>(dim1, function, file, line), dim2, std::forward<Ts>(dims)...);
196}
197#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(...) ::arm_compute::error_on_mismatching_dimensions(__func__, __FILE__, __LINE__, __VA_ARGS__)
198
199/** Throw an error if the passed two tensors have different shapes from the given dimension
200 *
201 * @param[in] function Function in which the error occurred.
202 * @param[in] file Name of the file where the error occurred.
203 * @param[in] line Line on which the error occurred.
204 * @param[in] tensor_1 The first tensor to be compared.
205 * @param[in] tensor_2 The second tensor to be compared.
206 * @param[in] tensors (Optional) Further allowed tensors.
207 */
208template <typename... Ts>
209void error_on_mismatching_shapes(const char *function, const char *file, const int line,
210 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
211{
212 error_on_mismatching_shapes(function, file, line, 0U, tensor_1, tensor_2, std::forward<Ts>(tensors)...);
213}
214
215/** Throw an error if the passed two tensors have different shapes from the given dimension
216 *
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] upper_dim The dimension from which to check.
221 * @param[in] tensor_1 The first tensor to be compared.
222 * @param[in] tensor_2 The second tensor to be compared.
223 * @param[in] tensors (Optional) Further allowed tensors.
224 */
225template <typename... Ts>
226void error_on_mismatching_shapes(const char *function, const char *file, const int line,
227 unsigned int upper_dim, const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
228{
229 ARM_COMPUTE_UNUSED(function);
230 ARM_COMPUTE_UNUSED(file);
231 ARM_COMPUTE_UNUSED(line);
232
233 const std::array < const ITensor *, 2 + sizeof...(Ts) > tensors_array{ { tensor_1, tensor_2, std::forward<Ts>(tensors)... } };
234 ARM_COMPUTE_UNUSED(tensors_array);
235
236 ARM_COMPUTE_ERROR_ON_LOC(tensors_array.cbegin() == nullptr, function, file, line);
237
238 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(std::next(tensors_array.cbegin()), tensors_array.cend(), [&](const ITensor * tensor)
239 {
240 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
241 return detail::have_different_dimensions((*tensors_array.cbegin())->info()->tensor_shape(), tensor->info()->tensor_shape(), upper_dim);
242 }),
243 function, file, line, "Tensors have different shapes");
244}
245#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...) ::arm_compute::error_on_mismatching_shapes(__func__, __FILE__, __LINE__, __VA_ARGS__)
246
247/** Throw an error if the passed two tensors have different data types
248 *
249 * @param[in] function Function in which the error occurred.
250 * @param[in] file Name of the file where the error occurred.
251 * @param[in] line Line on which the error occurred.
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100252 * @param[in] tensor The first tensor to be compared.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253 * @param[in] tensors (Optional) Further allowed tensors.
254 */
255template <typename... Ts>
256void error_on_mismatching_data_types(const char *function, const char *file, const int line,
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100257 const ITensor *tensor, Ts... tensors)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258{
259 ARM_COMPUTE_UNUSED(function);
260 ARM_COMPUTE_UNUSED(file);
261 ARM_COMPUTE_UNUSED(line);
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100262 ARM_COMPUTE_UNUSED(tensor);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100263
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100264 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
265
266 DataType &&tensor_data_type = tensor->info()->data_type();
267 ARM_COMPUTE_UNUSED(tensor_data_type);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100268
269 const std::array<const ITensor *, sizeof...(Ts)> tensors_array{ { std::forward<Ts>(tensors)... } };
270 ARM_COMPUTE_UNUSED(tensors_array);
271
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100272 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor_obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100273 {
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100274 ARM_COMPUTE_ERROR_ON_LOC(tensor_obj == nullptr, function, file, line);
275 return tensor_obj->info()->data_type() != tensor_data_type;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100276 }),
277 function, file, line, "Tensors have different data types");
278}
279
280#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...) ::arm_compute::error_on_mismatching_data_types(__func__, __FILE__, __LINE__, __VA_ARGS__)
281
282/** Throw an error if the passed tensors have different fixed point data types or different fixed point positions
283 *
284 * @note: If the first tensor doesn't have fixed point data type, the function returns without throwing an error
285 *
286 * @param[in] function Function in which the error occurred.
287 * @param[in] file Name of the file where the error occurred.
288 * @param[in] line Line on which the error occurred.
289 * @param[in] tensor_1 The first tensor to be compared.
290 * @param[in] tensor_2 The second tensor to be compared.
291 * @param[in] tensors (Optional) Further allowed tensors.
292 */
293template <typename... Ts>
294void error_on_mismatching_fixed_point(const char *function, const char *file, const int line,
295 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
296{
297 ARM_COMPUTE_UNUSED(function);
298 ARM_COMPUTE_UNUSED(file);
299 ARM_COMPUTE_UNUSED(line);
300 ARM_COMPUTE_UNUSED(tensor_1);
301 ARM_COMPUTE_UNUSED(tensor_2);
302
303 DataType &&first_data_type = tensor_1->info()->data_type();
304 const int first_fixed_point_position = tensor_1->info()->fixed_point_position();
305 ARM_COMPUTE_UNUSED(first_data_type);
306 ARM_COMPUTE_UNUSED(first_fixed_point_position);
307
308 if((first_data_type != DataType::QS8) && (first_data_type != DataType::QS16))
309 {
310 return;
311 }
312
313 const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_array{ { tensor_2, std::forward<Ts>(tensors)... } };
314 ARM_COMPUTE_UNUSED(tensors_array);
315
316 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
317 {
318 return tensor->info()->data_type() != first_data_type;
319 }),
320 function, file, line, "Tensors have different fixed point data types");
321
322 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
323 {
324 return tensor->info()->fixed_point_position() != first_fixed_point_position;
325 }),
326 function, file, line, "Tensors have different fixed point positions");
327}
328
329#define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(...) ::arm_compute::error_on_mismatching_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)
330
331/** Throw an error if the format of the passed tensor/multi-image does not match any of the formats provided.
332 *
333 * @param[in] function Function in which the error occurred.
334 * @param[in] file Name of the file where the error occurred.
335 * @param[in] line Line on which the error occurred.
336 * @param[in] object Tensor/multi-image to validate.
337 * @param[in] format First format allowed.
338 * @param[in] formats (Optional) Further allowed formats.
339 */
340template <typename T, typename F, typename... Fs>
341void error_on_format_not_in(const char *function, const char *file, const int line,
342 const T *object, F &&format, Fs &&... formats)
343{
344 ARM_COMPUTE_ERROR_ON_LOC(object == nullptr, function, file, line);
345
346 Format &&object_format = object->info()->format();
347 ARM_COMPUTE_UNUSED(object_format);
348
349 ARM_COMPUTE_ERROR_ON_LOC(object_format == Format::UNKNOWN, function, file, line);
350
351 const std::array<F, sizeof...(Fs)> formats_array{ { std::forward<Fs>(formats)... } };
352 ARM_COMPUTE_UNUSED(formats_array);
353
354 ARM_COMPUTE_ERROR_ON_LOC_MSG(object_format != format && std::none_of(formats_array.begin(), formats_array.end(), [&](const F & f)
355 {
356 return f == object_format;
357 }),
358 function, file, line, "Format %s not supported by this kernel", string_from_format(object_format).c_str());
359}
360#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t, ...) ::arm_compute::error_on_format_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)
361
362/** Throw an error if the data type of the passed tensor does not match any of the data types provided.
363 *
364 * @param[in] function Function in which the error occurred.
365 * @param[in] file Name of the file where the error occurred.
366 * @param[in] line Line on which the error occurred.
367 * @param[in] tensor Tensor to validate.
368 * @param[in] dt First data type allowed.
369 * @param[in] dts (Optional) Further allowed data types.
370 */
371template <typename T, typename... Ts>
372void error_on_data_type_not_in(const char *function, const char *file, const int line,
373 const ITensor *tensor, T &&dt, Ts &&... dts)
374{
375 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
376
377 const DataType &tensor_dt = tensor->info()->data_type(); //NOLINT
378 ARM_COMPUTE_UNUSED(tensor_dt);
379
380 ARM_COMPUTE_ERROR_ON_LOC(tensor_dt == DataType::UNKNOWN, function, file, line);
381
382 const std::array<T, sizeof...(Ts)> dts_array{ { std::forward<Ts>(dts)... } };
383 ARM_COMPUTE_UNUSED(dts_array);
384
385 ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor_dt != dt && std::none_of(dts_array.begin(), dts_array.end(), [&](const T & d)
386 {
387 return d == tensor_dt;
388 }),
389 function, file, line, "ITensor data type %s not supported by this kernel", string_from_data_type(tensor_dt).c_str());
390}
391#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t, ...) ::arm_compute::error_on_data_type_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)
392
393/** Throw 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.
394 *
395 * @param[in] function Function in which the error occurred.
396 * @param[in] file Name of the file where the error occurred.
397 * @param[in] line Line on which the error occurred.
398 * @param[in] tensor Tensor to validate.
399 * @param[in] num_channels Number of channels to check
400 * @param[in] dt First data type allowed.
401 * @param[in] dts (Optional) Further allowed data types.
402 */
403template <typename T, typename... Ts>
404void error_on_data_type_channel_not_in(const char *function, const char *file, const int line,
405 const ITensor *tensor, size_t num_channels, T &&dt, Ts &&... dts)
406{
407 error_on_data_type_not_in(function, file, line, tensor, std::forward<T>(dt), std::forward<Ts>(dts)...);
408
409 const size_t tensor_nc = tensor->info()->num_channels();
410 ARM_COMPUTE_UNUSED(tensor_nc);
411
412 ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor_nc != num_channels, function, file, line, "Number of channels %d. Required number of channels %d", tensor_nc, num_channels);
413}
414#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c, ...) ::arm_compute::error_on_data_type_channel_not_in(__func__, __FILE__, __LINE__, t, c, __VA_ARGS__)
415
416/** Throw an error if the tensor is not 2D.
417 *
418 * @param[in] function Function in which the error occurred.
419 * @param[in] file Name of the file where the error occurred.
420 * @param[in] line Line on which the error occurred.
421 * @param[in] tensor Tensor to validate.
422 */
423void error_on_tensor_not_2d(const char *function, const char *file, const int line,
424 const ITensor *tensor);
425#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t) ::arm_compute::error_on_tensor_not_2d(__func__, __FILE__, __LINE__, t)
426
427/** Throw an error if the channel is not in channels.
428 *
429 * @param[in] function Function in which the error occurred.
430 * @param[in] file Name of the file where the error occurred.
431 * @param[in] line Line on which the error occurred.
432 * @param[in] cn Input channel
433 * @param[in] channel First channel allowed.
434 * @param[in] channels (Optional) Further allowed channels.
435 */
436template <typename T, typename... Ts>
437void error_on_channel_not_in(const char *function, const char *file, const int line,
438 T cn, T &&channel, Ts &&... channels)
439{
440 ARM_COMPUTE_ERROR_ON_LOC(cn == Channel::UNKNOWN, function, file, line);
441
442 const std::array<T, sizeof...(Ts)> channels_array{ { std::forward<Ts>(channels)... } };
443 ARM_COMPUTE_UNUSED(channels_array);
444 ARM_COMPUTE_ERROR_ON_LOC(channel != cn && std::none_of(channels_array.begin(), channels_array.end(), [&](const T & f)
445 {
446 return f == cn;
447 }),
448 function, file, line);
449}
450#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN(c, ...) ::arm_compute::error_on_channel_not_in(__func__, __FILE__, __LINE__, c, __VA_ARGS__)
451
452/** Throw an error if the channel is not in format.
453 *
454 * @param[in] function Function in which the error occurred.
455 * @param[in] file Name of the file where the error occurred.
456 * @param[in] line Line on which the error occurred.
457 * @param[in] fmt Input channel
458 * @param[in] cn First channel allowed.
459 */
460void error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
461 Format fmt, Channel cn);
462#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN_KNOWN_FORMAT(f, c) ::arm_compute::error_on_channel_not_in_known_format(__func__, __FILE__, __LINE__, f, c)
463
464/** Throw an error if the @ref IMultiHOG container is invalid
465 *
466 * An @ref IMultiHOG container is invalid if:
467 *
468 * -# it is a nullptr
469 * -# it doesn't contain models
470 * -# it doesn't have the HOG data objects with the same phase_type, normalization_type and l2_hyst_threshold (if normalization_type == L2HYS_NORM)
471 *
472 * @param[in] function Function in which the error occurred.
473 * @param[in] file Name of the file where the error occurred.
474 * @param[in] line Line on which the error occurred.
475 * @param[in] multi_hog IMultiHOG container to validate
476 */
477void error_on_invalid_multi_hog(const char *function, const char *file, const int line,
478 const IMultiHOG *multi_hog);
479#define ARM_COMPUTE_ERROR_ON_INVALID_MULTI_HOG(m) ::arm_compute::error_on_invalid_multi_hog(__func__, __FILE__, __LINE__, m)
480
481/** Throw an error if the kernel is not configured.
482 *
483 * @param[in] function Function in which the error occurred.
484 * @param[in] file Name of the file where the error occurred.
485 * @param[in] line Line on which the error occurred.
486 * @param[in] kernel Kernel to validate.
487 */
488void error_on_unconfigured_kernel(const char *function, const char *file, const int line,
489 const IKernel *kernel);
490#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k) ::arm_compute::error_on_unconfigured_kernel(__func__, __FILE__, __LINE__, k)
491
492/** Throw an error if if the coordinates and shape of the subtensor are within the parent tensor.
493 *
494 * @param[in] function Function in which the error occurred.
495 * @param[in] file Name of the file where the error occurred.
496 * @param[in] line Line on which the error occurred.
497 * @param[in] parent_shape Parent tensor shape
498 * @param[in] coords Coordinates inside the parent tensor where the first element of the subtensor is
499 * @param[in] shape Shape of the subtensor
500 */
501void error_on_invalid_subtensor(const char *function, const char *file, const int line,
502 const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape);
503#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(p, c, s) ::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, p, c, s)
504
505/** Throw an error if the valid region of a subtensor is not inside the valid region of the parent tensor.
506 *
507 * @param[in] function Function in which the error occurred.
508 * @param[in] file Name of the file where the error occurred.
509 * @param[in] line Line on which the error occurred.
510 * @param[in] parent_valid_region Parent valid region.
511 * @param[in] valid_region Valid region of subtensor.
512 */
513void error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
514 const ValidRegion &parent_valid_region, const ValidRegion &valid_region);
515#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(pv, sv) ::arm_compute::error_on_invalid_subtensor_valid_region(__func__, __FILE__, __LINE__, pv, sv)
516
517/** Throw an error if the input fixed-point positions are different.
518 *
519 * @param[in] function Function in which the error occurred.
520 * @param[in] file Name of the file where the error occurred.
521 * @param[in] line Line on which the error occurred.
522 * @param[in] tensor_1 The first tensor to be compared.
523 * @param[in] tensor_2 The second tensor to be compared.
524 * @param[in] tensors (Optional) Further allowed tensors.
525 */
526template <typename... Ts>
527void error_on_mismatching_fixed_point_position(const char *function, const char *file, const int line,
528 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
529{
530 const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_array{ { tensor_2, std::forward<Ts>(tensors)... } };
531 ARM_COMPUTE_UNUSED(tensors_array);
532
533 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
534 {
535 return tensor->info()->fixed_point_position() != tensor_1->info()->fixed_point_position();
536 }),
537 function, file, line, "Tensors have different fixed-point positions");
538}
539#define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(...) ::arm_compute::error_on_mismatching_fixed_point_position(__func__, __FILE__, __LINE__, __VA_ARGS__)
540
541/** Throw an error if the fixed-point value is not representable in the specified Q format.
542 *
543 * @param[in] function Function in which the error occurred.
544 * @param[in] file Name of the file where the error occurred.
545 * @param[in] line Line on which the error occurred.
546 * @param[in] value The floating point value to be checked.
547 * @param[in] tensor Input tensor that has information on data type and fixed-point position.
548 */
549template <typename... Ts>
550void error_on_value_not_representable_in_fixed_point(const char *function, const char *file, int line,
551 float value, const ITensor *tensor)
552{
553 const int fixed_point_position = tensor->info()->fixed_point_position();
554 const DataType dt = tensor->info()->data_type();
555 const unsigned int q_max_range = 0xFFFFFFFFu >> (((sizeof(unsigned int) - element_size_from_data_type(dt)) * 8) + 1);
556 const float max_range = q_max_range / (static_cast<float>(1 << fixed_point_position));
557 ARM_COMPUTE_UNUSED(max_range);
558
559 ARM_COMPUTE_ERROR_ON_LOC_MSG(value > max_range, function, file, line,
560 "Value %f is not representable in %s with fixed-point position %d", value, string_from_data_type(dt).c_str(), fixed_point_position);
561}
562#define ARM_COMPUTE_ERROR_ON_VALUE_NOT_REPRESENTABLE_IN_FIXED_POINT(...) ::arm_compute::error_on_value_not_representable_in_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)
563}
564#endif /* __ARM_COMPUTE_VALIDATE_H__*/