blob: 8317e0d938a82b6fd9149a8efea2e9eb8c2b9620 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Usama Arif52c54f62019-05-14 10:22:36 +01002 * Copyright (c) 2018-2019 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"
28#include "support/ToolchainSupport.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
50void CLArithmeticAddition::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy)
51{
52 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
53 k->configure(ArithmeticOperation::ADD, input1, input2, output, policy);
54 _kernel = std::move(k);
55 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
56}
57
58Status CLArithmeticAddition::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
59{
60 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::ADD, input1, input2, output, policy);
61}
62
63void CLArithmeticSubtraction::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy)
64{
65 auto k = arm_compute::support::cpp14::make_unique<CLSaturatedArithmeticOperationKernel>();
66 k->configure(ArithmeticOperation::SUB, input1, input2, output, policy);
67 _kernel = std::move(k);
68 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
69}
70
71Status CLArithmeticSubtraction::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
72{
73 ARM_COMPUTE_UNUSED(policy);
74 return CLSaturatedArithmeticOperationKernel::validate(ArithmeticOperation::SUB, input1, input2, output, policy);
75}
76
77void CLArithmeticDivision::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
78{
79 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
80 k->configure(ArithmeticOperation::DIV, input1, input2, output);
81 _kernel = std::move(k);
82 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
83}
84
85Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
86{
87 return CLArithmeticOperationKernel::validate(ArithmeticOperation::DIV, input1, input2, output);
88}
89
90void CLElementwiseMax::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
91{
92 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
93 k->configure(ArithmeticOperation::MAX, input1, input2, output);
94 _kernel = std::move(k);
95 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
96}
97
98Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
99{
100 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output);
101}
102
103void CLElementwiseMin::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
104{
105 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
106 k->configure(ArithmeticOperation::MIN, input1, input2, output);
107 _kernel = std::move(k);
108 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
109}
110
111Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
112{
113 return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output);
114}
115
116void CLElementwiseSquaredDiff::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
117{
118 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
119 k->configure(ArithmeticOperation::SQUARED_DIFF, input1, input2, output);
120 _kernel = std::move(k);
121 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
122}
123
124Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
125{
126 return CLArithmeticOperationKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output);
127}
Usama Arif52c54f62019-05-14 10:22:36 +0100128
129void CLElementwisePower::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
130{
131 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
132 k->configure(ArithmeticOperation::POWER, input1, input2, output);
133 _kernel = std::move(k);
134 configure_border_handler(_border_handler, _kernel->border_size(), input1, input2, output);
135}
136
137Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
138{
139 return CLArithmeticOperationKernel::validate(ArithmeticOperation::POWER, input1, input2, output);
140}
141
giuros01164a2722018-11-20 18:34:46 +0000142} // namespace arm_compute