blob: 7636a87e934f0c7fa43a058de8b0082f587023db [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Matthew Bentham92046462020-03-07 22:15:55 +00002 * Copyright (c) 2018-2020 ARM Limited.
giuros01164a2722018-11-20 18:34:46 +00003 *
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 */
giuros011e6e1b82019-05-14 16:12:53 +010024#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
25
giuros01164a2722018-11-20 18:34:46 +000026#include "arm_compute/core/CL/ICLTensor.h"
27#include "arm_compute/core/CL/kernels/CLElementwiseOperationKernel.h"
Matthew Bentham92046462020-03-07 22:15:55 +000028#include "support/MemorySupport.h"
giuros01164a2722018-11-20 18:34:46 +000029
30#include <utility>
31
32namespace arm_compute
33{
34namespace
35{
36void 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 Arena8b2a7d32020-02-11 17:21:31 +000050void CLArithmeticAddition::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000051{
52 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000053 k->configure(ArithmeticOperation::ADD, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000054 _kernel = std::move(k);
55 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
56}
57
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000058Status CLArithmeticAddition::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000059{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000060 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::ADD, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000061}
62
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000063void CLArithmeticSubtraction::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000064{
65 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000066 k->configure(ArithmeticOperation::SUB, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000067 _kernel = std::move(k);
68 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
69}
70
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000071Status CLArithmeticSubtraction::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000072{
73 ARM_COMPUTE_UNUSED(policy);
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000074 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::SUB, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000075}
76
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000077void CLArithmeticDivision::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000078{
79 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000080 k->configure(ArithmeticOperation::DIV, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +000081 _kernel = std::move(k);
82 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
83}
84
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000085Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000086{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000087 return CLArithmeticOperationKernel::validate(ArithmeticOperation::DIV, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +000088}
89
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000090void CLElementwiseMax::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000091{
92 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000093 k->configure(ArithmeticOperation::MAX, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +000094 _kernel = std::move(k);
95 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
96}
97
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000098Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000099{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000100 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000101}
102
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000103void CLElementwiseMin::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000104{
105 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000106 k->configure(ArithmeticOperation::MIN, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000107 _kernel = std::move(k);
108 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
109}
110
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000111Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000112{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000113 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000114}
115
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000116void CLElementwiseSquaredDiff::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000117{
118 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000119 k->configure(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000120 _kernel = std::move(k);
121 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
122}
123
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000124Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000125{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000126 return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000127}
Usama Arif52c54f62019-05-14 10:22:36 +0100128
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000129void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
Usama Arif52c54f62019-05-14 10:22:36 +0100130{
131 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000132 k->configure(ArithmeticOperation::POWER, input1, input2, output, act_info);
Usama Arif52c54f62019-05-14 10:22:36 +0100133 _kernel = std::move(k);
134 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
135}
136
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000137Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Usama Arif52c54f62019-05-14 10:22:36 +0100138{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000139 return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output, act_info);
Usama Arif52c54f62019-05-14 10:22:36 +0100140}
141
giuros01164a2722018-11-20 18:34:46 +0000142} // namespace arm_compute