blob: 20e9545b61e5ece0b7e000aca5e0bd5be41a2f5a [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{
Manuel Bottini2b84be52020-04-08 10:15:51 +010036void configure_border_handler(const CLCompileContext &compile_context, CLFillBorderKernel &border_handler, BorderSize border_size, ICLTensor *input1, ICLTensor *input2, const ICLTensor *output)
giuros01164a2722018-11-20 18:34:46 +000037{
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 {
Manuel Bottini2b84be52020-04-08 10:15:51 +010044 border_handler.configure(compile_context, broadcasted_info, border_size, BorderMode::REPLICATE);
giuros01164a2722018-11-20 18:34:46 +000045 }
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{
Manuel Bottini2b84be52020-04-08 10:15:51 +010052 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, policy, act_info);
53}
54
55void CLArithmeticAddition::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
56{
giuros01164a2722018-11-20 18:34:46 +000057 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010058 k->configure(compile_context, ArithmeticOperation::ADD, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000059 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +010060 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
giuros01164a2722018-11-20 18:34:46 +000061}
62
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000063Status CLArithmeticAddition::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000064{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000065 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::ADD, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000066}
67
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000068void CLArithmeticSubtraction::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000069{
Manuel Bottini2b84be52020-04-08 10:15:51 +010070 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, policy, act_info);
71}
72
73void CLArithmeticSubtraction::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
74{
giuros01164a2722018-11-20 18:34:46 +000075 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010076 k->configure(compile_context, ArithmeticOperation::SUB, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000077 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +010078 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
giuros01164a2722018-11-20 18:34:46 +000079}
80
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000081Status CLArithmeticSubtraction::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000082{
83 ARM_COMPUTE_UNUSED(policy);
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000084 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::SUB, input1, input2, output, policy, act_info);
giuros01164a2722018-11-20 18:34:46 +000085}
86
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000087void CLArithmeticDivision::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +000088{
Manuel Bottini2b84be52020-04-08 10:15:51 +010089 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info);
90}
91
92void CLArithmeticDivision::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
93{
giuros01164a2722018-11-20 18:34:46 +000094 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010095 k->configure(compile_context, ArithmeticOperation::DIV, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +000096 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +010097 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
giuros01164a2722018-11-20 18:34:46 +000098}
99
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000100Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000101{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000102 return CLArithmeticOperationKernel::validate(ArithmeticOperation::DIV, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000103}
104
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000105void CLElementwiseMax::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000106{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100107 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info);
108}
109
110void CLElementwiseMax::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
111{
giuros01164a2722018-11-20 18:34:46 +0000112 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +0100113 k->configure(compile_context, ArithmeticOperation::MAX, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000114 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100115 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
giuros01164a2722018-11-20 18:34:46 +0000116}
117
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000118Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000119{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000120 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000121}
122
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000123void CLElementwiseMin::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000124{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100125 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info);
126}
127
128void CLElementwiseMin::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
129{
giuros01164a2722018-11-20 18:34:46 +0000130 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +0100131 k->configure(compile_context, ArithmeticOperation::MIN, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000132 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100133 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
giuros01164a2722018-11-20 18:34:46 +0000134}
135
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000136Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000137{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000138 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000139}
140
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000141void CLElementwiseSquaredDiff::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000142{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100143 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info);
144}
145
146void CLElementwiseSquaredDiff::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
147{
giuros01164a2722018-11-20 18:34:46 +0000148 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +0100149 k->configure(compile_context, ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000150 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100151 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
giuros01164a2722018-11-20 18:34:46 +0000152}
153
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000154Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
giuros01164a2722018-11-20 18:34:46 +0000155{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000156 return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info);
giuros01164a2722018-11-20 18:34:46 +0000157}
Usama Arif52c54f62019-05-14 10:22:36 +0100158
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000159void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
Usama Arif52c54f62019-05-14 10:22:36 +0100160{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100161 configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info);
162}
163
164void CLElementwisePower::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
165{
Usama Arif52c54f62019-05-14 10:22:36 +0100166 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +0100167 k->configure(compile_context, ArithmeticOperation::POWER, input1, input2, output, act_info);
Usama Arif52c54f62019-05-14 10:22:36 +0100168 _kernel = std::move(k);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100169 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Usama Arif52c54f62019-05-14 10:22:36 +0100170}
171
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000172Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Usama Arif52c54f62019-05-14 10:22:36 +0100173{
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000174 return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output, act_info);
Usama Arif52c54f62019-05-14 10:22:36 +0100175}
176
giuros01164a2722018-11-20 18:34:46 +0000177} // namespace arm_compute