blob: 9d91e583674fd8e5b6113b2c510f78539e98e011 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sheri Zhangf9ab9f92021-03-16 12:09:15 +00002 * Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Giorgio6259e5f2018-01-17 17:29:33 +000026#include "arm_compute/core/CL/ICLTensor.h"
Michalis Spyrou1009e872020-07-27 12:48:34 +010027#include "arm_compute/runtime/CL/CLScheduler.h"
Giorgio Arenaada6cbc2021-04-16 17:03:39 +010028#include "src/core/CL/ICLKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/gpu/cl/operators/ClMul.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31#include <utility>
32
Georgios Pinitas8be91482019-03-26 17:23:28 +000033namespace arm_compute
34{
Michalis Spyrou1009e872020-07-27 12:48:34 +010035struct CLPixelWiseMultiplication::Impl
36{
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010037 const ICLTensor *src_0{ nullptr };
38 const ICLTensor *src_1{ nullptr };
39 ICLTensor *dst{ nullptr };
40 std::unique_ptr<opencl::ClMul> op{ nullptr };
Michalis Spyrou1009e872020-07-27 12:48:34 +010041};
42
43CLPixelWiseMultiplication::CLPixelWiseMultiplication()
Georgios Pinitas40f51a62020-11-21 03:04:18 +000044 : _impl(std::make_unique<Impl>())
Michalis Spyrou1009e872020-07-27 12:48:34 +010045{
46}
47CLPixelWiseMultiplication::CLPixelWiseMultiplication(CLPixelWiseMultiplication &&) = default;
48CLPixelWiseMultiplication &CLPixelWiseMultiplication::operator=(CLPixelWiseMultiplication &&) = default;
49CLPixelWiseMultiplication::~CLPixelWiseMultiplication() = default;
50
51void 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
57void 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;
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010063 _impl->op = std::make_unique<opencl::ClMul>();
Michalis Spyrou1009e872020-07-27 12:48:34 +010064 _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), scale, overflow_policy, rounding_policy, act_info);
65}
66
67Status 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{
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010070 return opencl::ClMul::validate(input1, input2, output, scale, overflow_policy, rounding_policy, act_info);
Michalis Spyrou1009e872020-07-27 12:48:34 +010071}
72
73void CLPixelWiseMultiplication::run()
74{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010075 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 Spyrou1009e872020-07-27 12:48:34 +010079
Georgios Pinitas0499dff2020-07-31 22:21:38 +010080 _impl->op->run(pack);
Michalis Spyrou1009e872020-07-27 12:48:34 +010081}
82
83struct CLComplexPixelWiseMultiplication::Impl
84{
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010085 const ICLTensor *src_0{ nullptr };
86 const ICLTensor *src_1{ nullptr };
87 ICLTensor *dst{ nullptr };
88 std::unique_ptr<opencl::ClComplexMul> op{ nullptr };
Michalis Spyrou1009e872020-07-27 12:48:34 +010089};
90
91CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication()
Georgios Pinitas40f51a62020-11-21 03:04:18 +000092 : _impl(std::make_unique<Impl>())
Michalis Spyrou1009e872020-07-27 12:48:34 +010093{
94}
95CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication(CLComplexPixelWiseMultiplication &&) = default;
96CLComplexPixelWiseMultiplication &CLComplexPixelWiseMultiplication::operator=(CLComplexPixelWiseMultiplication &&) = default;
97CLComplexPixelWiseMultiplication::~CLComplexPixelWiseMultiplication() = default;
98
99void 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
104void 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;
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100109 _impl->op = std::make_unique<opencl::ClComplexMul>();
Michalis Spyrou1009e872020-07-27 12:48:34 +0100110 _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info);
111}
112
113Status CLComplexPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
114{
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100115 return opencl::ClComplexMul::validate(input1, input2, output, act_info);
Michalis Spyrou1009e872020-07-27 12:48:34 +0100116}
117
118void CLComplexPixelWiseMultiplication::run()
119{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100120 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 Spyrou1009e872020-07-27 12:48:34 +0100124
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100125 _impl->op->run(pack);
Michalis Spyrou1009e872020-07-27 12:48:34 +0100126}
Matthew Bentham92046462020-03-07 22:15:55 +0000127} // namespace arm_compute