Compute Library
 19.08
CLElementwiseOperations.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 ARM Limited.
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  */
25 
29 
30 #include <utility>
31 
32 namespace arm_compute
33 {
34 namespace
35 {
36 void 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 
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 
59 {
61 }
62 
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 
72 {
75 }
76 
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 
85 Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
86 {
88 }
89 
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 
98 Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
99 {
100  return CLArithmeticOperationKernel::validate(ArithmeticOperation::MAX, input1, input2, output);
101 }
102 
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 
111 Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
112 {
113  return CLArithmeticOperationKernel::validate(ArithmeticOperation::MIN, input1, input2, output);
114 }
115 
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 
125 {
127 }
128 
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 
137 Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
138 {
140 }
141 
142 } // namespace arm_compute
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
Static function to check if given info will lead to a valid configuration of CLSaturatedArithmeticOpe...
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
Static function to check if given info will lead to a valid configuration of CLSaturatedArithmeticOpe...
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
Initialise the kernel's inputs, output and conversion policy.
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy)
Initialise the kernel's inputs, output and conversion policy.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
Status class.
Definition: Error.h:52
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLArithmeticDivision.
Copyright (c) 2017-2018 ARM Limited.
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
Initialise the kernel's inputs, output and conversion policy.
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
Initialise the kernel's inputs, output and conversion policy.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy)
Initialise the kernel's inputs, output and conversion policy.
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ConvertPolicy &policy)
Static function to check if given info will lead to a valid configuration of CLSaturatedArithmeticOpe...
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
Initialise the kernel's inputs, output.
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
Pixels outside the image are assumed to have the same value as the closest image pixel.
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
ConvertPolicy
Policy to handle overflow.
Definition: Types.h:349
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output)
Initialise the kernel's inputs, output and conversion policy.