Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 "arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h" |
| 25 | |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/CL/ICLTensor.h" |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 28 | #include "src/core/CL/kernels/CLFillBorderKernel.h" |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 29 | #include "src/runtime/gpu/cl/operators/ClPixelWiseMultiplication.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
| 31 | #include <utility> |
| 32 | |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 35 | struct CLPixelWiseMultiplication::Impl |
| 36 | { |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 37 | const ICLTensor *src_0{ nullptr }; |
| 38 | const ICLTensor *src_1{ nullptr }; |
| 39 | ICLTensor *dst{ nullptr }; |
| 40 | std::unique_ptr<opencl::ClPixelWiseMultiplication> op{ nullptr }; |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | CLPixelWiseMultiplication::CLPixelWiseMultiplication() |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 44 | : _impl(std::make_unique<Impl>()) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | CLPixelWiseMultiplication::CLPixelWiseMultiplication(CLPixelWiseMultiplication &&) = default; |
| 48 | CLPixelWiseMultiplication &CLPixelWiseMultiplication::operator=(CLPixelWiseMultiplication &&) = default; |
| 49 | CLPixelWiseMultiplication::~CLPixelWiseMultiplication() = default; |
| 50 | |
| 51 | void CLPixelWiseMultiplication::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, float scale, |
| 52 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 53 | { |
| 54 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, scale, overflow_policy, rounding_policy, act_info); |
| 55 | } |
| 56 | |
| 57 | void CLPixelWiseMultiplication::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, float scale, |
| 58 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 59 | { |
| 60 | _impl->src_0 = input1; |
| 61 | _impl->src_1 = input2; |
| 62 | _impl->dst = output; |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 63 | _impl->op = std::make_unique<opencl::ClPixelWiseMultiplication>(); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 64 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), scale, overflow_policy, rounding_policy, act_info); |
| 65 | } |
| 66 | |
| 67 | Status CLPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, |
| 68 | ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info) |
| 69 | { |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 70 | return opencl::ClPixelWiseMultiplication::validate(input1, input2, output, scale, overflow_policy, rounding_policy, act_info); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void CLPixelWiseMultiplication::run() |
| 74 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 75 | ITensorPack pack; |
| 76 | pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0); |
| 77 | pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1); |
| 78 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 79 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 80 | _impl->op->run(pack); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | struct CLComplexPixelWiseMultiplication::Impl |
| 84 | { |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 85 | const ICLTensor *src_0{ nullptr }; |
| 86 | const ICLTensor *src_1{ nullptr }; |
| 87 | ICLTensor *dst{ nullptr }; |
| 88 | std::unique_ptr<opencl::ClComplexPixelWiseMultiplication> op{ nullptr }; |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication() |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 92 | : _impl(std::make_unique<Impl>()) |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 93 | { |
| 94 | } |
| 95 | CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication(CLComplexPixelWiseMultiplication &&) = default; |
| 96 | CLComplexPixelWiseMultiplication &CLComplexPixelWiseMultiplication::operator=(CLComplexPixelWiseMultiplication &&) = default; |
| 97 | CLComplexPixelWiseMultiplication::~CLComplexPixelWiseMultiplication() = default; |
| 98 | |
| 99 | void CLComplexPixelWiseMultiplication::configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 100 | { |
| 101 | configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, act_info); |
| 102 | } |
| 103 | |
| 104 | void CLComplexPixelWiseMultiplication::configure(const CLCompileContext &compile_context, ICLTensor *input1, ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info) |
| 105 | { |
| 106 | _impl->src_0 = input1; |
| 107 | _impl->src_1 = input2; |
| 108 | _impl->dst = output; |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 109 | _impl->op = std::make_unique<opencl::ClComplexPixelWiseMultiplication>(); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 110 | _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); |
| 111 | } |
| 112 | |
| 113 | Status CLComplexPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 114 | { |
Sheri Zhang | f9ab9f9 | 2021-03-16 12:09:15 +0000 | [diff] [blame] | 115 | return opencl::ClComplexPixelWiseMultiplication::validate(input1, input2, output, act_info); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void CLComplexPixelWiseMultiplication::run() |
| 119 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 120 | ITensorPack pack; |
| 121 | pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0); |
| 122 | pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1); |
| 123 | pack.add_tensor(TensorType::ACL_DST, _impl->dst); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 124 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 125 | _impl->op->run(pack); |
Michalis Spyrou | 1009e87 | 2020-07-27 12:48:34 +0100 | [diff] [blame] | 126 | } |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 127 | } // namespace arm_compute |