Compute Library
 21.11
CpuElementwise.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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 #include "src/common/utils/Log.h"
28 
29 namespace arm_compute
30 {
31 namespace cpu
32 {
34 {
35  // If the kernel has been configured, use the window from the kernel.
36  if(_kernel->is_window_configured())
37  {
38  ICpuOperator::run(tensors);
39  return;
40  }
41 
42  auto src0_info = tensors.get_const_tensor(TensorType::ACL_SRC_0)->info();
43  auto src1_info = tensors.get_const_tensor(TensorType::ACL_SRC_1)->info();
44  auto shape_and_window = compute_output_shape_and_window(src0_info->tensor_shape(), src1_info->tensor_shape());
45  ICpuOperator::run(tensors, shape_and_window.second);
46 }
47 
48 template <ArithmeticOperation op>
50 {
51  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
52  auto k = std::make_unique<kernels::CpuArithmeticKernel>();
53  k->configure(op, src0, src1, dst);
54  _kernel = std::move(k);
55 }
56 
57 template <ArithmeticOperation op>
59 {
60  return kernels::CpuArithmeticKernel::validate(op, src0, src1, dst);
61 }
62 
67 
69 {
70  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
71  auto k = std::make_unique<kernels::CpuDivisionKernel>();
72  k->configure(src0, src1, dst);
73  _kernel = std::move(k);
74 }
75 
77 {
78  return kernels::CpuDivisionKernel::validate(src0, src1, dst);
79 }
80 
82 {
83  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
84  auto k = std::make_unique<kernels::CpuPowerKernel>();
85  k->configure(src0, src1, dst);
86  _kernel = std::move(k);
87 }
88 
90 {
91  return kernels::CpuPowerKernel::validate(src0, src1, dst);
92 }
93 
94 template <ComparisonOperation COP>
96 {
97  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
98  auto k = std::make_unique<kernels::CpuComparisonKernel>();
99  k->configure(COP, src0, src1, dst);
100  _kernel = std::move(k);
101 }
102 
103 template <ComparisonOperation COP>
105 {
106  return kernels::CpuComparisonKernel::validate(COP, src0, src1, dst);
107 }
108 
110 {
111  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
112  auto k = std::make_unique<kernels::CpuComparisonKernel>();
113  k->configure(op, src0, src1, dst);
114  _kernel = std::move(k);
115 }
116 
118 {
119  return kernels::CpuComparisonKernel::validate(op, src0, src1, dst);
120 }
121 
122 // Supported Specializations
129 } // namespace cpu
130 } // namespace arm_compute
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst, ComparisonOperation op)
Static function to check if given info will lead to a valid configuration.
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Initialise the kernel&#39;s inputs, dst and conversion policy.
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Initialise the kernel&#39;s inputs, dst and conversion policy.
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Initialise the kernel&#39;s inputs, dst and conversion policy.
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Copyright (c) 2017-2021 Arm Limited.
static Status validate(ArithmeticOperation op, const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: INEOperator.cpp:40
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
ComparisonOperation
Supported comparison operations.
Definition: Types.h:173
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
Basic function to run cpu::kernels::CpuComparisonKernel.
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
Class to run cpu::kernels::CpuArithmeticKernel except for division and power.
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ComparisonOperation op)
Initialise the kernel&#39;s inputs, dst and conversion policy.
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_LOG_PARAMS(...)
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Configure the operator.
static Status validate(ComparisonOperation op, const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.