giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [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" |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 28 | #include "support/MemorySupport.h" |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 29 | |
| 30 | #include <utility> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace |
| 35 | { |
| 36 | void configure_border_handler(CLFillBorderKernel &border_handler, BorderSize border_size, ICLTensor *input1, ICLTensor *input2, const ICLTensor *output) |
| 37 | { |
| 38 | if(output->info()->dimension(0) > 1) |
| 39 | { |
| 40 | ICLTensor *broadcasted_info = (input1->info()->dimension(0) == 1) ? input1 : input2; |
| 41 | |
| 42 | if(broadcasted_info->info()->dimension(0) == 1) |
| 43 | { |
| 44 | border_handler.configure(broadcasted_info, border_size, BorderMode::REPLICATE); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } // namespace |
| 49 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 50 | void CLArithmeticAddition::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 51 | { |
| 52 | auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 53 | k->configure(ArithmeticOperation::ADD, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 54 | _kernel = std::move(k); |
| 55 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 56 | } |
| 57 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 58 | 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] | 59 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 60 | return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::ADD, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 63 | void CLArithmeticSubtraction::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 64 | { |
| 65 | auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 66 | k->configure(ArithmeticOperation::SUB, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 67 | _kernel = std::move(k); |
| 68 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 69 | } |
| 70 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 71 | 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] | 72 | { |
| 73 | ARM_COMPUTE_UNUSED(policy); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 74 | return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::SUB, input1, input2, output, policy, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 77 | void CLArithmeticDivision::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 78 | { |
| 79 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 80 | k->configure(ArithmeticOperation::DIV, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 81 | _kernel = std::move(k); |
| 82 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 83 | } |
| 84 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 85 | 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] | 86 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 87 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::DIV, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 90 | void CLElementwiseMax::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 91 | { |
| 92 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 93 | k->configure(ArithmeticOperation::MAX, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 94 | _kernel = std::move(k); |
| 95 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 96 | } |
| 97 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 98 | 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] | 99 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 100 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 103 | void CLElementwiseMin::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 104 | { |
| 105 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 106 | k->configure(ArithmeticOperation::MIN, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 107 | _kernel = std::move(k); |
| 108 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 109 | } |
| 110 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 111 | 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] | 112 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 113 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 116 | void CLElementwiseSquaredDiff::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 117 | { |
| 118 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 119 | k->configure(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 120 | _kernel = std::move(k); |
| 121 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 122 | } |
| 123 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 124 | 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] | 125 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 126 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 127 | } |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 128 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 129 | void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 130 | { |
| 131 | auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>(); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 132 | k->configure(ArithmeticOperation::POWER, input1, input2, output, act_info); |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 133 | _kernel = std::move(k); |
| 134 | configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output); |
| 135 | } |
| 136 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 137 | 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] | 138 | { |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 139 | return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output, act_info); |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 140 | } |
| 141 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 142 | } // namespace arm_compute |