• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-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/CLElementwiseUnaryLayer.h"
25 
26 #include "arm_compute/core/CL/CLKernelLibrary.h"
27 #include "arm_compute/core/CL/ICLTensor.h"
28 #include "src/core/CL/ICLKernel.h"
29 #include "src/gpu/cl/operators/ClElementwiseUnary.h"
30 
31 namespace arm_compute
32 {
33 struct CLRsqrtLayer::Impl
34 {
35     const ICLTensor                 *src{ nullptr };
36     ICLTensor                       *dst{ nullptr };
37     std::unique_ptr<opencl::ClRsqrt> op{ nullptr };
38 };
39 
CLRsqrtLayer()40 CLRsqrtLayer::CLRsqrtLayer()
41     : _impl(std::make_unique<Impl>())
42 {
43 }
44 
45 CLRsqrtLayer::CLRsqrtLayer(CLRsqrtLayer &&) = default;
46 CLRsqrtLayer &CLRsqrtLayer::operator=(CLRsqrtLayer &&) = default;
47 CLRsqrtLayer::~CLRsqrtLayer()                          = default;
48 
configure(const ICLTensor * input,ICLTensor * output)49 void CLRsqrtLayer::configure(const ICLTensor *input, ICLTensor *output)
50 {
51     configure(CLKernelLibrary::get().get_compile_context(), input, output);
52 }
53 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)54 void CLRsqrtLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
55 {
56     _impl->src = input;
57     _impl->dst = output;
58     _impl->op  = std::make_unique<opencl::ClRsqrt>();
59     _impl->op->configure(compile_context, input->info(), output->info());
60 }
61 
validate(const ITensorInfo * input,const ITensorInfo * output)62 Status CLRsqrtLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
63 {
64     return opencl::ClRsqrt::validate(input, output);
65 }
66 
run()67 void CLRsqrtLayer::run()
68 {
69     ITensorPack pack;
70     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
71     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
72     _impl->op->run(pack);
73 }
74 
75 struct CLExpLayer::Impl
76 {
77     const ICLTensor               *src{ nullptr };
78     ICLTensor                     *dst{ nullptr };
79     std::unique_ptr<opencl::ClExp> op{ nullptr };
80 };
81 
CLExpLayer()82 CLExpLayer::CLExpLayer()
83     : _impl(std::make_unique<Impl>())
84 {
85 }
86 
87 CLExpLayer::CLExpLayer(CLExpLayer &&) = default;
88 CLExpLayer &CLExpLayer::operator=(CLExpLayer &&) = default;
89 CLExpLayer::~CLExpLayer()                        = default;
90 
configure(const ICLTensor * input,ICLTensor * output)91 void CLExpLayer::configure(const ICLTensor *input, ICLTensor *output)
92 {
93     configure(CLKernelLibrary::get().get_compile_context(), input, output);
94 }
95 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)96 void CLExpLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
97 {
98     _impl->src = input;
99     _impl->dst = output;
100     _impl->op  = std::make_unique<opencl::ClExp>();
101     _impl->op->configure(compile_context, input->info(), output->info());
102 }
103 
validate(const ITensorInfo * input,const ITensorInfo * output)104 Status CLExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
105 {
106     return opencl::ClExp::validate(input, output);
107 }
108 
run()109 void CLExpLayer::run()
110 {
111     ITensorPack pack;
112     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
113     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
114     _impl->op->run(pack);
115 }
116 
117 struct CLNegLayer::Impl
118 {
119     const ICLTensor               *src{ nullptr };
120     ICLTensor                     *dst{ nullptr };
121     std::unique_ptr<opencl::ClNeg> op{ nullptr };
122 };
123 
CLNegLayer()124 CLNegLayer::CLNegLayer()
125     : _impl(std::make_unique<Impl>())
126 {
127 }
128 
129 CLNegLayer::CLNegLayer(CLNegLayer &&) = default;
130 CLNegLayer &CLNegLayer::operator=(CLNegLayer &&) = default;
131 CLNegLayer::~CLNegLayer()                        = default;
132 
configure(const ICLTensor * input,ICLTensor * output)133 void CLNegLayer::configure(const ICLTensor *input, ICLTensor *output)
134 {
135     configure(CLKernelLibrary::get().get_compile_context(), input, output);
136 }
137 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)138 void CLNegLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
139 {
140     _impl->src = input;
141     _impl->dst = output;
142     _impl->op  = std::make_unique<opencl::ClNeg>();
143     _impl->op->configure(compile_context, input->info(), output->info());
144 }
validate(const ITensorInfo * input,const ITensorInfo * output)145 Status CLNegLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
146 {
147     return opencl::ClNeg::validate(input, output);
148 }
149 
run()150 void CLNegLayer::run()
151 {
152     ITensorPack pack;
153     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
154     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
155     _impl->op->run(pack);
156 }
157 
158 struct CLSinLayer::Impl
159 {
160     const ICLTensor               *src{ nullptr };
161     ICLTensor                     *dst{ nullptr };
162     std::unique_ptr<opencl::ClSin> op{ nullptr };
163 };
164 
CLSinLayer()165 CLSinLayer::CLSinLayer()
166     : _impl(std::make_unique<Impl>())
167 {
168 }
169 
170 CLSinLayer::CLSinLayer(CLSinLayer &&) = default;
171 CLSinLayer &CLSinLayer::operator=(CLSinLayer &&) = default;
172 CLSinLayer::~CLSinLayer()                        = default;
173 
configure(const ICLTensor * input,ICLTensor * output)174 void CLSinLayer::configure(const ICLTensor *input, ICLTensor *output)
175 {
176     configure(CLKernelLibrary::get().get_compile_context(), input, output);
177 }
178 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)179 void CLSinLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
180 {
181     _impl->src = input;
182     _impl->dst = output;
183     _impl->op  = std::make_unique<opencl::ClSin>();
184     _impl->op->configure(compile_context, input->info(), output->info());
185 }
validate(const ITensorInfo * input,const ITensorInfo * output)186 Status CLSinLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
187 {
188     return opencl::ClSin::validate(input, output);
189 }
190 
run()191 void CLSinLayer::run()
192 {
193     ITensorPack pack;
194     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
195     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
196     _impl->op->run(pack);
197 }
198 
199 struct CLAbsLayer::Impl
200 {
201     const ICLTensor               *src{ nullptr };
202     ICLTensor                     *dst{ nullptr };
203     std::unique_ptr<opencl::ClAbs> op{ nullptr };
204 };
205 
CLAbsLayer()206 CLAbsLayer::CLAbsLayer()
207     : _impl(std::make_unique<Impl>())
208 {
209 }
210 
211 CLAbsLayer::CLAbsLayer(CLAbsLayer &&) = default;
212 CLAbsLayer &CLAbsLayer::operator=(CLAbsLayer &&) = default;
213 CLAbsLayer::~CLAbsLayer()                        = default;
214 
configure(const ICLTensor * input,ICLTensor * output)215 void CLAbsLayer::configure(const ICLTensor *input, ICLTensor *output)
216 {
217     configure(CLKernelLibrary::get().get_compile_context(), input, output);
218 }
219 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)220 void CLAbsLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
221 {
222     _impl->src = input;
223     _impl->dst = output;
224     _impl->op  = std::make_unique<opencl::ClAbs>();
225     _impl->op->configure(compile_context, input->info(), output->info());
226 }
validate(const ITensorInfo * input,const ITensorInfo * output)227 Status CLAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
228 {
229     return opencl::ClAbs::validate(input, output);
230 }
231 
run()232 void CLAbsLayer::run()
233 {
234     ITensorPack pack;
235     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
236     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
237     _impl->op->run(pack);
238 }
239 
240 struct CLLogLayer::Impl
241 {
242     const ICLTensor               *src{ nullptr };
243     ICLTensor                     *dst{ nullptr };
244     std::unique_ptr<opencl::ClLog> op{ nullptr };
245 };
246 
CLLogLayer()247 CLLogLayer::CLLogLayer()
248     : _impl(std::make_unique<Impl>())
249 {
250 }
251 
252 CLLogLayer::CLLogLayer(CLLogLayer &&) = default;
253 CLLogLayer &CLLogLayer::operator=(CLLogLayer &&) = default;
254 CLLogLayer::~CLLogLayer()                        = default;
255 
configure(const ICLTensor * input,ICLTensor * output)256 void CLLogLayer::configure(const ICLTensor *input, ICLTensor *output)
257 {
258     configure(CLKernelLibrary::get().get_compile_context(), input, output);
259 }
260 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)261 void CLLogLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
262 {
263     _impl->src = input;
264     _impl->dst = output;
265     _impl->op  = std::make_unique<opencl::ClLog>();
266     _impl->op->configure(compile_context, input->info(), output->info());
267 }
validate(const ITensorInfo * input,const ITensorInfo * output)268 Status CLLogLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
269 {
270     return opencl::ClLog::validate(input, output);
271 }
272 
run()273 void CLLogLayer::run()
274 {
275     ITensorPack pack;
276     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
277     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
278     _impl->op->run(pack);
279 }
280 
281 struct CLRoundLayer::Impl
282 {
283     const ICLTensor                 *src{ nullptr };
284     ICLTensor                       *dst{ nullptr };
285     std::unique_ptr<opencl::ClRound> op{ nullptr };
286 };
287 
CLRoundLayer()288 CLRoundLayer::CLRoundLayer()
289     : _impl(std::make_unique<Impl>())
290 {
291 }
292 
293 CLRoundLayer::CLRoundLayer(CLRoundLayer &&) = default;
294 CLRoundLayer &CLRoundLayer::operator=(CLRoundLayer &&) = default;
295 CLRoundLayer::~CLRoundLayer()                          = default;
296 
configure(const ICLTensor * input,ICLTensor * output)297 void CLRoundLayer::configure(const ICLTensor *input, ICLTensor *output)
298 {
299     configure(CLKernelLibrary::get().get_compile_context(), input, output);
300 }
301 
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)302 void CLRoundLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
303 {
304     _impl->src = input;
305     _impl->dst = output;
306     _impl->op  = std::make_unique<opencl::ClRound>();
307     _impl->op->configure(compile_context, input->info(), output->info());
308 }
validate(const ITensorInfo * input,const ITensorInfo * output)309 Status CLRoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
310 {
311     return opencl::ClRound::validate(input, output);
312 }
313 
run()314 void CLRoundLayer::run()
315 {
316     ITensorPack pack;
317     pack.add_tensor(TensorType::ACL_SRC, _impl->src);
318     pack.add_tensor(TensorType::ACL_DST, _impl->dst);
319     _impl->op->run(pack);
320 }
321 } // namespace arm_compute
322