Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 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/runtime/CL/functions/CLPixelWiseMultiplication.h" |
| 25 | |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/CL/ICLTensor.h" |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 28 | #include "src/core/CL/kernels/CLFillBorderKernel.h" |
| 29 | #include "src/core/CL/kernels/CLPixelWiseMultiplicationKernel.h" |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 30 | #include "support/MemorySupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | |
| 32 | #include <utility> |
| 33 | |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 34 | namespace arm_compute |
| 35 | { |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 36 | namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 38 | ITensorPack select_border_input(ITensorPack &tensors) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 39 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 40 | ITensorPack pack; |
| 41 | if(tensors.get_tensor(TensorType::ACL_DST)->info()->dimension(0) > 1) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 42 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 43 | if(tensors.get_const_tensor(TensorType::ACL_SRC_1)->info()->dimension(0) == 1) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 44 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 45 | pack.add_tensor(TensorType::ACL_SRC, tensors.get_const_tensor(TensorType::ACL_SRC_1)); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 46 | } |
| 47 | else |
| 48 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 49 | pack.add_tensor(TensorType::ACL_SRC, tensors.get_const_tensor(TensorType::ACL_SRC_0)); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 50 | } |
| 51 | } |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 52 | return pack; |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 53 | } |
| 54 | } // namespace |
| 55 | |
| 56 | namespace experimental |
| 57 | { |
| 58 | CLPixelWiseMultiplication::CLPixelWiseMultiplication() |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 59 | : _border_handler(support::cpp14::make_unique<CLFillBorderKernel>()) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 60 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 63 | void CLPixelWiseMultiplication::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 64 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 65 | { |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 66 | auto k = arm_compute::support::cpp14::make_unique<CLPixelWiseMultiplicationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 67 | k->configure(compile_context, input1, input2, output, scale, overflow_policy, rounding_policy, act_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | _kernel = std::move(k); |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 69 | |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 70 | if(output->dimension(0) > 1) |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 71 | { |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 72 | ITensorInfo *broadcasted_info = (input1->dimension(0) == 1) ? input1 : input2; |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 73 | |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 74 | if(broadcasted_info->dimension(0) == 1) |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 75 | { |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 76 | _border_handler->configure(compile_context, broadcasted_info, _kernel->border_size(), BorderMode::REPLICATE); |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | } |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 80 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 81 | Status CLPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 82 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 83 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 84 | return CLPixelWiseMultiplicationKernel::validate(input1, input2, output, scale, overflow_policy, rounding_policy, act_info); |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 85 | } |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 86 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 87 | void CLPixelWiseMultiplication::run(ITensorPack &tensors) |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 88 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 89 | auto border_pack = select_border_input(tensors); |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 90 | CLScheduler::get().enqueue_op(*_border_handler, border_pack); |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 91 | ICLOperator::run(tensors); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 94 | CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication() |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 95 | : _border_handler(support::cpp14::make_unique<CLFillBorderKernel>()) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 96 | { |
| 97 | } |
| 98 | |
| 99 | void CLComplexPixelWiseMultiplication::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 100 | { |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 101 | auto k = arm_compute::support::cpp14::make_unique<CLComplexPixelWiseMultiplicationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 102 | k->configure(compile_context, input1, input2, output, act_info); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 103 | _kernel = std::move(k); |
| 104 | |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 105 | if(output->dimension(0) > 1) |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 106 | { |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 107 | ITensorInfo *broadcasted_info = (input1->dimension(0) == 1) ? input1 : input2; |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 108 | |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 109 | if(broadcasted_info->dimension(0) == 1) |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 110 | { |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 111 | _border_handler->configure(compile_context, broadcasted_info, _kernel->border_size(), BorderMode::REPLICATE); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 116 | Status CLComplexPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 117 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 118 | return CLComplexPixelWiseMultiplicationKernel::validate(input1, input2, output, act_info); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 119 | } |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 120 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 121 | void CLComplexPixelWiseMultiplication::run(ITensorPack &tensors) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 122 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 123 | auto border_pack = select_border_input(tensors); |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame^] | 124 | CLScheduler::get().enqueue_op(*_border_handler, border_pack); |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 125 | ICLOperator::run(tensors); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 126 | } |
| 127 | } // namespace experimental |
| 128 | |
| 129 | struct CLPixelWiseMultiplication::Impl |
| 130 | { |
| 131 | const ICLTensor *src_0{ nullptr }; |
| 132 | const ICLTensor *src_1{ nullptr }; |
| 133 | ICLTensor *dst{ nullptr }; |
| 134 | std::unique_ptr<experimental::CLPixelWiseMultiplication> op{ nullptr }; |
| 135 | }; |
| 136 | |
| 137 | CLPixelWiseMultiplication::CLPixelWiseMultiplication() |
| 138 | : _impl(support::cpp14::make_unique<Impl>()) |
| 139 | { |
| 140 | } |
| 141 | CLPixelWiseMultiplication::CLPixelWiseMultiplication(CLPixelWiseMultiplication &&) = default; |
| 142 | CLPixelWiseMultiplication &CLPixelWiseMultiplication::operator=(CLPixelWiseMultiplication &&) = default; |
| 143 | CLPixelWiseMultiplication::~CLPixelWiseMultiplication() = default; |
| 144 | |
| 145 | void CLPixelWiseMultiplication::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, float scale, |
| 146 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 147 | { |
| 148 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, scale, overflow_policy, rounding_policy, act_info); |
| 149 | } |
| 150 | |
| 151 | void CLPixelWiseMultiplication::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, float scale, |
| 152 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 153 | { |
| 154 | _impl->src_0 = input1; |
| 155 | _impl->src_1 = input2; |
| 156 | _impl->dst = output; |
| 157 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLPixelWiseMultiplication>(); |
| 158 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), scale, overflow_policy, rounding_policy, act_info); |
| 159 | } |
| 160 | |
| 161 | Status CLPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, |
| 162 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 163 | { |
| 164 | return experimental::CLPixelWiseMultiplication::validate(input1, input2, output, scale, overflow_policy, rounding_policy, act_info); |
| 165 | } |
| 166 | |
| 167 | void CLPixelWiseMultiplication::run() |
| 168 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 169 | ITensorPack pack; |
| 170 | pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0); |
| 171 | pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1); |
| 172 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 173 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 174 | _impl->op->run(pack); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | struct CLComplexPixelWiseMultiplication::Impl |
| 178 | { |
| 179 | const ICLTensor *src_0{ nullptr }; |
| 180 | const ICLTensor *src_1{ nullptr }; |
| 181 | ICLTensor *dst{ nullptr }; |
| 182 | std::unique_ptr<experimental::CLComplexPixelWiseMultiplication> op{ nullptr }; |
| 183 | }; |
| 184 | |
| 185 | CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication() |
| 186 | : _impl(support::cpp14::make_unique<Impl>()) |
| 187 | { |
| 188 | } |
| 189 | CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication(CLComplexPixelWiseMultiplication &&) = default; |
| 190 | CLComplexPixelWiseMultiplication &CLComplexPixelWiseMultiplication::operator=(CLComplexPixelWiseMultiplication &&) = default; |
| 191 | CLComplexPixelWiseMultiplication::~CLComplexPixelWiseMultiplication() = default; |
| 192 | |
| 193 | void CLComplexPixelWiseMultiplication::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 194 | { |
| 195 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 196 | } |
| 197 | |
| 198 | void CLComplexPixelWiseMultiplication::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 199 | { |
| 200 | _impl->src_0 = input1; |
| 201 | _impl->src_1 = input2; |
| 202 | _impl->dst = output; |
| 203 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLComplexPixelWiseMultiplication>(); |
| 204 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 205 | } |
| 206 | |
| 207 | Status CLComplexPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 208 | { |
| 209 | return experimental::CLComplexPixelWiseMultiplication::validate(input1, input2, output, act_info); |
| 210 | } |
| 211 | |
| 212 | void CLComplexPixelWiseMultiplication::run() |
| 213 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 214 | ITensorPack pack; |
| 215 | pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0); |
| 216 | pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1); |
| 217 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 218 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 219 | _impl->op->run(pack); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 220 | } |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 221 | } // namespace arm_compute |