Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2021 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 | */ |
| 24 | #include "arm_compute/core/Validate.h" |
| 25 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 26 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | full.validate(); |
| 33 | win.validate(); |
| 34 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 35 | for (size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 37 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 41 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 44 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | full.validate(); |
| 51 | sub.validate(); |
| 52 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 53 | for (size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 54 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 55 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 60 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 63 | arm_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) |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 69 | { |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 70 | full.validate(); |
| 71 | window.validate(); |
| 72 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 73 | 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 Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 77 | return arm_compute::Status{}; |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 80 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 83 | for (unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 85 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(pos[i] != 0, function, file, line); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 87 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 90 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 93 | for (unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 94 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 95 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 99 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 102 | arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function, |
| 103 | const char *file, |
| 104 | const int line, |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 105 | const arm_compute::ITensor *tensor) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 106 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 107 | 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 109 | 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 Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 112 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 115 | arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function, |
| 116 | const char *file, |
| 117 | const int line, |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 118 | const arm_compute::ITensorInfo *tensor) |
| 119 | { |
| 120 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 121 | 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 Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 124 | return arm_compute::Status{}; |
| 125 | } |
| 126 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 127 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 130 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 132 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 133 | switch (fmt) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 134 | { |
| 135 | case arm_compute::Format::RGB888: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 136 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 138 | break; |
| 139 | case arm_compute::Format::RGBA8888: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 140 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 143 | break; |
| 144 | case arm_compute::Format::UV88: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 145 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::U, |
| 146 | arm_compute::Channel::V); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 147 | 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 154 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 156 | break; |
| 157 | default: |
| 158 | ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format."); |
| 159 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 160 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 163 | arm_compute::Status arm_compute::error_on_unconfigured_kernel(const char *function, |
| 164 | const char *file, |
| 165 | const int line, |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 166 | const arm_compute::IKernel *kernel) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 167 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 168 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(kernel == nullptr, function, file, line); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 169 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(!kernel->is_window_configured(), function, file, line, |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 170 | "This kernel hasn't been configured."); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 171 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 174 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 180 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 181 | // Check dimensions |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 182 | for (unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | { |
Georgios Pinitas | 0b5af9f | 2020-06-19 23:22:08 +0100 | [diff] [blame] | 184 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 187 | } |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 188 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 191 | arm_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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 196 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 197 | // Check valid regions |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 198 | for (unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 199 | { |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 200 | ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 201 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 205 | } |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 206 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 207 | return arm_compute::Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 208 | } |