Compute Library
 23.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 
26 #include "src/common/utils/Log.h"
29 
30 namespace arm_compute
31 {
32 namespace cpu
33 {
35 {
36  // If the kernel has been configured, use the window from the kernel.
37  if (_kernel->is_window_configured())
38  {
39  ICpuOperator::run(tensors);
40  return;
41  }
42 
43  auto src0_info = tensors.get_const_tensor(TensorType::ACL_SRC_0)->info();
44  auto src1_info = tensors.get_const_tensor(TensorType::ACL_SRC_1)->info();
45  auto shape_and_window = compute_output_shape_and_window(src0_info->tensor_shape(), src1_info->tensor_shape());
46  ICpuOperator::run(tensors, shape_and_window.second);
47 }
48 
49 template <ArithmeticOperation op>
51 {
52  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
53  auto k = std::make_unique<kernels::CpuArithmeticKernel>();
54  k->configure(op, src0, src1, dst);
55  _kernel = std::move(k);
56 }
57 
58 template <ArithmeticOperation op>
60 {
61  return kernels::CpuArithmeticKernel::validate(op, src0, src1, dst);
62 }
63 
68 
70 {
71  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
72  auto k = std::make_unique<kernels::CpuDivisionKernel>();
73  k->configure(src0, src1, dst);
74  _kernel = std::move(k);
75 }
76 
78 {
79  return kernels::CpuDivisionKernel::validate(src0, src1, dst);
80 }
81 
83 {
84  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
85  auto k = std::make_unique<kernels::CpuPowerKernel>();
86  k->configure(src0, src1, dst);
87  _kernel = std::move(k);
88 }
89 
91 {
92  return kernels::CpuPowerKernel::validate(src0, src1, dst);
93 }
94 
95 template <ComparisonOperation COP>
97 {
98  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
99  auto k = std::make_unique<kernels::CpuComparisonKernel>();
100  k->configure(COP, src0, src1, dst);
101  _kernel = std::move(k);
102 }
103 
104 template <ComparisonOperation COP>
105 Status
107 {
108  return kernels::CpuComparisonKernel::validate(COP, src0, src1, dst);
109 }
110 
112  const ITensorInfo *src1,
113  ITensorInfo *dst,
115 {
116  ARM_COMPUTE_LOG_PARAMS(src0, src1, dst);
117  auto k = std::make_unique<kernels::CpuComparisonKernel>();
118  k->configure(op, src0, src1, dst);
119  _kernel = std::move(k);
120 }
121 
123  const ITensorInfo *src1,
124  const ITensorInfo *dst,
126 {
127  return kernels::CpuComparisonKernel::validate(op, src0, src1, dst);
128 }
129 
130 // Supported Specializations
137 } // namespace cpu
138 } // namespace arm_compute
CpuElementwiseKernel.h
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
arm_compute::cpu::CpuElementwiseComparisonStatic::configure
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Initialise the kernel's inputs, dst and conversion policy.
Definition: CpuElementwise.cpp:96
arm_compute::cpu::kernels::CpuArithmeticKernel::validate
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.
Definition: CpuElementwiseKernel.cpp:338
arm_compute::cpu::CpuElementwiseComparisonStatic
Basic function to run cpu::kernels::CpuComparisonKernel.
Definition: CpuElementwise.h:152
arm_compute::cpu::kernels::CpuComparisonKernel::validate
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.
Definition: CpuElementwiseKernel.cpp:499
CpuElementwise.h
arm_compute::cpu::CpuElementwiseArithmetic::validate
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.
Definition: CpuElementwise.cpp:59
arm_compute::ACL_SRC_0
@ ACL_SRC_0
Definition: Types.h:45
arm_compute::ACL_SRC_1
@ ACL_SRC_1
Definition: Types.h:46
arm_compute::ITensor::info
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
arm_compute::ITensorPack::get_const_tensor
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:53
arm_compute::ITensorPack
Tensor packing service.
Definition: ITensorPack.h:39
arm_compute::ComparisonOperation
ComparisonOperation
Supported comparison operations.
Definition: Types.h:132
arm_compute::Status
Status class.
Definition: Error.h:52
WindowHelpers.h
arm_compute::cpu::CpuElementwisePower::validate
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.
Definition: CpuElementwise.cpp:90
arm_compute::cpu::CpuElementwiseArithmetic::configure
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Configure the operator.
Definition: CpuElementwise.cpp:50
arm_compute::cpu::CpuElementwiseComparison::validate
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.
Definition: CpuElementwise.cpp:122
arm_compute::cpu::kernels::CpuDivisionKernel::validate
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.
Definition: CpuElementwiseKernel.cpp:447
arm_compute::cpu::kernels::CpuPowerKernel::validate
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.
Definition: CpuElementwiseKernel.cpp:468
arm_compute::cpu::CpuElementwiseComparisonStatic::validate
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.
Definition: CpuElementwise.cpp:106
arm_compute::cpu::CpuElementwiseBase::run
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: CpuElementwise.cpp:34
arm_compute::experimental::INEOperator::run
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: INEOperator.cpp:41
arm_compute::cpu::CpuElementwiseDivision::configure
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Initialise the kernel's inputs, dst and conversion policy.
Definition: CpuElementwise.cpp:69
arm_compute::cpu::CpuElementwisePower::configure
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst)
Initialise the kernel's inputs, dst and conversion policy.
Definition: CpuElementwise.cpp:82
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::cpu::CpuElementwiseArithmetic
Class to run cpu::kernels::CpuArithmeticKernel except for division and power.
Definition: CpuElementwise.h:45
arm_compute::cpu::CpuElementwiseComparison::configure
void configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ComparisonOperation op)
Initialise the kernel's inputs, dst and conversion policy.
Definition: CpuElementwise.cpp:111
Log.h
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:44
arm_compute::cpu::CpuElementwiseDivision::validate
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.
Definition: CpuElementwise.cpp:77
ARM_COMPUTE_LOG_PARAMS
#define ARM_COMPUTE_LOG_PARAMS(...)
Definition: Log.h:35