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 | |
| 63 | void arm_compute::error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line, |
| 64 | const arm_compute::Coordinates &pos, unsigned int max_dim) |
| 65 | { |
| 66 | ARM_COMPUTE_UNUSED(function); |
| 67 | ARM_COMPUTE_UNUSED(file); |
| 68 | ARM_COMPUTE_UNUSED(line); |
| 69 | ARM_COMPUTE_UNUSED(pos); |
| 70 | |
| 71 | for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
| 72 | { |
| 73 | ARM_COMPUTE_ERROR_ON_LOC(pos[i] != 0, function, file, line); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void arm_compute::error_on_window_dimensions_gte(const char *function, const char *file, const int line, |
| 78 | const arm_compute::Window &win, unsigned int max_dim) |
| 79 | { |
| 80 | ARM_COMPUTE_UNUSED(function); |
| 81 | ARM_COMPUTE_UNUSED(file); |
| 82 | ARM_COMPUTE_UNUSED(line); |
| 83 | ARM_COMPUTE_UNUSED(win); |
| 84 | |
| 85 | for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i) |
| 86 | { |
| 87 | ARM_COMPUTE_ERROR_ON_LOC_MSG(win[i].start() != 0 || win[i].end() != win[i].step(), |
| 88 | function, file, line, |
| 89 | "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line, |
| 94 | const arm_compute::ITensor *tensor) |
| 95 | { |
| 96 | ARM_COMPUTE_UNUSED(function); |
| 97 | ARM_COMPUTE_UNUSED(file); |
| 98 | ARM_COMPUTE_UNUSED(line); |
| 99 | ARM_COMPUTE_UNUSED(tensor); |
| 100 | |
| 101 | ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 102 | ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor->info()->num_dimensions() != 2, |
| 103 | function, file, line, |
| 104 | "Only 2D Tensors are supported by this kernel (%d passed)", tensor->info()->num_dimensions()); |
| 105 | } |
| 106 | |
| 107 | void arm_compute::error_on_channel_not_in_known_format(const char *function, const char *file, const int line, |
| 108 | arm_compute::Format fmt, arm_compute::Channel cn) |
| 109 | { |
| 110 | ARM_COMPUTE_ERROR_ON_LOC(fmt == arm_compute::Format::UNKNOWN, function, file, line); |
| 111 | ARM_COMPUTE_ERROR_ON_LOC(cn == arm_compute::Channel::UNKNOWN, function, file, line); |
| 112 | |
| 113 | switch(fmt) |
| 114 | { |
| 115 | case arm_compute::Format::RGB888: |
| 116 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::R, arm_compute::Channel::G, arm_compute::Channel::B); |
| 117 | break; |
| 118 | case arm_compute::Format::RGBA8888: |
| 119 | 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); |
| 120 | break; |
| 121 | case arm_compute::Format::UV88: |
| 122 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::U, arm_compute::Channel::V); |
| 123 | break; |
| 124 | case arm_compute::Format::IYUV: |
| 125 | case arm_compute::Format::UYVY422: |
| 126 | case arm_compute::Format::YUYV422: |
| 127 | case arm_compute::Format::NV12: |
| 128 | case arm_compute::Format::NV21: |
| 129 | case arm_compute::Format::YUV444: |
| 130 | arm_compute::error_on_channel_not_in(function, file, line, cn, arm_compute::Channel::Y, arm_compute::Channel::U, arm_compute::Channel::V); |
| 131 | break; |
| 132 | default: |
| 133 | ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format."); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void arm_compute::error_on_invalid_multi_hog(const char *function, const char *file, const int line, |
| 138 | const arm_compute::IMultiHOG *multi_hog) |
| 139 | { |
| 140 | ARM_COMPUTE_UNUSED(function); |
| 141 | ARM_COMPUTE_UNUSED(file); |
| 142 | ARM_COMPUTE_UNUSED(line); |
| 143 | |
| 144 | ARM_COMPUTE_ERROR_ON_LOC(nullptr == multi_hog, function, file, line); |
| 145 | ARM_COMPUTE_ERROR_ON_LOC(0 == multi_hog->num_models(), function, file, line); |
| 146 | |
| 147 | for(size_t i = 1; i < multi_hog->num_models(); ++i) |
| 148 | { |
| 149 | ARM_COMPUTE_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->phase_type() != multi_hog->model(i)->info()->phase_type(), |
| 150 | function, file, line, |
| 151 | "All HOG parameters must have the same phase type"); |
| 152 | ARM_COMPUTE_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->normalization_type() != multi_hog->model(i)->info()->normalization_type(), |
| 153 | function, file, line, |
| 154 | "All HOG parameters must have the same normalization type"); |
| 155 | ARM_COMPUTE_ERROR_ON_LOC_MSG((multi_hog->model(0)->info()->l2_hyst_threshold() != multi_hog->model(i)->info()->l2_hyst_threshold()) |
| 156 | && (multi_hog->model(0)->info()->normalization_type() == arm_compute::HOGNormType::L2HYS_NORM), |
| 157 | function, file, line, |
| 158 | "All HOG parameters must have the same l2 hysteresis threshold if you use L2 hysteresis normalization type"); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void arm_compute::error_on_unconfigured_kernel(const char *function, const char *file, const int line, |
| 163 | const arm_compute::IKernel *kernel) |
| 164 | { |
| 165 | ARM_COMPUTE_UNUSED(function); |
| 166 | ARM_COMPUTE_UNUSED(file); |
| 167 | ARM_COMPUTE_UNUSED(line); |
| 168 | ARM_COMPUTE_UNUSED(kernel); |
| 169 | |
| 170 | ARM_COMPUTE_ERROR_ON_LOC(kernel == nullptr, function, file, line); |
| 171 | ARM_COMPUTE_ERROR_ON_LOC_MSG((kernel->window().x().start() == kernel->window().x().end()) && (kernel->window().x().end() == 0), |
| 172 | function, file, line, |
| 173 | "This kernel hasn't been configured."); |
| 174 | } |
| 175 | |
| 176 | void arm_compute::error_on_invalid_subtensor(const char *function, const char *file, const int line, |
| 177 | const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape) |
| 178 | { |
| 179 | ARM_COMPUTE_UNUSED(function); |
| 180 | ARM_COMPUTE_UNUSED(file); |
| 181 | ARM_COMPUTE_UNUSED(line); |
| 182 | ARM_COMPUTE_UNUSED(parent_shape); |
| 183 | ARM_COMPUTE_UNUSED(coords); |
| 184 | ARM_COMPUTE_UNUSED(shape); |
| 185 | |
| 186 | // Subtensor should not index in x, y dimensions. |
| 187 | ARM_COMPUTE_ERROR_ON_LOC(((coords.x() != 0) && (coords.y() != 0)), function, file, line); |
| 188 | // Subtensor shape should match parent tensor in x, y dimensions. |
| 189 | ARM_COMPUTE_ERROR_ON_LOC(((parent_shape.x() != shape.x()) && (parent_shape.y() != parent_shape.y())), function, file, line); |
| 190 | |
| 191 | // Check dimensions |
| 192 | for(unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i) |
| 193 | { |
| 194 | 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]))), |
| 195 | function, file, line); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void arm_compute::error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line, |
| 200 | const ValidRegion &parent_valid_region, const ValidRegion &valid_region) |
| 201 | { |
| 202 | ARM_COMPUTE_UNUSED(function); |
| 203 | ARM_COMPUTE_UNUSED(file); |
| 204 | ARM_COMPUTE_UNUSED(line); |
| 205 | ARM_COMPUTE_UNUSED(parent_valid_region); |
| 206 | ARM_COMPUTE_UNUSED(valid_region); |
| 207 | |
| 208 | // Check valid regions |
| 209 | for(unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d) |
| 210 | { |
| 211 | ARM_COMPUTE_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line); |
| 212 | 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])), |
| 213 | function, file, line); |
| 214 | } |
| 215 | } |