blob: 34da339f03fbddc7c05357040267beff6f2c802c [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
steniu01868e5412017-07-17 23:16:00 +0100150/** Throw an error if the window can't be collapsed at the given dimension.
151 *
152 * The window cannot be collapsed if the given dimension not equal to the full window's dimension or not start 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] full Full size window
158 * @param[in] window Window to be collapsed.
159 * @param[in] dim Dimension need to be checked.
160 */
161void error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line,
162 const Window &full, const Window &window, const int dim);
163#define ARM_COMPUTE_ERROR_ON_WINDOW_NOT_COLLAPSABLE_AT_DIMENSION(f, w, d) ::arm_compute::error_on_window_not_collapsable_at_dimension(__func__, __FILE__, __LINE__, f, w, d)
164
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100165/** Throw an error if the passed coordinates have too many dimensions.
166 *
167 * The coordinates have too many dimensions if any of the dimensions greater or equal to max_dim is different from 0.
168 *
169 * @param[in] function Function in which the error occurred.
170 * @param[in] file Name of the file where the error occurred.
171 * @param[in] line Line on which the error occurred.
172 * @param[in] pos Coordinates to validate
173 * @param[in] max_dim Maximum number of dimensions allowed.
174 */
175void error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
176 const Coordinates &pos, unsigned int max_dim);
177#define ARM_COMPUTE_ERROR_ON_COORDINATES_DIMENSIONS_GTE(p, md) ::arm_compute::error_on_coordinates_dimensions_gte(__func__, __FILE__, __LINE__, p, md)
178
179/** Throw an error if the passed window has too many dimensions.
180 *
181 * The window has too many dimensions if any of the dimension greater or equal to max_dim is different from 0.
182 *
183 * @param[in] function Function in which the error occurred.
184 * @param[in] file Name of the file where the error occurred.
185 * @param[in] line Line on which the error occurred.
186 * @param[in] win Window to validate
187 * @param[in] max_dim Maximum number of dimensions allowed.
188 */
189void error_on_window_dimensions_gte(const char *function, const char *file, const int line,
190 const Window &win, unsigned int max_dim);
191#define ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(w, md) ::arm_compute::error_on_window_dimensions_gte(__func__, __FILE__, __LINE__, w, md)
192
193/** Throw an error if the passed dimension objects differ.
194 *
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] dim1 The first object to be compared.
199 * @param[in] dim2 The second object to be compared.
200 * @param[in] dims (Optional) Further allowed objects.
201 */
202template <typename T, typename... Ts>
203void error_on_mismatching_dimensions(const char *function, const char *file, int line,
204 const Dimensions<T> &dim1, const Dimensions<T> &dim2, Ts &&... dims)
205{
206 ARM_COMPUTE_UNUSED(function);
207 ARM_COMPUTE_UNUSED(file);
208 ARM_COMPUTE_UNUSED(line);
209
210 for_each(detail::compare_dimension<T>(dim1, function, file, line), dim2, std::forward<Ts>(dims)...);
211}
212#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(...) ::arm_compute::error_on_mismatching_dimensions(__func__, __FILE__, __LINE__, __VA_ARGS__)
213
214/** Throw an error if the passed two tensors have different shapes from the given dimension
215 *
216 * @param[in] function Function in which the error occurred.
217 * @param[in] file Name of the file where the error occurred.
218 * @param[in] line Line on which the error occurred.
219 * @param[in] tensor_1 The first tensor to be compared.
220 * @param[in] tensor_2 The second tensor to be compared.
221 * @param[in] tensors (Optional) Further allowed tensors.
222 */
223template <typename... Ts>
224void error_on_mismatching_shapes(const char *function, const char *file, const int line,
225 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
226{
227 error_on_mismatching_shapes(function, file, line, 0U, tensor_1, tensor_2, std::forward<Ts>(tensors)...);
228}
229
230/** Throw an error if the passed two tensors have different shapes from the given dimension
231 *
232 * @param[in] function Function in which the error occurred.
233 * @param[in] file Name of the file where the error occurred.
234 * @param[in] line Line on which the error occurred.
235 * @param[in] upper_dim The dimension from which to check.
236 * @param[in] tensor_1 The first tensor to be compared.
237 * @param[in] tensor_2 The second tensor to be compared.
238 * @param[in] tensors (Optional) Further allowed tensors.
239 */
240template <typename... Ts>
241void error_on_mismatching_shapes(const char *function, const char *file, const int line,
242 unsigned int upper_dim, const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
243{
244 ARM_COMPUTE_UNUSED(function);
245 ARM_COMPUTE_UNUSED(file);
246 ARM_COMPUTE_UNUSED(line);
247
248 const std::array < const ITensor *, 2 + sizeof...(Ts) > tensors_array{ { tensor_1, tensor_2, std::forward<Ts>(tensors)... } };
249 ARM_COMPUTE_UNUSED(tensors_array);
250
251 ARM_COMPUTE_ERROR_ON_LOC(tensors_array.cbegin() == nullptr, function, file, line);
252
253 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(std::next(tensors_array.cbegin()), tensors_array.cend(), [&](const ITensor * tensor)
254 {
255 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
256 return detail::have_different_dimensions((*tensors_array.cbegin())->info()->tensor_shape(), tensor->info()->tensor_shape(), upper_dim);
257 }),
258 function, file, line, "Tensors have different shapes");
259}
260#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...) ::arm_compute::error_on_mismatching_shapes(__func__, __FILE__, __LINE__, __VA_ARGS__)
261
262/** Throw an error if the passed two tensors have different data types
263 *
264 * @param[in] function Function in which the error occurred.
265 * @param[in] file Name of the file where the error occurred.
266 * @param[in] line Line on which the error occurred.
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100267 * @param[in] tensor The first tensor to be compared.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100268 * @param[in] tensors (Optional) Further allowed tensors.
269 */
270template <typename... Ts>
271void error_on_mismatching_data_types(const char *function, const char *file, const int line,
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100272 const ITensor *tensor, Ts... tensors)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100273{
274 ARM_COMPUTE_UNUSED(function);
275 ARM_COMPUTE_UNUSED(file);
276 ARM_COMPUTE_UNUSED(line);
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100277 ARM_COMPUTE_UNUSED(tensor);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100278
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100279 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
280
281 DataType &&tensor_data_type = tensor->info()->data_type();
282 ARM_COMPUTE_UNUSED(tensor_data_type);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100283
284 const std::array<const ITensor *, sizeof...(Ts)> tensors_array{ { std::forward<Ts>(tensors)... } };
285 ARM_COMPUTE_UNUSED(tensors_array);
286
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100287 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 +0100288 {
Georgios Pinitas0326eae2017-06-27 15:46:05 +0100289 ARM_COMPUTE_ERROR_ON_LOC(tensor_obj == nullptr, function, file, line);
290 return tensor_obj->info()->data_type() != tensor_data_type;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100291 }),
292 function, file, line, "Tensors have different data types");
293}
294
295#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...) ::arm_compute::error_on_mismatching_data_types(__func__, __FILE__, __LINE__, __VA_ARGS__)
296
297/** Throw an error if the passed tensors have different fixed point data types or different fixed point positions
298 *
299 * @note: If the first tensor doesn't have fixed point data type, the function returns without throwing an error
300 *
301 * @param[in] function Function in which the error occurred.
302 * @param[in] file Name of the file where the error occurred.
303 * @param[in] line Line on which the error occurred.
304 * @param[in] tensor_1 The first tensor to be compared.
305 * @param[in] tensor_2 The second tensor to be compared.
306 * @param[in] tensors (Optional) Further allowed tensors.
307 */
308template <typename... Ts>
309void error_on_mismatching_fixed_point(const char *function, const char *file, const int line,
310 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
311{
312 ARM_COMPUTE_UNUSED(function);
313 ARM_COMPUTE_UNUSED(file);
314 ARM_COMPUTE_UNUSED(line);
315 ARM_COMPUTE_UNUSED(tensor_1);
316 ARM_COMPUTE_UNUSED(tensor_2);
317
318 DataType &&first_data_type = tensor_1->info()->data_type();
319 const int first_fixed_point_position = tensor_1->info()->fixed_point_position();
320 ARM_COMPUTE_UNUSED(first_data_type);
321 ARM_COMPUTE_UNUSED(first_fixed_point_position);
322
323 if((first_data_type != DataType::QS8) && (first_data_type != DataType::QS16))
324 {
325 return;
326 }
327
328 const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_array{ { tensor_2, std::forward<Ts>(tensors)... } };
329 ARM_COMPUTE_UNUSED(tensors_array);
330
331 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
332 {
333 return tensor->info()->data_type() != first_data_type;
334 }),
335 function, file, line, "Tensors have different fixed point data types");
336
337 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
338 {
339 return tensor->info()->fixed_point_position() != first_fixed_point_position;
340 }),
341 function, file, line, "Tensors have different fixed point positions");
342}
343
344#define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(...) ::arm_compute::error_on_mismatching_fixed_point(__func__, __FILE__, __LINE__, __VA_ARGS__)
345
346/** Throw an error if the format of the passed tensor/multi-image does not match any of the formats provided.
347 *
348 * @param[in] function Function in which the error occurred.
349 * @param[in] file Name of the file where the error occurred.
350 * @param[in] line Line on which the error occurred.
351 * @param[in] object Tensor/multi-image to validate.
352 * @param[in] format First format allowed.
353 * @param[in] formats (Optional) Further allowed formats.
354 */
355template <typename T, typename F, typename... Fs>
356void error_on_format_not_in(const char *function, const char *file, const int line,
357 const T *object, F &&format, Fs &&... formats)
358{
359 ARM_COMPUTE_ERROR_ON_LOC(object == nullptr, function, file, line);
360
361 Format &&object_format = object->info()->format();
362 ARM_COMPUTE_UNUSED(object_format);
363
364 ARM_COMPUTE_ERROR_ON_LOC(object_format == Format::UNKNOWN, function, file, line);
365
366 const std::array<F, sizeof...(Fs)> formats_array{ { std::forward<Fs>(formats)... } };
367 ARM_COMPUTE_UNUSED(formats_array);
368
369 ARM_COMPUTE_ERROR_ON_LOC_MSG(object_format != format && std::none_of(formats_array.begin(), formats_array.end(), [&](const F & f)
370 {
371 return f == object_format;
372 }),
373 function, file, line, "Format %s not supported by this kernel", string_from_format(object_format).c_str());
374}
375#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t, ...) ::arm_compute::error_on_format_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)
376
377/** Throw an error if the data type of the passed tensor does not match any of the data types provided.
378 *
379 * @param[in] function Function in which the error occurred.
380 * @param[in] file Name of the file where the error occurred.
381 * @param[in] line Line on which the error occurred.
382 * @param[in] tensor Tensor to validate.
383 * @param[in] dt First data type allowed.
384 * @param[in] dts (Optional) Further allowed data types.
385 */
386template <typename T, typename... Ts>
387void error_on_data_type_not_in(const char *function, const char *file, const int line,
388 const ITensor *tensor, T &&dt, Ts &&... dts)
389{
390 ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
391
392 const DataType &tensor_dt = tensor->info()->data_type(); //NOLINT
393 ARM_COMPUTE_UNUSED(tensor_dt);
394
395 ARM_COMPUTE_ERROR_ON_LOC(tensor_dt == DataType::UNKNOWN, function, file, line);
396
397 const std::array<T, sizeof...(Ts)> dts_array{ { std::forward<Ts>(dts)... } };
398 ARM_COMPUTE_UNUSED(dts_array);
399
400 ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor_dt != dt && std::none_of(dts_array.begin(), dts_array.end(), [&](const T & d)
401 {
402 return d == tensor_dt;
403 }),
404 function, file, line, "ITensor data type %s not supported by this kernel", string_from_data_type(tensor_dt).c_str());
405}
406#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t, ...) ::arm_compute::error_on_data_type_not_in(__func__, __FILE__, __LINE__, t, __VA_ARGS__)
407
408/** 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.
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] tensor Tensor to validate.
414 * @param[in] num_channels Number of channels to check
415 * @param[in] dt First data type allowed.
416 * @param[in] dts (Optional) Further allowed data types.
417 */
418template <typename T, typename... Ts>
419void error_on_data_type_channel_not_in(const char *function, const char *file, const int line,
420 const ITensor *tensor, size_t num_channels, T &&dt, Ts &&... dts)
421{
422 error_on_data_type_not_in(function, file, line, tensor, std::forward<T>(dt), std::forward<Ts>(dts)...);
423
424 const size_t tensor_nc = tensor->info()->num_channels();
425 ARM_COMPUTE_UNUSED(tensor_nc);
426
427 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);
428}
429#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__)
430
431/** Throw an error if the tensor is not 2D.
432 *
433 * @param[in] function Function in which the error occurred.
434 * @param[in] file Name of the file where the error occurred.
435 * @param[in] line Line on which the error occurred.
436 * @param[in] tensor Tensor to validate.
437 */
438void error_on_tensor_not_2d(const char *function, const char *file, const int line,
439 const ITensor *tensor);
440#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t) ::arm_compute::error_on_tensor_not_2d(__func__, __FILE__, __LINE__, t)
441
442/** Throw an error if the channel is not in channels.
443 *
444 * @param[in] function Function in which the error occurred.
445 * @param[in] file Name of the file where the error occurred.
446 * @param[in] line Line on which the error occurred.
447 * @param[in] cn Input channel
448 * @param[in] channel First channel allowed.
449 * @param[in] channels (Optional) Further allowed channels.
450 */
451template <typename T, typename... Ts>
452void error_on_channel_not_in(const char *function, const char *file, const int line,
453 T cn, T &&channel, Ts &&... channels)
454{
455 ARM_COMPUTE_ERROR_ON_LOC(cn == Channel::UNKNOWN, function, file, line);
456
457 const std::array<T, sizeof...(Ts)> channels_array{ { std::forward<Ts>(channels)... } };
458 ARM_COMPUTE_UNUSED(channels_array);
459 ARM_COMPUTE_ERROR_ON_LOC(channel != cn && std::none_of(channels_array.begin(), channels_array.end(), [&](const T & f)
460 {
461 return f == cn;
462 }),
463 function, file, line);
464}
465#define ARM_COMPUTE_ERROR_ON_CHANNEL_NOT_IN(c, ...) ::arm_compute::error_on_channel_not_in(__func__, __FILE__, __LINE__, c, __VA_ARGS__)
466
467/** Throw an error if the channel is not in format.
468 *
469 * @param[in] function Function in which the error occurred.
470 * @param[in] file Name of the file where the error occurred.
471 * @param[in] line Line on which the error occurred.
472 * @param[in] fmt Input channel
473 * @param[in] cn First channel allowed.
474 */
475void error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
476 Format fmt, Channel cn);
477#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)
478
479/** Throw an error if the @ref IMultiHOG container is invalid
480 *
481 * An @ref IMultiHOG container is invalid if:
482 *
483 * -# it is a nullptr
484 * -# it doesn't contain models
485 * -# it doesn't have the HOG data objects with the same phase_type, normalization_type and l2_hyst_threshold (if normalization_type == L2HYS_NORM)
486 *
487 * @param[in] function Function in which the error occurred.
488 * @param[in] file Name of the file where the error occurred.
489 * @param[in] line Line on which the error occurred.
490 * @param[in] multi_hog IMultiHOG container to validate
491 */
492void error_on_invalid_multi_hog(const char *function, const char *file, const int line,
493 const IMultiHOG *multi_hog);
494#define ARM_COMPUTE_ERROR_ON_INVALID_MULTI_HOG(m) ::arm_compute::error_on_invalid_multi_hog(__func__, __FILE__, __LINE__, m)
495
496/** Throw an error if the kernel is not configured.
497 *
498 * @param[in] function Function in which the error occurred.
499 * @param[in] file Name of the file where the error occurred.
500 * @param[in] line Line on which the error occurred.
501 * @param[in] kernel Kernel to validate.
502 */
503void error_on_unconfigured_kernel(const char *function, const char *file, const int line,
504 const IKernel *kernel);
505#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k) ::arm_compute::error_on_unconfigured_kernel(__func__, __FILE__, __LINE__, k)
506
507/** Throw an error if if the coordinates and shape of the subtensor are within the parent tensor.
508 *
509 * @param[in] function Function in which the error occurred.
510 * @param[in] file Name of the file where the error occurred.
511 * @param[in] line Line on which the error occurred.
512 * @param[in] parent_shape Parent tensor shape
513 * @param[in] coords Coordinates inside the parent tensor where the first element of the subtensor is
514 * @param[in] shape Shape of the subtensor
515 */
516void error_on_invalid_subtensor(const char *function, const char *file, const int line,
517 const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape);
518#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(p, c, s) ::arm_compute::error_on_invalid_subtensor(__func__, __FILE__, __LINE__, p, c, s)
519
520/** Throw an error if the valid region of a subtensor is not inside the valid region of the parent tensor.
521 *
522 * @param[in] function Function in which the error occurred.
523 * @param[in] file Name of the file where the error occurred.
524 * @param[in] line Line on which the error occurred.
525 * @param[in] parent_valid_region Parent valid region.
526 * @param[in] valid_region Valid region of subtensor.
527 */
528void error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
529 const ValidRegion &parent_valid_region, const ValidRegion &valid_region);
530#define ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR_VALID_REGION(pv, sv) ::arm_compute::error_on_invalid_subtensor_valid_region(__func__, __FILE__, __LINE__, pv, sv)
531
532/** Throw an error if the input fixed-point positions are different.
533 *
534 * @param[in] function Function in which the error occurred.
535 * @param[in] file Name of the file where the error occurred.
536 * @param[in] line Line on which the error occurred.
537 * @param[in] tensor_1 The first tensor to be compared.
538 * @param[in] tensor_2 The second tensor to be compared.
539 * @param[in] tensors (Optional) Further allowed tensors.
540 */
541template <typename... Ts>
542void error_on_mismatching_fixed_point_position(const char *function, const char *file, const int line,
543 const ITensor *tensor_1, const ITensor *tensor_2, Ts... tensors)
544{
545 const std::array < const ITensor *, 1 + sizeof...(Ts) > tensors_array{ { tensor_2, std::forward<Ts>(tensors)... } };
546 ARM_COMPUTE_UNUSED(tensors_array);
547
548 ARM_COMPUTE_ERROR_ON_LOC_MSG(std::any_of(tensors_array.begin(), tensors_array.end(), [&](const ITensor * tensor)
549 {
550 return tensor->info()->fixed_point_position() != tensor_1->info()->fixed_point_position();
551 }),
552 function, file, line, "Tensors have different fixed-point positions");
553}
554#define ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(...) ::arm_compute::error_on_mismatching_fixed_point_position(__func__, __FILE__, __LINE__, __VA_ARGS__)
555
556/** Throw an error if the fixed-point value is not representable in the specified Q format.
557 *
558 * @param[in] function Function in which the error occurred.
559 * @param[in] file Name of the file where the error occurred.
560 * @param[in] line Line on which the error occurred.
561 * @param[in] value The floating point value to be checked.
562 * @param[in] tensor Input tensor that has information on data type and fixed-point position.
563 */
564template <typename... Ts>
565void error_on_value_not_representable_in_fixed_point(const char *function, const char *file, int line,
566 float value, const ITensor *tensor)
567{
568 const int fixed_point_position = tensor->info()->fixed_point_position();
569 const DataType dt = tensor->info()->data_type();
570 const unsigned int q_max_range = 0xFFFFFFFFu >> (((sizeof(unsigned int) - element_size_from_data_type(dt)) * 8) + 1);
571 const float max_range = q_max_range / (static_cast<float>(1 << fixed_point_position));
572 ARM_COMPUTE_UNUSED(max_range);
573
574 ARM_COMPUTE_ERROR_ON_LOC_MSG(value > max_range, function, file, line,
575 "Value %f is not representable in %s with fixed-point position %d", value, string_from_data_type(dt).c_str(), fixed_point_position);
576}
577#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__)
578}
579#endif /* __ARM_COMPUTE_VALIDATE_H__*/