Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 | #include "arm_compute/core/Validate.h" |
| 25 | |
| 26 | void 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) |
| 28 | { |
| 29 | ARM_COMPUTE_UNUSED(function); |
| 30 | ARM_COMPUTE_UNUSED(file); |
| 31 | ARM_COMPUTE_UNUSED(line); |
| 32 | |
| 33 | full.validate(); |
| 34 | win.validate(); |
| 35 | |
| 36 | for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
| 37 | { |
| 38 | ARM_COMPUTE_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line); |
| 39 | ARM_COMPUTE_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line); |
| 40 | ARM_COMPUTE_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void arm_compute::error_on_invalid_subwindow(const char *function, const char *file, const int line, |
| 45 | const arm_compute::Window &full, const arm_compute::Window &sub) |
| 46 | { |
| 47 | ARM_COMPUTE_UNUSED(function); |
| 48 | ARM_COMPUTE_UNUSED(file); |
| 49 | ARM_COMPUTE_UNUSED(line); |
| 50 | |
| 51 | full.validate(); |
| 52 | sub.validate(); |
| 53 | |
| 54 | for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
| 55 | { |
| 56 | ARM_COMPUTE_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line); |
| 57 | ARM_COMPUTE_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line); |
| 58 | ARM_COMPUTE_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line); |
| 59 | ARM_COMPUTE_ERROR_ON_LOC((sub[i].start() - full[i].start()) % sub[i].step(), function, file, line); |
| 60 | } |
| 61 | } |
| 62 | |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 63 | void arm_compute::error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line, |
| 64 | const arm_compute::Window &full, const arm_compute::Window &window, const int dim) |
| 65 | { |
| 66 | ARM_COMPUTE_UNUSED(function); |
| 67 | ARM_COMPUTE_UNUSED(file); |
| 68 | ARM_COMPUTE_UNUSED(line); |
| 69 | ARM_COMPUTE_UNUSED(dim); |
| 70 | |
| 71 | full.validate(); |
| 72 | window.validate(); |
| 73 | |
| 74 | ARM_COMPUTE_ERROR_ON_LOC(window[dim].start() != 0, function, file, line); |
| 75 | ARM_COMPUTE_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line); |
| 76 | ARM_COMPUTE_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line); |
| 77 | } |
| 78 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | void arm_compute::error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line, |
| 80 | const arm_compute::Coordinates &pos, unsigned int max_dim) |
| 81 | { |
| 82 | ARM_COMPUTE_UNUSED(function); |
| 83 | ARM_COMPUTE_UNUSED(file); |
| 84 | ARM_COMPUTE_UNUSED(line); |
| 85 | ARM_COMPUTE_UNUSED(pos); |
| 86 | |
| 87 | for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
| 88 | { |
| 89 | ARM_COMPUTE_ERROR_ON_LOC(pos[i] != 0, function, file, line); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void arm_compute::error_on_window_dimensions_gte(const char *function, const char *file, const int line, |
| 94 | const arm_compute::Window &win, unsigned int max_dim) |
| 95 | { |
| 96 | ARM_COMPUTE_UNUSED(function); |
| 97 | ARM_COMPUTE_UNUSED(file); |
| 98 | ARM_COMPUTE_UNUSED(line); |
| 99 | ARM_COMPUTE_UNUSED(win); |
| 100 | |
| 101 | for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
| 102 | { |
| 103 | ARM_COMPUTE_ERROR_ON_LOC_MSG(win[i].start() != 0 || win[i].end() != win[i].step(), |
| 104 | function, file, line, |
| 105 | "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line, |
| 110 | const arm_compute::ITensor *tensor) |
| 111 | { |
| 112 | ARM_COMPUTE_UNUSED(function); |
| 113 | ARM_COMPUTE_UNUSED(file); |
| 114 | ARM_COMPUTE_UNUSED(line); |
| 115 | ARM_COMPUTE_UNUSED(tensor); |
| 116 | |
| 117 | ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 118 | ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor->info()->num_dimensions() != 2, |
| 119 | function, file, line, |
| 120 | "Only 2D Tensors are supported by this kernel (%d passed)", tensor->info()->num_dimensions()); |
| 121 | } |
| 122 | |
| 123 | void arm_compute::error_on_channel_not_in_known_format(const char *function, const char *file, const int line, |
| 124 | arm_compute::Format fmt, arm_compute::Channel cn) |
| 125 | { |
| 126 | ARM_COMPUTE_ERROR_ON_LOC(fmt == arm_compute::Format::UNKNOWN, function, file, line); |
| 127 | ARM_COMPUTE_ERROR_ON_LOC(cn == arm_compute::Channel::UNKNOWN, function, file, line); |
| 128 | |
| 129 | switch(fmt) |
| 130 | { |
| 131 | case arm_compute::Format::RGB888: |
| 132 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::R, arm_compute::Channel::G, arm_compute::Channel::B); |
| 133 | break; |
| 134 | case arm_compute::Format::RGBA8888: |
| 135 | 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); |
| 136 | break; |
| 137 | case arm_compute::Format::UV88: |
| 138 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::U, arm_compute::Channel::V); |
| 139 | break; |
| 140 | case arm_compute::Format::IYUV: |
| 141 | case arm_compute::Format::UYVY422: |
| 142 | case arm_compute::Format::YUYV422: |
| 143 | case arm_compute::Format::NV12: |
| 144 | case arm_compute::Format::NV21: |
| 145 | case arm_compute::Format::YUV444: |
| 146 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::Y, arm_compute::Channel::U, arm_compute::Channel::V); |
| 147 | break; |
| 148 | default: |
| 149 | ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format."); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void arm_compute::error_on_invalid_multi_hog(const char *function, const char *file, const int line, |
| 154 | const arm_compute::IMultiHOG *multi_hog) |
| 155 | { |
| 156 | ARM_COMPUTE_UNUSED(function); |
| 157 | ARM_COMPUTE_UNUSED(file); |
| 158 | ARM_COMPUTE_UNUSED(line); |
| 159 | |
| 160 | ARM_COMPUTE_ERROR_ON_LOC(nullptr == multi_hog, function, file, line); |
| 161 | ARM_COMPUTE_ERROR_ON_LOC(0 == multi_hog->num_models(), function, file, line); |
| 162 | |
| 163 | for(size_t i = 1; i < multi_hog->num_models(); ++i) |
| 164 | { |
| 165 | ARM_COMPUTE_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->phase_type() != multi_hog->model(i)->info()->phase_type(), |
| 166 | function, file, line, |
| 167 | "All HOG parameters must have the same phase type"); |
| 168 | ARM_COMPUTE_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->normalization_type() != multi_hog->model(i)->info()->normalization_type(), |
| 169 | function, file, line, |
| 170 | "All HOG parameters must have the same normalization type"); |
| 171 | ARM_COMPUTE_ERROR_ON_LOC_MSG((multi_hog->model(0)->info()->l2_hyst_threshold() != multi_hog->model(i)->info()->l2_hyst_threshold()) |
| 172 | && (multi_hog->model(0)->info()->normalization_type() == arm_compute::HOGNormType::L2HYS_NORM), |
| 173 | function, file, line, |
| 174 | "All HOG parameters must have the same l2 hysteresis threshold if you use L2 hysteresis normalization type"); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void arm_compute::error_on_unconfigured_kernel(const char *function, const char *file, const int line, |
| 179 | const arm_compute::IKernel *kernel) |
| 180 | { |
| 181 | ARM_COMPUTE_UNUSED(function); |
| 182 | ARM_COMPUTE_UNUSED(file); |
| 183 | ARM_COMPUTE_UNUSED(line); |
| 184 | ARM_COMPUTE_UNUSED(kernel); |
| 185 | |
| 186 | ARM_COMPUTE_ERROR_ON_LOC(kernel == nullptr, function, file, line); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 187 | ARM_COMPUTE_ERROR_ON_LOC_MSG((kernel->window().x().start() == kernel->window().x().end()) && (kernel->window().x().end() == 0) && (kernel->window().x().step() == 0), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 188 | function, file, line, |
| 189 | "This kernel hasn't been configured."); |
| 190 | } |
| 191 | |
| 192 | void arm_compute::error_on_invalid_subtensor(const char *function, const char *file, const int line, |
| 193 | const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape) |
| 194 | { |
| 195 | ARM_COMPUTE_UNUSED(function); |
| 196 | ARM_COMPUTE_UNUSED(file); |
| 197 | ARM_COMPUTE_UNUSED(line); |
| 198 | ARM_COMPUTE_UNUSED(parent_shape); |
| 199 | ARM_COMPUTE_UNUSED(coords); |
| 200 | ARM_COMPUTE_UNUSED(shape); |
| 201 | |
| 202 | // Subtensor should not index in x, y dimensions. |
| 203 | ARM_COMPUTE_ERROR_ON_LOC(((coords.x() != 0) && (coords.y() != 0)), function, file, line); |
| 204 | // Subtensor shape should match parent tensor in x, y dimensions. |
| 205 | ARM_COMPUTE_ERROR_ON_LOC(((parent_shape.x() != shape.x()) && (parent_shape.y() != parent_shape.y())), function, file, line); |
| 206 | |
| 207 | // Check dimensions |
| 208 | for(unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i) |
| 209 | { |
| 210 | ARM_COMPUTE_ERROR_ON_LOC(((coords[i] >= static_cast<int>(parent_shape[i])) || (coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]))), |
| 211 | function, file, line); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | void arm_compute::error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line, |
| 216 | const ValidRegion &parent_valid_region, const ValidRegion &valid_region) |
| 217 | { |
| 218 | ARM_COMPUTE_UNUSED(function); |
| 219 | ARM_COMPUTE_UNUSED(file); |
| 220 | ARM_COMPUTE_UNUSED(line); |
| 221 | ARM_COMPUTE_UNUSED(parent_valid_region); |
| 222 | ARM_COMPUTE_UNUSED(valid_region); |
| 223 | |
| 224 | // Check valid regions |
| 225 | for(unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d) |
| 226 | { |
| 227 | ARM_COMPUTE_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line); |
| 228 | ARM_COMPUTE_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])), |
| 229 | function, file, line); |
| 230 | } |
| 231 | } |