giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
giuros01 | 164a272 | 2018-11-20 18:34:46 +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 | */ |
giuros01 | 1e6e1b8 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 24 | #include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h" |
| 25 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/CL/ICLTensor.h" |
| 27 | #include "arm_compute/core/CL/kernels/CLElementwiseOperationKernel.h" |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 28 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 29 | #include "support/MemorySupport.h" |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 30 | |
| 31 | #include <utility> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace |
| 36 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 37 | void configure_border_handler(const CLCompileContext &compile_context, CLFillBorderKernel &border_handler, BorderSize border_size, ITensorInfo *input1, ITensorInfo *input2, const ITensorInfo *output) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 38 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 39 | if(output->dimension(0) > 1) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 40 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 41 | ITensorInfo *broadcasted_info = (input1->dimension(0) == 1) ? input1 : input2; |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 42 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 43 | if(broadcasted_info->dimension(0) == 1) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 44 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 45 | border_handler.configure(compile_context, broadcasted_info, border_size, BorderMode::REPLICATE); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 49 | |
| 50 | void select_border_input(InputTensorMap &tensor_map, InputTensorMap &inputs, OutputTensorMap &outputs) |
| 51 | { |
| 52 | if(outputs.at(TensorType::ACL_DST)->info()->dimension(0) > 1) |
| 53 | { |
| 54 | if(inputs.at(TensorType::ACL_SRC_1)->info()->dimension(0) == 1) |
| 55 | { |
| 56 | tensor_map[TensorType::ACL_SRC] = inputs.at(TensorType::ACL_SRC_1); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | tensor_map[TensorType::ACL_SRC] = inputs.at(TensorType::ACL_SRC_0); |
| 61 | } |
| 62 | } |
| 63 | } |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 64 | } // namespace |
| 65 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 66 | namespace experimental |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 67 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 68 | CLArithmeticAddition::CLArithmeticAddition() |
| 69 | : _border_handler() |
| 70 | { |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 73 | void CLArithmeticAddition::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 74 | { |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 75 | auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 76 | k->configure(compile_context, ArithmeticOperation::ADD, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 77 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 78 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 81 | Status CLArithmeticAddition::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 82 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 83 | return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::ADD, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 86 | void CLArithmeticAddition::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 87 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 88 | InputTensorMap src; |
| 89 | select_border_input(src, inputs, outputs); |
| 90 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 91 | ICLOperator::run(inputs, outputs, workspace); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 94 | CLArithmeticSubtraction::CLArithmeticSubtraction() |
| 95 | : _border_handler() |
| 96 | { |
| 97 | } |
| 98 | void CLArithmeticSubtraction::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, ConvertPolicy policy, |
| 99 | const ActivationLayerInfo &act_info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 100 | { |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 101 | auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 102 | k->configure(compile_context, ArithmeticOperation::SUB, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 103 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 104 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 107 | Status CLArithmeticSubtraction::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 108 | { |
| 109 | ARM_COMPUTE_UNUSED(policy); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 110 | return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::SUB, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 113 | void CLArithmeticSubtraction::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 114 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 115 | InputTensorMap src; |
| 116 | select_border_input(src, inputs, outputs); |
| 117 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 118 | ICLOperator::run(inputs, outputs, workspace); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 121 | CLArithmeticDivision::CLArithmeticDivision() |
| 122 | : _border_handler() |
| 123 | { |
| 124 | } |
| 125 | |
| 126 | void CLArithmeticDivision::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] | 127 | { |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 128 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 129 | k->configure(compile_context, ArithmeticOperation::DIV, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 130 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 131 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 134 | Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 135 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 136 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::DIV, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 139 | void CLArithmeticDivision::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 140 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 141 | InputTensorMap src; |
| 142 | select_border_input(src, inputs, outputs); |
| 143 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 144 | ICLOperator::run(inputs, outputs, workspace); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 147 | CLElementwiseMax::CLElementwiseMax() |
| 148 | : _border_handler() |
| 149 | { |
| 150 | } |
| 151 | |
| 152 | void CLElementwiseMax::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] | 153 | { |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 154 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 155 | k->configure(compile_context, ArithmeticOperation::MAX, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 156 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 157 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 160 | Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 161 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 162 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 165 | void CLElementwiseMax::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 166 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 167 | InputTensorMap src; |
| 168 | select_border_input(src, inputs, outputs); |
| 169 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 170 | ICLOperator::run(inputs, outputs, workspace); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 173 | CLElementwiseMin::CLElementwiseMin() |
| 174 | : _border_handler() |
| 175 | { |
| 176 | } |
| 177 | |
| 178 | void CLElementwiseMin::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] | 179 | { |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 180 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 181 | k->configure(compile_context, ArithmeticOperation::MIN, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 182 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 183 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 186 | Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 187 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 188 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 191 | void CLElementwiseMin::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 192 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 193 | InputTensorMap src; |
| 194 | select_border_input(src, inputs, outputs); |
| 195 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 196 | ICLOperator::run(inputs, outputs, workspace); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 199 | CLElementwiseSquaredDiff::CLElementwiseSquaredDiff() |
| 200 | : _border_handler() |
| 201 | { |
| 202 | } |
| 203 | |
| 204 | void CLElementwiseSquaredDiff::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] | 205 | { |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 206 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 207 | k->configure(compile_context, ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 208 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 209 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 212 | Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 213 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 214 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 215 | } |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 216 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 217 | void CLElementwiseSquaredDiff::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 218 | { |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 219 | InputTensorMap src; |
| 220 | select_border_input(src, inputs, outputs); |
| 221 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 222 | ICLOperator::run(inputs, outputs, workspace); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 225 | CLElementwisePower::CLElementwisePower() |
| 226 | : _border_handler() |
| 227 | { |
| 228 | } |
| 229 | |
| 230 | void CLElementwisePower::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] | 231 | { |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 232 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 233 | k->configure(compile_context, ArithmeticOperation::POWER, input1, input2, output, act_info); |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 234 | _kernel = std::move(k); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 235 | configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output); |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 238 | Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 239 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 240 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output, act_info); |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Michalis Spyrou | ad7515d | 2020-07-24 00:02:23 +0100 | [diff] [blame^] | 243 | void CLElementwisePower::run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) |
| 244 | { |
| 245 | InputTensorMap src; |
| 246 | select_border_input(src, inputs, outputs); |
| 247 | CLScheduler::get().enqueue_op(_border_handler, src, {}); |
| 248 | ICLOperator::run(inputs, outputs, workspace); |
| 249 | } |
| 250 | } // namespace experimental |
| 251 | |
| 252 | struct CLArithmeticAddition::Impl |
| 253 | { |
| 254 | const ICLTensor *src_0{ nullptr }; |
| 255 | const ICLTensor *src_1{ nullptr }; |
| 256 | ICLTensor *dst{ nullptr }; |
| 257 | std::unique_ptr<experimental::CLArithmeticAddition> op{ nullptr }; |
| 258 | }; |
| 259 | |
| 260 | CLArithmeticAddition::CLArithmeticAddition() |
| 261 | : _impl(support::cpp14::make_unique<Impl>()) |
| 262 | { |
| 263 | } |
| 264 | CLArithmeticAddition::CLArithmeticAddition(CLArithmeticAddition &&) = default; |
| 265 | CLArithmeticAddition &CLArithmeticAddition::operator=(CLArithmeticAddition &&) = default; |
| 266 | CLArithmeticAddition::~CLArithmeticAddition() = default; |
| 267 | |
| 268 | void CLArithmeticAddition::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
| 269 | { |
| 270 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, policy, act_info); |
| 271 | } |
| 272 | |
| 273 | void CLArithmeticAddition::configure(const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, |
| 274 | const ActivationLayerInfo &act_info) |
| 275 | { |
| 276 | _impl->src_0 = input1; |
| 277 | _impl->src_1 = input2; |
| 278 | _impl->dst = output; |
| 279 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLArithmeticAddition>(); |
| 280 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), policy, act_info); |
| 281 | } |
| 282 | |
| 283 | Status CLArithmeticAddition::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
| 284 | { |
| 285 | return experimental::CLArithmeticAddition::validate(input1, input2, output, policy, act_info); |
| 286 | } |
| 287 | |
| 288 | void CLArithmeticAddition::run() |
| 289 | { |
| 290 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 291 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 292 | |
| 293 | _impl->op->run(src, dst, {}); |
| 294 | } |
| 295 | |
| 296 | struct CLArithmeticSubtraction::Impl |
| 297 | { |
| 298 | const ICLTensor *src_0{ nullptr }; |
| 299 | const ICLTensor *src_1{ nullptr }; |
| 300 | ICLTensor *dst{ nullptr }; |
| 301 | std::unique_ptr<experimental::CLArithmeticSubtraction> op{ nullptr }; |
| 302 | }; |
| 303 | |
| 304 | CLArithmeticSubtraction::CLArithmeticSubtraction() |
| 305 | : _impl(support::cpp14::make_unique<Impl>()) |
| 306 | { |
| 307 | } |
| 308 | CLArithmeticSubtraction::CLArithmeticSubtraction(CLArithmeticSubtraction &&) = default; |
| 309 | CLArithmeticSubtraction &CLArithmeticSubtraction::operator=(CLArithmeticSubtraction &&) = default; |
| 310 | CLArithmeticSubtraction::~CLArithmeticSubtraction() = default; |
| 311 | |
| 312 | void CLArithmeticSubtraction::configure(const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
| 313 | { |
| 314 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, policy, act_info); |
| 315 | } |
| 316 | |
| 317 | void CLArithmeticSubtraction::configure(const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, |
| 318 | const ActivationLayerInfo &act_info) |
| 319 | { |
| 320 | _impl->src_0 = input1; |
| 321 | _impl->src_1 = input2; |
| 322 | _impl->dst = output; |
| 323 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLArithmeticSubtraction>(); |
| 324 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), policy, act_info); |
| 325 | } |
| 326 | |
| 327 | Status CLArithmeticSubtraction::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
| 328 | { |
| 329 | return experimental::CLArithmeticSubtraction::validate(input1, input2, output, policy, act_info); |
| 330 | } |
| 331 | |
| 332 | void CLArithmeticSubtraction::run() |
| 333 | { |
| 334 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 335 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 336 | |
| 337 | _impl->op->run(src, dst, {}); |
| 338 | } |
| 339 | |
| 340 | struct CLArithmeticDivision::Impl |
| 341 | { |
| 342 | const ICLTensor *src_0{ nullptr }; |
| 343 | const ICLTensor *src_1{ nullptr }; |
| 344 | ICLTensor *dst{ nullptr }; |
| 345 | std::unique_ptr<experimental::CLArithmeticDivision> op{ nullptr }; |
| 346 | }; |
| 347 | |
| 348 | CLArithmeticDivision::CLArithmeticDivision() |
| 349 | : _impl(support::cpp14::make_unique<Impl>()) |
| 350 | { |
| 351 | } |
| 352 | CLArithmeticDivision::CLArithmeticDivision(CLArithmeticDivision &&) = default; |
| 353 | CLArithmeticDivision &CLArithmeticDivision::operator=(CLArithmeticDivision &&) = default; |
| 354 | CLArithmeticDivision::~CLArithmeticDivision() = default; |
| 355 | |
| 356 | void CLArithmeticDivision::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 357 | { |
| 358 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 359 | } |
| 360 | |
| 361 | void CLArithmeticDivision::configure(const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 362 | { |
| 363 | _impl->src_0 = input1; |
| 364 | _impl->src_1 = input2; |
| 365 | _impl->dst = output; |
| 366 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLArithmeticDivision>(); |
| 367 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 368 | } |
| 369 | |
| 370 | Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 371 | { |
| 372 | return experimental::CLArithmeticDivision::validate(input1, input2, output, act_info); |
| 373 | } |
| 374 | |
| 375 | void CLArithmeticDivision::run() |
| 376 | { |
| 377 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 378 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 379 | |
| 380 | _impl->op->run(src, dst, {}); |
| 381 | } |
| 382 | |
| 383 | struct CLElementwiseMax::Impl |
| 384 | { |
| 385 | const ICLTensor *src_0{ nullptr }; |
| 386 | const ICLTensor *src_1{ nullptr }; |
| 387 | ICLTensor *dst{ nullptr }; |
| 388 | std::unique_ptr<experimental::CLElementwiseMax> op{ nullptr }; |
| 389 | }; |
| 390 | |
| 391 | CLElementwiseMax::CLElementwiseMax() |
| 392 | : _impl(support::cpp14::make_unique<Impl>()) |
| 393 | { |
| 394 | } |
| 395 | CLElementwiseMax::CLElementwiseMax(CLElementwiseMax &&) = default; |
| 396 | CLElementwiseMax &CLElementwiseMax::operator=(CLElementwiseMax &&) = default; |
| 397 | CLElementwiseMax::~CLElementwiseMax() = default; |
| 398 | |
| 399 | void CLElementwiseMax::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 400 | { |
| 401 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 402 | } |
| 403 | |
| 404 | void CLElementwiseMax::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 405 | { |
| 406 | _impl->src_0 = input1; |
| 407 | _impl->src_1 = input2; |
| 408 | _impl->dst = output; |
| 409 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLElementwiseMax>(); |
| 410 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 411 | } |
| 412 | |
| 413 | Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 414 | { |
| 415 | return experimental::CLElementwiseMax::validate(input1, input2, output, act_info); |
| 416 | } |
| 417 | |
| 418 | void CLElementwiseMax::run() |
| 419 | { |
| 420 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 421 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 422 | |
| 423 | _impl->op->run(src, dst, {}); |
| 424 | } |
| 425 | |
| 426 | struct CLElementwiseMin::Impl |
| 427 | { |
| 428 | const ICLTensor *src_0{ nullptr }; |
| 429 | const ICLTensor *src_1{ nullptr }; |
| 430 | ICLTensor *dst{ nullptr }; |
| 431 | std::unique_ptr<experimental::CLElementwiseMin> op{ nullptr }; |
| 432 | }; |
| 433 | |
| 434 | CLElementwiseMin::CLElementwiseMin() |
| 435 | : _impl(support::cpp14::make_unique<Impl>()) |
| 436 | { |
| 437 | } |
| 438 | CLElementwiseMin::CLElementwiseMin(CLElementwiseMin &&) = default; |
| 439 | CLElementwiseMin &CLElementwiseMin::operator=(CLElementwiseMin &&) = default; |
| 440 | CLElementwiseMin::~CLElementwiseMin() = default; |
| 441 | |
| 442 | void CLElementwiseMin::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 443 | { |
| 444 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 445 | } |
| 446 | |
| 447 | void CLElementwiseMin::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 448 | { |
| 449 | _impl->src_0 = input1; |
| 450 | _impl->src_1 = input2; |
| 451 | _impl->dst = output; |
| 452 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLElementwiseMin>(); |
| 453 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 454 | } |
| 455 | |
| 456 | Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 457 | { |
| 458 | return experimental::CLElementwiseMin::validate(input1, input2, output, act_info); |
| 459 | } |
| 460 | |
| 461 | void CLElementwiseMin::run() |
| 462 | { |
| 463 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 464 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 465 | |
| 466 | _impl->op->run(src, dst, {}); |
| 467 | } |
| 468 | |
| 469 | struct CLElementwiseSquaredDiff::Impl |
| 470 | { |
| 471 | const ICLTensor *src_0{ nullptr }; |
| 472 | const ICLTensor *src_1{ nullptr }; |
| 473 | ICLTensor *dst{ nullptr }; |
| 474 | std::unique_ptr<experimental::CLElementwiseSquaredDiff> op{ nullptr }; |
| 475 | std::unique_ptr<CLFillBorderKernel> _border_handler{ nullptr }; |
| 476 | }; |
| 477 | |
| 478 | CLElementwiseSquaredDiff::CLElementwiseSquaredDiff() |
| 479 | : _impl(support::cpp14::make_unique<Impl>()) |
| 480 | { |
| 481 | } |
| 482 | CLElementwiseSquaredDiff::CLElementwiseSquaredDiff(CLElementwiseSquaredDiff &&) = default; |
| 483 | CLElementwiseSquaredDiff &CLElementwiseSquaredDiff::operator=(CLElementwiseSquaredDiff &&) = default; |
| 484 | CLElementwiseSquaredDiff::~CLElementwiseSquaredDiff() = default; |
| 485 | |
| 486 | void CLElementwiseSquaredDiff::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 487 | { |
| 488 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 489 | } |
| 490 | |
| 491 | void CLElementwiseSquaredDiff::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 492 | { |
| 493 | _impl->src_0 = input1; |
| 494 | _impl->src_1 = input2; |
| 495 | _impl->dst = output; |
| 496 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLElementwiseSquaredDiff>(); |
| 497 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 498 | } |
| 499 | |
| 500 | Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 501 | { |
| 502 | return experimental::CLElementwiseSquaredDiff::validate(input1, input2, output, act_info); |
| 503 | } |
| 504 | |
| 505 | void CLElementwiseSquaredDiff::run() |
| 506 | { |
| 507 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 508 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 509 | |
| 510 | _impl->op->run(src, dst, {}); |
| 511 | } |
| 512 | |
| 513 | struct CLElementwisePower::Impl |
| 514 | { |
| 515 | const ICLTensor *src_0{ nullptr }; |
| 516 | const ICLTensor *src_1{ nullptr }; |
| 517 | ICLTensor *dst{ nullptr }; |
| 518 | std::unique_ptr<experimental::CLElementwisePower> op{ nullptr }; |
| 519 | }; |
| 520 | |
| 521 | CLElementwisePower::CLElementwisePower() |
| 522 | : _impl(support::cpp14::make_unique<Impl>()) |
| 523 | { |
| 524 | } |
| 525 | CLElementwisePower::CLElementwisePower(CLElementwisePower &&) = default; |
| 526 | CLElementwisePower &CLElementwisePower::operator=(CLElementwisePower &&) = default; |
| 527 | CLElementwisePower::~CLElementwisePower() = default; |
| 528 | |
| 529 | void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 530 | { |
| 531 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 532 | } |
| 533 | |
| 534 | void CLElementwisePower::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 535 | { |
| 536 | _impl->src_0 = input1; |
| 537 | _impl->src_1 = input2; |
| 538 | _impl->dst = output; |
| 539 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLElementwisePower>(); |
| 540 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 541 | } |
| 542 | |
| 543 | Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 544 | { |
| 545 | return experimental::CLElementwisePower::validate(input1, input2, output, act_info); |
| 546 | } |
| 547 | |
| 548 | void CLElementwisePower::run() |
| 549 | { |
| 550 | const InputTensorMap src{ { TensorType::ACL_SRC_0, _impl->src_0 }, { TensorType::ACL_SRC_1, _impl->src_1 } }; |
| 551 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 552 | |
| 553 | _impl->op->run(src, dst, {}); |
| 554 | } |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 555 | } // namespace arm_compute |