blob: 5a6486e11e8f0407f535f38c7b29cea5301fe64a [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
Georgios Pinitas631c41a2017-12-06 11:53:03 +000026arm_compute::Status arm_compute::error_on_mismatching_windows(const char *function, const char *file, const int line,
27 const arm_compute::Window &full, const arm_compute::Window &win)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029 full.validate();
30 win.validate();
31
32 for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
33 {
Georgios Pinitas3faea252017-10-30 14:13:50 +000034 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line);
35 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line);
36 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000038 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039}
40
Georgios Pinitas631c41a2017-12-06 11:53:03 +000041arm_compute::Status arm_compute::error_on_invalid_subwindow(const char *function, const char *file, const int line,
42 const arm_compute::Window &full, const arm_compute::Window &sub)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044 full.validate();
45 sub.validate();
46
47 for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
48 {
Georgios Pinitas3faea252017-10-30 14:13:50 +000049 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line);
50 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line);
51 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line);
52 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 +010053 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000054 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055}
56
Georgios Pinitas631c41a2017-12-06 11:53:03 +000057arm_compute::Status arm_compute::error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line,
58 const arm_compute::Window &full, const arm_compute::Window &window, const int dim)
steniu01868e5412017-07-17 23:16:00 +010059{
steniu01868e5412017-07-17 23:16:00 +010060 full.validate();
61 window.validate();
62
Georgios Pinitas3faea252017-10-30 14:13:50 +000063 ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != 0, function, file, line);
64 ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line);
65 ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line);
66
Georgios Pinitas631c41a2017-12-06 11:53:03 +000067 return arm_compute::Status{};
steniu01868e5412017-07-17 23:16:00 +010068}
69
Georgios Pinitas631c41a2017-12-06 11:53:03 +000070arm_compute::Status arm_compute::error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
71 const arm_compute::Coordinates &pos, unsigned int max_dim)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
74 {
Georgios Pinitas3faea252017-10-30 14:13:50 +000075 ARM_COMPUTE_RETURN_ERROR_ON_LOC(pos[i] != 0, function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000077 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078}
79
Georgios Pinitas631c41a2017-12-06 11:53:03 +000080arm_compute::Status arm_compute::error_on_window_dimensions_gte(const char *function, const char *file, const int line,
81 const arm_compute::Window &win, unsigned int max_dim)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083 for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
84 {
Michalis Spyrou7c60c992019-10-10 14:33:47 +010085 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR((win[i].start() != 0) || (win[i].end() != win[i].step()),
86 function, file, line,
87 "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +000089 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090}
91
Georgios Pinitas631c41a2017-12-06 11:53:03 +000092arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line,
93 const arm_compute::ITensor *tensor)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094{
Georgios Pinitas3faea252017-10-30 14:13:50 +000095 ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
96 ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor->info() == nullptr, function, file, line);
Michalis Spyrou7c60c992019-10-10 14:33:47 +010097 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(tensor->info()->num_dimensions() != 2,
98 function, file, line,
99 "Only 2D Tensors are supported by this kernel (%zu passed)", tensor->info()->num_dimensions());
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000100 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101}
102
Michalis Spyroud1794eb2018-06-15 16:15:26 +0100103arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line,
104 const arm_compute::ITensorInfo *tensor)
105{
106 ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100107 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(tensor->num_dimensions() != 2,
108 function, file, line,
109 "Only 2D Tensors are supported by this kernel (%zu passed)", tensor->num_dimensions());
Michalis Spyroud1794eb2018-06-15 16:15:26 +0100110 return arm_compute::Status{};
111}
112
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000113arm_compute::Status arm_compute::error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
114 arm_compute::Format fmt, arm_compute::Channel cn)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115{
Georgios Pinitas3faea252017-10-30 14:13:50 +0000116 ARM_COMPUTE_RETURN_ERROR_ON_LOC(fmt == arm_compute::Format::UNKNOWN, function, file, line);
117 ARM_COMPUTE_RETURN_ERROR_ON_LOC(cn == arm_compute::Channel::UNKNOWN, function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118
119 switch(fmt)
120 {
121 case arm_compute::Format::RGB888:
122 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::R, arm_compute::Channel::G, arm_compute::Channel::B);
123 break;
124 case arm_compute::Format::RGBA8888:
125 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::R, arm_compute::Channel::G, arm_compute::Channel::B, arm_compute::Channel::A);
126 break;
127 case arm_compute::Format::UV88:
128 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::U, arm_compute::Channel::V);
129 break;
130 case arm_compute::Format::IYUV:
131 case arm_compute::Format::UYVY422:
132 case arm_compute::Format::YUYV422:
133 case arm_compute::Format::NV12:
134 case arm_compute::Format::NV21:
135 case arm_compute::Format::YUV444:
136 arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::Y, arm_compute::Channel::U, arm_compute::Channel::V);
137 break;
138 default:
139 ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format.");
140 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000141 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142}
143
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000144arm_compute::Status arm_compute::error_on_unconfigured_kernel(const char *function, const char *file, const int line,
145 const arm_compute::IKernel *kernel)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146{
Georgios Pinitas3faea252017-10-30 14:13:50 +0000147 ARM_COMPUTE_RETURN_ERROR_ON_LOC(kernel == nullptr, function, file, line);
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +0000148 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(!kernel->is_window_configured(),
Georgios Pinitas3faea252017-10-30 14:13:50 +0000149 function, file, line,
150 "This kernel hasn't been configured.");
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000151 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152}
153
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000154arm_compute::Status arm_compute::error_on_invalid_subtensor(const char *function, const char *file, const int line,
155 const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100157 // Check dimensions
158 for(unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i)
159 {
Georgios Pinitas0b5af9f2020-06-19 23:22:08 +0100160 const bool invalid_idx = coords[i] >= static_cast<int>(parent_shape[i]);
161 const bool out_of_bounds_size = coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]);
162 ARM_COMPUTE_RETURN_ERROR_ON_LOC(invalid_idx || out_of_bounds_size, function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100163 }
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000164 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100165}
166
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000167arm_compute::Status arm_compute::error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
168 const ValidRegion &parent_valid_region, const ValidRegion &valid_region)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100169{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170 // Check valid regions
171 for(unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d)
172 {
Georgios Pinitas3faea252017-10-30 14:13:50 +0000173 ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line);
174 ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] + static_cast<int>(parent_valid_region.shape[d])) < (valid_region.anchor[d] + static_cast<int>(valid_region.shape[d])),
175 function, file, line);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100176 }
Georgios Pinitas3faea252017-10-30 14:13:50 +0000177
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000178 return arm_compute::Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179}