blob: 322bd09c437059f2326525f60360bc27f46f120f [file] [log] [blame]
Sang-Hoon Park63001ac2021-01-18 14:20:27 +00001/*
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 */
24#include "src/runtime/cpu/operators/CpuElementwise.h"
25#include "src/core/cpu/kernels/CpuElementwiseKernel.h"
26
27namespace arm_compute
28{
29namespace cpu
30{
31void CpuElementwiseMax::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output)
32{
33 auto k = std::make_unique<kernels::CpuArithmeticKernel>();
34 k->configure(ArithmeticOperation::MAX, input1, input2, output);
35 _kernel = std::move(k);
36}
37
38Status CpuElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
39{
40 return kernels::CpuArithmeticKernel::validate(ArithmeticOperation::MAX, input1, input2, output);
41}
42
43void CpuElementwiseMin::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output)
44{
45 auto k = std::make_unique<kernels::CpuArithmeticKernel>();
46 k->configure(ArithmeticOperation::MIN, input1, input2, output);
47 _kernel = std::move(k);
48}
49
50Status CpuElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
51{
52 return kernels::CpuArithmeticKernel::validate(ArithmeticOperation::MIN, input1, input2, output);
53}
54
55void CpuElementwiseSquaredDiff::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output)
56{
57 auto k = std::make_unique<kernels::CpuArithmeticKernel>();
58 k->configure(ArithmeticOperation::SQUARED_DIFF, input1, input2, output);
59 _kernel = std::move(k);
60}
61
62Status CpuElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
63{
64 return kernels::CpuArithmeticKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output);
65}
66
67void CpuElementwiseDivision::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output)
68{
69 auto k = std::make_unique<kernels::CpuDivisionKernel>();
70 k->configure(input1, input2, output);
71 _kernel = std::move(k);
72}
73
74Status CpuElementwiseDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
75{
76 return kernels::CpuDivisionKernel::validate(input1, input2, output);
77}
78
79void CpuElementwisePower::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output)
80{
81 auto k = std::make_unique<kernels::CpuPowerKernel>();
82 k->configure(input1, input2, output);
83 _kernel = std::move(k);
84}
85
86Status CpuElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
87{
88 return kernels::CpuPowerKernel::validate(input1, input2, output);
89}
90
91template <ComparisonOperation COP>
92void CpuElementwiseComparisonStatic<COP>::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output)
93{
94 auto k = std::make_unique<kernels::CpuComparisonKernel>();
95 k->configure(COP, input1, input2, output);
96 _kernel = std::move(k);
97}
98
99template <ComparisonOperation COP>
100Status CpuElementwiseComparisonStatic<COP>::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output)
101{
102 return kernels::CpuComparisonKernel::validate(COP, input1, input2, output);
103}
104
105void CpuElementwiseComparison::configure(const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output, ComparisonOperation op)
106{
107 auto k = std::make_unique<kernels::CpuComparisonKernel>();
108 k->configure(op, input1, input2, output);
109 _kernel = std::move(k);
110}
111
112Status CpuElementwiseComparison::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation op)
113{
114 return kernels::CpuComparisonKernel::validate(op, input1, input2, output);
115}
116
117// Supported Specializations
118template class CpuElementwiseComparisonStatic<ComparisonOperation::Equal>;
119template class CpuElementwiseComparisonStatic<ComparisonOperation::NotEqual>;
120template class CpuElementwiseComparisonStatic<ComparisonOperation::Greater>;
121template class CpuElementwiseComparisonStatic<ComparisonOperation::GreaterEqual>;
122template class CpuElementwiseComparisonStatic<ComparisonOperation::Less>;
123template class CpuElementwiseComparisonStatic<ComparisonOperation::LessEqual>;
124} // namespace cpu
125} // namespace arm_compute