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