blob: d8f796193ee16fad3e5d5c344b313187252cc775 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +00002 * Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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#include "arm_compute/core/Validate.h"
25
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010026arm_compute::Status arm_compute::error_on_mismatching_windows(const char *function,
27 const char *file,
28 const int line,
29 const arm_compute::Window &full,
30 const arm_compute::Window &win)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032 full.validate();
33 win.validate();
34
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010035 for (size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036 {
Georgios Pinitas3faea252017-10-30 14:13:50 +000037 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line);
38 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line);
39 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000041 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042}
43
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010044arm_compute::Status arm_compute::error_on_invalid_subwindow(const char *function,
45 const char *file,
46 const int line,
47 const arm_compute::Window &full,
48 const arm_compute::Window &sub)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050 full.validate();
51 sub.validate();
52
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010053 for (size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 {
Georgios Pinitas3faea252017-10-30 14:13:50 +000055 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line);
56 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line);
57 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line);
58 ARM_COMPUTE_RETURN_ERROR_ON_LOC((sub[i].start() - full[i].start()) % sub[i].step(), function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000060 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061}
62
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063arm_compute::Status arm_compute::error_on_window_not_collapsable_at_dimension(const char *function,
64 const char *file,
65 const int line,
66 const arm_compute::Window &full,
67 const arm_compute::Window &window,
68 const int dim)
steniu01868e5412017-07-17 23:16:00 +010069{
steniu01868e5412017-07-17 23:16:00 +010070 full.validate();
71 window.validate();
72
Georgios Pinitas3faea252017-10-30 14:13:50 +000073 ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != 0, function, file, line);
74 ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line);
75 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line);
76
Georgios Pinitas631c41a2017-12-06 11:53:03 +000077 return arm_compute::Status{};
steniu01868e5412017-07-17 23:16:00 +010078}
79
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010080arm_compute::Status arm_compute::error_on_coordinates_dimensions_gte(
81 const char *function, const char *file, const int line, const arm_compute::Coordinates &pos, unsigned int max_dim)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010083 for (unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084 {
Georgios Pinitas3faea252017-10-30 14:13:50 +000085 ARM_COMPUTE_RETURN_ERROR_ON_LOC(pos[i] != 0, function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000087 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088}
89
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010090arm_compute::Status arm_compute::error_on_window_dimensions_gte(
91 const char *function, const char *file, const int line, const arm_compute::Window &win, unsigned int max_dim)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010093 for (unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010095 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(
96 (win[i].start() != 0) || (win[i].end() != win[i].step()), function, file, line,
97 "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000099 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100}
101
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100102arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function,
103 const char *file,
104 const int line,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000105 const arm_compute::ITensor *tensor)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106{
Georgios Pinitas3faea252017-10-30 14:13:50 +0000107 ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
108 ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor->info() == nullptr, function, file, line);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100109 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(tensor->info()->num_dimensions() != 2, function, file, line,
110 "Only 2D Tensors are supported by this kernel (%zu passed)",
111 tensor->info()->num_dimensions());
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000112 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113}
114
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100115arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function,
116 const char *file,
117 const int line,
Michalis Spyroud1794eb2018-06-15 16:15:26 +0100118 const arm_compute::ITensorInfo *tensor)
119{
120 ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100121 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(tensor->num_dimensions() != 2, function, file, line,
122 "Only 2D Tensors are supported by this kernel (%zu passed)",
123 tensor->num_dimensions());
Michalis Spyroud1794eb2018-06-15 16:15:26 +0100124 return arm_compute::Status{};
125}
126
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100127arm_compute::Status arm_compute::error_on_channel_not_in_known_format(
128 const char *function, const char *file, const int line, arm_compute::Format fmt, arm_compute::Channel cn)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100129{
Georgios Pinitas3faea252017-10-30 14:13:50 +0000130 ARM_COMPUTE_RETURN_ERROR_ON_LOC(fmt == arm_compute::Format::UNKNOWN, function, file, line);
131 ARM_COMPUTE_RETURN_ERROR_ON_LOC(cn == arm_compute::Channel::UNKNOWN, function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100132
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100133 switch (fmt)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 {
135 case arm_compute::Format::RGB888:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100136 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::R,
137 arm_compute::Channel::G, arm_compute::Channel::B);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138 break;
139 case arm_compute::Format::RGBA8888:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100140 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::R,
141 arm_compute::Channel::G, arm_compute::Channel::B,
142 arm_compute::Channel::A);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143 break;
144 case arm_compute::Format::UV88:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100145 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::U,
146 arm_compute::Channel::V);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100147 break;
148 case arm_compute::Format::IYUV:
149 case arm_compute::Format::UYVY422:
150 case arm_compute::Format::YUYV422:
151 case arm_compute::Format::NV12:
152 case arm_compute::Format::NV21:
153 case arm_compute::Format::YUV444:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100154 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::Y,
155 arm_compute::Channel::U, arm_compute::Channel::V);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156 break;
157 default:
158 ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format.");
159 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000160 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100161}
162
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100163arm_compute::Status arm_compute::error_on_unconfigured_kernel(const char *function,
164 const char *file,
165 const int line,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000166 const arm_compute::IKernel *kernel)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100167{
Georgios Pinitas3faea252017-10-30 14:13:50 +0000168 ARM_COMPUTE_RETURN_ERROR_ON_LOC(kernel == nullptr, function, file, line);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100169 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(!kernel->is_window_configured(), function, file, line,
Georgios Pinitas3faea252017-10-30 14:13:50 +0000170 "This kernel hasn't been configured.");
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000171 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100172}
173
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100174arm_compute::Status arm_compute::error_on_invalid_subtensor(const char *function,
175 const char *file,
176 const int line,
177 const TensorShape &parent_shape,
178 const Coordinates &coords,
179 const TensorShape &shape)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181 // Check dimensions
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100182 for (unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100183 {
Georgios Pinitas0b5af9f2020-06-19 23:22:08 +0100184 const bool invalid_idx = coords[i] >= static_cast<int>(parent_shape[i]);
185 const bool out_of_bounds_size = coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]);
186 ARM_COMPUTE_RETURN_ERROR_ON_LOC(invalid_idx || out_of_bounds_size, function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000188 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189}
190
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100191arm_compute::Status arm_compute::error_on_invalid_subtensor_valid_region(const char *function,
192 const char *file,
193 const int line,
194 const ValidRegion &parent_valid_region,
195 const ValidRegion &valid_region)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100196{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100197 // Check valid regions
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100198 for (unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199 {
Georgios Pinitas3faea252017-10-30 14:13:50 +0000200 ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100201 ARM_COMPUTE_RETURN_ERROR_ON_LOC(
202 (parent_valid_region.anchor[d] + static_cast<int>(parent_valid_region.shape[d])) <
203 (valid_region.anchor[d] + static_cast<int>(valid_region.shape[d])),
204 function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100205 }
Georgios Pinitas3faea252017-10-30 14:13:50 +0000206
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000207 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208}