1 /*
2 * Copyright (c) 2016-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 "arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h"
25
26 #include "arm_compute/core/CL/ICLTensor.h"
27 #include "arm_compute/runtime/CL/CLScheduler.h"
28 #include "src/core/CL/ICLKernel.h"
29 #include "src/gpu/cl/operators/ClMul.h"
30
31 #include <utility>
32
33 namespace arm_compute
34 {
35 struct CLPixelWiseMultiplication::Impl
36 {
37 const ICLTensor *src_0{ nullptr };
38 const ICLTensor *src_1{ nullptr };
39 ICLTensor *dst{ nullptr };
40 std::unique_ptr<opencl::ClMul> op{ nullptr };
41 };
42
CLPixelWiseMultiplication()43 CLPixelWiseMultiplication::CLPixelWiseMultiplication()
44 : _impl(std::make_unique<Impl>())
45 {
46 }
47 CLPixelWiseMultiplication::CLPixelWiseMultiplication(CLPixelWiseMultiplication &&) = default;
48 CLPixelWiseMultiplication &CLPixelWiseMultiplication::operator=(CLPixelWiseMultiplication &&) = default;
49 CLPixelWiseMultiplication::~CLPixelWiseMultiplication() = default;
50
configure(ICLTensor * input1,ICLTensor * input2,ICLTensor * output,float scale,ConvertPolicy overflow_policy,RoundingPolicy rounding_policy,const ActivationLayerInfo & act_info)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
configure(const CLCompileContext & compile_context,ICLTensor * input1,ICLTensor * input2,ICLTensor * output,float scale,ConvertPolicy overflow_policy,RoundingPolicy rounding_policy,const ActivationLayerInfo & act_info)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;
63 _impl->op = std::make_unique<opencl::ClMul>();
64 _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), scale, overflow_policy, rounding_policy, act_info);
65 }
66
validate(const ITensorInfo * input1,const ITensorInfo * input2,const ITensorInfo * output,float scale,ConvertPolicy overflow_policy,RoundingPolicy rounding_policy,const ActivationLayerInfo & act_info)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 {
70 return opencl::ClMul::validate(input1, input2, output, scale, overflow_policy, rounding_policy, act_info);
71 }
72
run()73 void CLPixelWiseMultiplication::run()
74 {
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);
79
80 _impl->op->run(pack);
81 }
82
83 struct CLComplexPixelWiseMultiplication::Impl
84 {
85 const ICLTensor *src_0{ nullptr };
86 const ICLTensor *src_1{ nullptr };
87 ICLTensor *dst{ nullptr };
88 std::unique_ptr<opencl::ClComplexMul> op{ nullptr };
89 };
90
CLComplexPixelWiseMultiplication()91 CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication()
92 : _impl(std::make_unique<Impl>())
93 {
94 }
95 CLComplexPixelWiseMultiplication::CLComplexPixelWiseMultiplication(CLComplexPixelWiseMultiplication &&) = default;
96 CLComplexPixelWiseMultiplication &CLComplexPixelWiseMultiplication::operator=(CLComplexPixelWiseMultiplication &&) = default;
97 CLComplexPixelWiseMultiplication::~CLComplexPixelWiseMultiplication() = default;
98
configure(ICLTensor * input1,ICLTensor * input2,ICLTensor * output,const ActivationLayerInfo & act_info)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
configure(const CLCompileContext & compile_context,ICLTensor * input1,ICLTensor * input2,ICLTensor * output,const ActivationLayerInfo & act_info)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;
109 _impl->op = std::make_unique<opencl::ClComplexMul>();
110 _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info);
111 }
112
validate(const ITensorInfo * input1,const ITensorInfo * input2,const ITensorInfo * output,const ActivationLayerInfo & act_info)113 Status CLComplexPixelWiseMultiplication::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info)
114 {
115 return opencl::ClComplexMul::validate(input1, input2, output, act_info);
116 }
117
run()118 void CLComplexPixelWiseMultiplication::run()
119 {
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);
124
125 _impl->op->run(pack);
126 }
127 } // namespace arm_compute
128