blob: 20e9545b61e5ece0b7e000aca5e0bd5be41a2f5a [file] [log] [blame]
Jenkins514be652019-02-28 12:25:18 +00001/*
Jenkins6a7771e2020-05-28 11:28:36 +01002 * Copyright (c) 2018-2020 ARM Limited.
Jenkins514be652019-02-28 12:25:18 +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 */
Jenkins975dfe12019-09-02 11:47:54 +010024#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
25
Jenkins514be652019-02-28 12:25:18 +000026#include "arm_compute/core/CL/ICLTensor.h"
27#include "arm_compute/core/CL/kernels/CLElementwiseOperationKernel.h"
Jenkins6a7771e2020-05-28 11:28:36 +010028#include "support/MemorySupport.h"
Jenkins514be652019-02-28 12:25:18 +000029
30#include <utility>
31
32namespace arm_compute
33{
34namespace
35{
Jenkins6a7771e2020-05-28 11:28:36 +010036void configure_border_handler(const CLCompileContext &compile_context, CLFillBorderKernel &border_handler, BorderSize border_size, ICLTensor *input1, ICLTensor *input2, const ICLTensor *output)
Jenkins514be652019-02-28 12:25:18 +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 {
Jenkins6a7771e2020-05-28 11:28:36 +010044 border_handler.configure(compile_context, broadcasted_info, border_size, BorderMode::REPLICATE);
Jenkins514be652019-02-28 12:25:18 +000045 }
46 }
47}
48} // namespace
49
Jenkins6a7771e2020-05-28 11:28:36 +010050void CLArithmeticAddition::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
51{
52 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)
Jenkins514be652019-02-28 12:25:18 +000056{
57 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +010058 k->configure(compile_context, ArithmeticOperation::ADD, input1, input2, output, policy, act_info);
Jenkins514be652019-02-28 12:25:18 +000059 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +010060 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins514be652019-02-28 12:25:18 +000061}
62
Jenkins6a7771e2020-05-28 11:28:36 +010063Status CLArithmeticAddition::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
Jenkins514be652019-02-28 12:25:18 +000064{
Jenkins6a7771e2020-05-28 11:28:36 +010065 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::ADD, input1, input2, output, policy, act_info);
Jenkins514be652019-02-28 12:25:18 +000066}
67
Jenkins6a7771e2020-05-28 11:28:36 +010068void CLArithmeticSubtraction::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
69{
70 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)
Jenkins514be652019-02-28 12:25:18 +000074{
75 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +010076 k->configure(compile_context, ArithmeticOperation::SUB, input1, input2, output, policy, act_info);
Jenkins514be652019-02-28 12:25:18 +000077 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +010078 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins514be652019-02-28 12:25:18 +000079}
80
Jenkins6a7771e2020-05-28 11:28:36 +010081Status CLArithmeticSubtraction::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info)
Jenkins514be652019-02-28 12:25:18 +000082{
83 ARM_COMPUTE_UNUSED(policy);
Jenkins6a7771e2020-05-28 11:28:36 +010084 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::SUB, input1, input2, output, policy, act_info);
Jenkins514be652019-02-28 12:25:18 +000085}
86
Jenkins6a7771e2020-05-28 11:28:36 +010087void CLArithmeticDivision::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
88{
89 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)
Jenkins514be652019-02-28 12:25:18 +000093{
94 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +010095 k->configure(compile_context, ArithmeticOperation::DIV, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +000096 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +010097 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins514be652019-02-28 12:25:18 +000098}
99
Jenkins6a7771e2020-05-28 11:28:36 +0100100Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Jenkins514be652019-02-28 12:25:18 +0000101{
Jenkins6a7771e2020-05-28 11:28:36 +0100102 return CLArithmeticOperationKernel::validate(ArithmeticOperation::DIV, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000103}
104
Jenkins6a7771e2020-05-28 11:28:36 +0100105void CLElementwiseMax::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
106{
107 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)
Jenkins514be652019-02-28 12:25:18 +0000111{
112 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +0100113 k->configure(compile_context, ArithmeticOperation::MAX, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000114 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +0100115 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins514be652019-02-28 12:25:18 +0000116}
117
Jenkins6a7771e2020-05-28 11:28:36 +0100118Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Jenkins514be652019-02-28 12:25:18 +0000119{
Jenkins6a7771e2020-05-28 11:28:36 +0100120 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000121}
122
Jenkins6a7771e2020-05-28 11:28:36 +0100123void CLElementwiseMin::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
124{
125 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)
Jenkins514be652019-02-28 12:25:18 +0000129{
130 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +0100131 k->configure(compile_context, ArithmeticOperation::MIN, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000132 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +0100133 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins514be652019-02-28 12:25:18 +0000134}
135
Jenkins6a7771e2020-05-28 11:28:36 +0100136Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Jenkins514be652019-02-28 12:25:18 +0000137{
Jenkins6a7771e2020-05-28 11:28:36 +0100138 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000139}
140
Jenkins6a7771e2020-05-28 11:28:36 +0100141void CLElementwiseSquaredDiff::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
142{
143 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)
Jenkins514be652019-02-28 12:25:18 +0000147{
148 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +0100149 k->configure(compile_context, ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000150 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +0100151 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins514be652019-02-28 12:25:18 +0000152}
153
Jenkins6a7771e2020-05-28 11:28:36 +0100154Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Jenkins514be652019-02-28 12:25:18 +0000155{
Jenkins6a7771e2020-05-28 11:28:36 +0100156 return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info);
Jenkins514be652019-02-28 12:25:18 +0000157}
Jenkins975dfe12019-09-02 11:47:54 +0100158
Jenkins6a7771e2020-05-28 11:28:36 +0100159void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
160{
161 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)
Jenkins975dfe12019-09-02 11:47:54 +0100165{
166 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Jenkins6a7771e2020-05-28 11:28:36 +0100167 k->configure(compile_context, ArithmeticOperation::POWER, input1, input2, output, act_info);
Jenkins975dfe12019-09-02 11:47:54 +0100168 _kernel = std::move(k);
Jenkins6a7771e2020-05-28 11:28:36 +0100169 configure_border_handler(compile_context, _border_handler, _kernel->border_size(), input1, input2, output);
Jenkins975dfe12019-09-02 11:47:54 +0100170}
171
Jenkins6a7771e2020-05-28 11:28:36 +0100172Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Jenkins975dfe12019-09-02 11:47:54 +0100173{
Jenkins6a7771e2020-05-28 11:28:36 +0100174 return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output, act_info);
Jenkins975dfe12019-09-02 11:47:54 +0100175}
176
Jenkins514be652019-02-28 12:25:18 +0000177} // namespace arm_compute