Sang-Hoon Park | 63001ac | 2021-01-18 14:20:27 +0000 | [diff] [blame] | 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 | */ |
| 24 | #include "src/runtime/cpu/operators/CpuElementwise.h" |
| 25 | #include "src/core/cpu/kernels/CpuElementwiseKernel.h" |
| 26 | |
| 27 | namespace arm_compute |
| 28 | { |
| 29 | namespace cpu |
| 30 | { |
| 31 | void 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 | |
| 38 | Status CpuElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 39 | { |
| 40 | return kernels::CpuArithmeticKernel::validate(ArithmeticOperation::MAX, input1, input2, output); |
| 41 | } |
| 42 | |
| 43 | void 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 | |
| 50 | Status CpuElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 51 | { |
| 52 | return kernels::CpuArithmeticKernel::validate(ArithmeticOperation::MIN, input1, input2, output); |
| 53 | } |
| 54 | |
| 55 | void 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 | |
| 62 | Status 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 | |
| 67 | void 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 | |
| 74 | Status CpuElementwiseDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 75 | { |
| 76 | return kernels::CpuDivisionKernel::validate(input1, input2, output); |
| 77 | } |
| 78 | |
| 79 | void 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 | |
| 86 | Status CpuElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 87 | { |
| 88 | return kernels::CpuPowerKernel::validate(input1, input2, output); |
| 89 | } |
| 90 | |
| 91 | template <ComparisonOperation COP> |
| 92 | void 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 | |
| 99 | template <ComparisonOperation COP> |
| 100 | Status CpuElementwiseComparisonStatic<COP>::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) |
| 101 | { |
| 102 | return kernels::CpuComparisonKernel::validate(COP, input1, input2, output); |
| 103 | } |
| 104 | |
| 105 | void 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 | |
| 112 | Status 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 |
| 118 | template class CpuElementwiseComparisonStatic<ComparisonOperation::Equal>; |
| 119 | template class CpuElementwiseComparisonStatic<ComparisonOperation::NotEqual>; |
| 120 | template class CpuElementwiseComparisonStatic<ComparisonOperation::Greater>; |
| 121 | template class CpuElementwiseComparisonStatic<ComparisonOperation::GreaterEqual>; |
| 122 | template class CpuElementwiseComparisonStatic<ComparisonOperation::Less>; |
| 123 | template class CpuElementwiseComparisonStatic<ComparisonOperation::LessEqual>; |
| 124 | } // namespace cpu |
| 125 | } // namespace arm_compute |