Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021 Arm Limited. |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [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 "src/core/NEON/kernels/NELogicalKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/Validate.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 29 | #include "src/common/utils/Validate.h" |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 30 | #include "src/core/helpers/AutoConfiguration.h" |
| 31 | #include "src/core/helpers/WindowHelpers.h" |
| 32 | |
| 33 | #include <arm_neon.h> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace kernels |
| 38 | { |
| 39 | namespace |
| 40 | { |
| 41 | static const uint8x8_t c0_x8 = vdup_n_u8(0); |
| 42 | static const uint8x16_t c0_x16 = vdupq_n_u8(0); |
| 43 | static const uint8x8_t c1_x8 = vdup_n_u8(1); |
| 44 | static const uint8x16_t c1_x16 = vdupq_n_u8(1); |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 45 | static const uint32_t step = 16; |
| 46 | static const uint32_t half_step = step / 2; |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 47 | |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 48 | void neon_logical_and(const uint8_t *src0, const uint8_t *src1, uint8_t *dst, uint32_t len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 49 | { |
| 50 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src0); |
| 51 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src1); |
| 52 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 53 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 54 | for (; len >= step; len -= step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 55 | { |
| 56 | vst1q_u8(dst, vandq_u8(vminq_u8(vld1q_u8(src0), c1_x16), vminq_u8(vld1q_u8(src1), c1_x16))); |
| 57 | src0 += step; |
| 58 | src1 += step; |
| 59 | dst += step; |
| 60 | } |
| 61 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 62 | for (; len >= half_step; len -= half_step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 63 | { |
| 64 | vst1_u8(dst, vand_u8(vmin_u8(vld1_u8(src0), c1_x8), vmin_u8(vld1_u8(src1), c1_x8))); |
| 65 | src0 += half_step; |
| 66 | src1 += half_step; |
| 67 | dst += half_step; |
| 68 | } |
| 69 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 70 | for (; len > 0; --len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 71 | { |
| 72 | *dst = (*src0) && (*src1); |
| 73 | ++src0; |
| 74 | ++src1; |
| 75 | ++dst; |
| 76 | } |
| 77 | } |
| 78 | |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 79 | void neon_logical_and_broadcast(const uint8_t *src, uint8_t broadcast_val, uint8_t *dst, uint32_t len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 80 | { |
| 81 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src); |
| 82 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 83 | |
| 84 | const auto broadcast_val_clamped_s = std::min<uint8_t>(broadcast_val, 1); |
| 85 | const auto broadcast_val_clamped_x16 = vdupq_n_u8(broadcast_val_clamped_s); |
| 86 | const auto broadcast_val_clamped_x8 = vdup_n_u8(broadcast_val_clamped_s); |
| 87 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 88 | for (; len >= step; len -= step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 89 | { |
| 90 | vst1q_u8(dst, vandq_u8(vminq_u8(vld1q_u8(src), c1_x16), broadcast_val_clamped_x16)); |
| 91 | src += step; |
| 92 | dst += step; |
| 93 | } |
| 94 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 95 | for (; len >= half_step; len -= half_step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 96 | { |
| 97 | vst1_u8(dst, vand_u8(vmin_u8(vld1_u8(src), c1_x8), broadcast_val_clamped_x8)); |
| 98 | src += half_step; |
| 99 | dst += half_step; |
| 100 | } |
| 101 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 102 | for (; len > 0; --len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 103 | { |
| 104 | *dst = (*src) && broadcast_val_clamped_s; |
| 105 | ++src; |
| 106 | ++dst; |
| 107 | } |
| 108 | } |
| 109 | |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 110 | void neon_logical_or(const uint8_t *src0, const uint8_t *src1, uint8_t *dst, uint32_t len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 111 | { |
| 112 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src0); |
| 113 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src1); |
| 114 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 115 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 116 | for (; len >= step; len -= step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 117 | { |
| 118 | vst1q_u8(dst, vorrq_u8(vminq_u8(vld1q_u8(src0), c1_x16), vminq_u8(vld1q_u8(src1), c1_x16))); |
| 119 | src0 += step; |
| 120 | src1 += step; |
| 121 | dst += step; |
| 122 | } |
| 123 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 124 | for (; len >= half_step; len -= half_step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 125 | { |
| 126 | vst1_u8(dst, vorr_u8(vmin_u8(vld1_u8(src0), c1_x8), vmin_u8(vld1_u8(src1), c1_x8))); |
| 127 | src0 += half_step; |
| 128 | src1 += half_step; |
| 129 | dst += half_step; |
| 130 | } |
| 131 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 132 | for (; len > 0; --len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 133 | { |
| 134 | *dst = (*src0) || (*src1); |
| 135 | ++src0; |
| 136 | ++src1; |
| 137 | ++dst; |
| 138 | } |
| 139 | } |
| 140 | |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 141 | void neon_logical_or_broadcast(const uint8_t *src, uint8_t broadcast_val, uint8_t *dst, uint32_t len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 142 | { |
| 143 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src); |
| 144 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 145 | |
| 146 | const auto broadcast_val_clamped_s = std::min<uint8_t>(broadcast_val, 1); |
| 147 | const auto broadcast_val_clamped_x16 = vdupq_n_u8(broadcast_val_clamped_s); |
| 148 | const auto broadcast_val_clamped_x8 = vdup_n_u8(broadcast_val_clamped_s); |
| 149 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 150 | for (; len >= step; len -= step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 151 | { |
| 152 | vst1q_u8(dst, vorrq_u8(vminq_u8(vld1q_u8(src), c1_x16), broadcast_val_clamped_x16)); |
| 153 | src += step; |
| 154 | dst += step; |
| 155 | } |
| 156 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 157 | for (; len >= half_step; len -= half_step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 158 | { |
| 159 | vst1_u8(dst, vorr_u8(vmin_u8(vld1_u8(src), c1_x8), broadcast_val_clamped_x8)); |
| 160 | src += half_step; |
| 161 | dst += half_step; |
| 162 | } |
| 163 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 164 | for (; len > 0; --len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 165 | { |
| 166 | *dst = (*src) || broadcast_val_clamped_s; |
| 167 | ++src; |
| 168 | ++dst; |
| 169 | } |
| 170 | } |
| 171 | |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 172 | void neon_logical_not(const uint8_t *src, uint8_t *dst, uint32_t len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 173 | { |
| 174 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(src); |
| 175 | ARM_COMPUTE_ASSERT_NOT_NULLPTR(dst); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 176 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 177 | for (; len >= step; len -= step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 178 | { |
| 179 | vst1q_u8(dst, vbslq_u8(vceqq_u8(vld1q_u8(src), c0_x16), c1_x16, c0_x16)); |
| 180 | src += step; |
| 181 | dst += step; |
| 182 | } |
| 183 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 184 | for (; len >= half_step; len -= half_step) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 185 | { |
| 186 | vst1_u8(dst, vbsl_u8(vceq_u8(vld1_u8(src), c0_x8), c1_x8, c0_x8)); |
| 187 | src += half_step; |
| 188 | dst += half_step; |
| 189 | } |
| 190 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 191 | for (; len > 0; --len) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 192 | { |
| 193 | *dst = !(*src); |
| 194 | ++src; |
| 195 | ++dst; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void run_unary(const Window &window, const ITensor *src, ITensor *dst) |
| 200 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 201 | Window win{window}; |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 202 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 203 | const auto len = window.x().end() - window.x().start(); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 204 | |
| 205 | Iterator in(src, win); |
| 206 | Iterator out(dst, win); |
| 207 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 208 | execute_window_loop( |
| 209 | win, [&](const Coordinates &) { neon_logical_not(in.ptr(), out.ptr(), len); }, in, out); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void run_binary(const Window &window, const ITensor *src0, const ITensor *src1, ITensor *dst, LogicalOperation op) |
| 213 | { |
| 214 | Window src0_win = window.broadcast_if_dimension_le_one(src0->info()->tensor_shape()); |
| 215 | Window src1_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
| 216 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 217 | Window win{window}; |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 218 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 219 | |
| 220 | const bool is_broadcast_across_x = src0->info()->tensor_shape().x() != src1->info()->tensor_shape().x(); |
Michalis Spyrou | c89998f | 2021-08-26 14:11:44 +0100 | [diff] [blame] | 221 | const auto len = window.x().end() - window.x().start(); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 222 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 223 | if (is_broadcast_across_x) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 224 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 225 | using LogicalBroadcastUKernelPtr = std::add_pointer<void(const uint8_t *, uint8_t, uint8_t *, uint32_t)>::type; |
| 226 | LogicalBroadcastUKernelPtr logical_func = |
| 227 | op == LogicalOperation::Or ? &neon_logical_or_broadcast : &neon_logical_and_broadcast; |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 228 | |
| 229 | const bool is_broadcast_input_1 = src1_win.x().step() == 0; |
| 230 | Window broadcast_win = is_broadcast_input_1 ? src1_win : src0_win; |
| 231 | Window non_broadcast_win = !is_broadcast_input_1 ? src1_win : src0_win; |
| 232 | const ITensor *broadcast_tensor = is_broadcast_input_1 ? src1 : src0; |
| 233 | const ITensor *non_broadcast_tensor = !is_broadcast_input_1 ? src1 : src0; |
| 234 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 235 | |
| 236 | Iterator broadcast_in(broadcast_tensor, broadcast_win); |
| 237 | Iterator non_broadcast_in(non_broadcast_tensor, non_broadcast_win); |
| 238 | Iterator out(dst, win); |
| 239 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 240 | execute_window_loop( |
| 241 | win, |
| 242 | [&](const Coordinates &) |
| 243 | { |
| 244 | const uint8_t broadcast_value = *broadcast_in.ptr(); |
| 245 | logical_func(non_broadcast_in.ptr(), broadcast_value, out.ptr(), len); |
| 246 | }, |
| 247 | broadcast_in, non_broadcast_in, out); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 248 | } |
| 249 | else |
| 250 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 251 | using LogicalUKernelPtr = std::add_pointer<void(const uint8_t *, const uint8_t *, uint8_t *, uint32_t)>::type; |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 252 | LogicalUKernelPtr logical_func = op == LogicalOperation::Or ? &neon_logical_or : &neon_logical_and; |
| 253 | |
| 254 | src0_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 255 | src1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 256 | |
| 257 | Iterator in0(src0, src0_win); |
| 258 | Iterator in1(src1, src1_win); |
| 259 | Iterator out(dst, win); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 260 | execute_window_loop( |
| 261 | win, [&](const Coordinates &) { logical_func(in0.ptr(), in1.ptr(), out.ptr(), len); }, in0, in1, out); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | } // namespace |
| 265 | const char *NELogicalKernel::name() const |
| 266 | { |
| 267 | return "NELogicalKernel"; |
| 268 | } |
| 269 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 270 | void NELogicalKernel::configure(const ITensorInfo *input1, |
| 271 | const ITensorInfo *input2, |
| 272 | ITensorInfo *output, |
| 273 | LogicalOperation op) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 274 | { |
| 275 | ARM_COMPUTE_ERROR_ON_NULLPTR(input1, output); |
| 276 | ARM_COMPUTE_ERROR_THROW_ON(validate(input1, input2, output, op)); |
| 277 | |
| 278 | _op = op; |
| 279 | |
| 280 | Window win = calculate_max_window(*input1, Steps()); |
| 281 | TensorShape out_shape = input1->tensor_shape(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 282 | if (op != LogicalOperation::Not) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 283 | { |
| 284 | ARM_COMPUTE_ERROR_ON_NULLPTR(input2); |
SiCongLi | c7b1e84 | 2021-02-22 14:28:33 +0000 | [diff] [blame] | 285 | out_shape = TensorShape::broadcast_shape(input1->tensor_shape(), input2->tensor_shape()); |
| 286 | win = calculate_max_window(out_shape, Steps()); |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 287 | } |
| 288 | ICPPKernel::configure(win); |
| 289 | |
| 290 | // Auto initialize if empty |
| 291 | set_shape_if_empty(*output, out_shape); |
| 292 | set_data_type_if_unknown(*output, input1->data_type()); |
| 293 | } |
| 294 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 295 | Status NELogicalKernel::validate(const ITensorInfo *input1, |
| 296 | const ITensorInfo *input2, |
| 297 | const ITensorInfo *output, |
| 298 | LogicalOperation op) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 299 | { |
| 300 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8); |
| 301 | ARM_COMPUTE_RETURN_ERROR_ON(op == LogicalOperation::Unknown); |
| 302 | |
| 303 | TensorShape out_shape = input1->tensor_shape(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 304 | if (op != LogicalOperation::Not) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 305 | { |
| 306 | out_shape = TensorShape::broadcast_shape(input1->tensor_shape(), input2->tensor_shape()); |
| 307 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 308 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input1, input2); |
| 309 | } |
| 310 | |
| 311 | // Checks performed when output is configured |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 312 | if ((output != nullptr) && (output->total_size() != 0)) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 313 | { |
| 314 | ARM_COMPUTE_RETURN_ERROR_ON(detail::have_different_dimensions(out_shape, output->tensor_shape(), 0)); |
| 315 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input1, output); |
| 316 | } |
| 317 | |
| 318 | return Status{}; |
| 319 | } |
| 320 | |
| 321 | void NELogicalKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
| 322 | { |
| 323 | ARM_COMPUTE_UNUSED(info); |
| 324 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 325 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 326 | ARM_COMPUTE_ERROR_ON(tensors.empty()); |
| 327 | |
| 328 | const ITensor *src0 = tensors.get_const_tensor(TensorType::ACL_SRC_0); |
| 329 | const ITensor *src1 = tensors.get_const_tensor(TensorType::ACL_SRC_1); |
| 330 | ITensor *dst = tensors.get_tensor(TensorType::ACL_DST); |
| 331 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 332 | if (_op == LogicalOperation::Not) |
Georgios Pinitas | 58bce68 | 2020-11-13 11:38:58 +0000 | [diff] [blame] | 333 | { |
| 334 | run_unary(window, src0, dst); |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | run_binary(window, src0, src1, dst, _op); |
| 339 | } |
| 340 | } |
| 341 | } // namespace kernels |
| 342 | } // namespace arm_compute |