1 /*
2 * Copyright (c) 2018-2020 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 "src/core/CL/kernels/CLElementWiseUnaryLayerKernel.h"
27 #include "support/MemorySupport.h"
28
29 #include <utility>
30
31 namespace arm_compute
32 {
33 namespace experimental
34 {
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)35 void CLRsqrt::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
36 {
37 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
38 k->configure(compile_context, input, output, ElementWiseUnary::RSQRT);
39 _kernel = std::move(k);
40 }
41
validate(const ITensorInfo * input,const ITensorInfo * output)42 Status CLRsqrt::validate(const ITensorInfo *input, const ITensorInfo *output)
43 {
44 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::RSQRT);
45 }
46
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)47 void CLExp::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
48 {
49 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
50 k->configure(compile_context, input, output, ElementWiseUnary::EXP);
51 _kernel = std::move(k);
52 }
53
validate(const ITensorInfo * input,const ITensorInfo * output)54 Status CLExp::validate(const ITensorInfo *input, const ITensorInfo *output)
55 {
56 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::EXP);
57 }
58
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)59 void CLNeg::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
60 {
61 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
62 k->configure(compile_context, input, output, ElementWiseUnary::NEG);
63 _kernel = std::move(k);
64 }
65
validate(const ITensorInfo * input,const ITensorInfo * output)66 Status CLNeg::validate(const ITensorInfo *input, const ITensorInfo *output)
67 {
68 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::NEG);
69 }
70
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)71 void CLSin::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
72 {
73 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
74 k->configure(compile_context, input, output, ElementWiseUnary::SIN);
75 _kernel = std::move(k);
76 }
77
validate(const ITensorInfo * input,const ITensorInfo * output)78 Status CLSin::validate(const ITensorInfo *input, const ITensorInfo *output)
79 {
80 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::SIN);
81 }
82
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)83 void CLAbs::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
84 {
85 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
86 k->configure(compile_context, input, output, ElementWiseUnary::ABS);
87 _kernel = std::move(k);
88 }
89
validate(const ITensorInfo * input,const ITensorInfo * output)90 Status CLAbs::validate(const ITensorInfo *input, const ITensorInfo *output)
91 {
92 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::ABS);
93 }
94
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)95 void CLLog::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
96 {
97 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
98 k->configure(compile_context, input, output, ElementWiseUnary::LOG);
99 _kernel = std::move(k);
100 }
101
validate(const ITensorInfo * input,const ITensorInfo * output)102 Status CLLog::validate(const ITensorInfo *input, const ITensorInfo *output)
103 {
104 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::LOG);
105 }
106
configure(const CLCompileContext & compile_context,const ITensorInfo * input,ITensorInfo * output)107 void CLRound::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
108 {
109 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
110 k->configure(compile_context, input, output, ElementWiseUnary::ROUND);
111 _kernel = std::move(k);
112 }
113
validate(const ITensorInfo * input,const ITensorInfo * output)114 Status CLRound::validate(const ITensorInfo *input, const ITensorInfo *output)
115 {
116 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::ROUND);
117 }
118 } // namespace experimental
119
120 struct CLRsqrtLayer::Impl
121 {
122 const ICLTensor *src{ nullptr };
123 ICLTensor *dst{ nullptr };
124 std::unique_ptr<experimental::CLRsqrt> op{ nullptr };
125 };
126
CLRsqrtLayer()127 CLRsqrtLayer::CLRsqrtLayer()
128 : _impl(support::cpp14::make_unique<Impl>())
129 {
130 }
131
132 CLRsqrtLayer::CLRsqrtLayer(CLRsqrtLayer &&) = default;
133 CLRsqrtLayer &CLRsqrtLayer::operator=(CLRsqrtLayer &&) = default;
134 CLRsqrtLayer::~CLRsqrtLayer() = default;
135
configure(const ICLTensor * input,ICLTensor * output)136 void CLRsqrtLayer::configure(const ICLTensor *input, ICLTensor *output)
137 {
138 configure(CLKernelLibrary::get().get_compile_context(), input, output);
139 }
140
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)141 void CLRsqrtLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
142 {
143 _impl->src = input;
144 _impl->dst = output;
145 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLRsqrt>();
146 _impl->op->configure(compile_context, input->info(), output->info());
147 }
148
validate(const ITensorInfo * input,const ITensorInfo * output)149 Status CLRsqrtLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
150 {
151 return experimental::CLRsqrt::validate(input, output);
152 }
153
run()154 void CLRsqrtLayer::run()
155 {
156 ITensorPack pack;
157 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
158 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
159 _impl->op->run(pack);
160 }
161
162 struct CLExpLayer::Impl
163 {
164 const ICLTensor *src{ nullptr };
165 ICLTensor *dst{ nullptr };
166 std::unique_ptr<experimental::CLExp> op{ nullptr };
167 };
168
CLExpLayer()169 CLExpLayer::CLExpLayer()
170 : _impl(support::cpp14::make_unique<Impl>())
171 {
172 }
173
174 CLExpLayer::CLExpLayer(CLExpLayer &&) = default;
175 CLExpLayer &CLExpLayer::operator=(CLExpLayer &&) = default;
176 CLExpLayer::~CLExpLayer() = default;
177
configure(const ICLTensor * input,ICLTensor * output)178 void CLExpLayer::configure(const ICLTensor *input, ICLTensor *output)
179 {
180 configure(CLKernelLibrary::get().get_compile_context(), input, output);
181 }
182
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)183 void CLExpLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
184 {
185 _impl->src = input;
186 _impl->dst = output;
187 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLExp>();
188 _impl->op->configure(compile_context, input->info(), output->info());
189 }
190
validate(const ITensorInfo * input,const ITensorInfo * output)191 Status CLExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
192 {
193 return experimental::CLExp::validate(input, output);
194 }
195
run()196 void CLExpLayer::run()
197 {
198 ITensorPack pack;
199 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
200 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
201 _impl->op->run(pack);
202 }
203
204 struct CLNegLayer::Impl
205 {
206 const ICLTensor *src{ nullptr };
207 ICLTensor *dst{ nullptr };
208 std::unique_ptr<experimental::CLNeg> op{ nullptr };
209 };
210
CLNegLayer()211 CLNegLayer::CLNegLayer()
212 : _impl(support::cpp14::make_unique<Impl>())
213 {
214 }
215
216 CLNegLayer::CLNegLayer(CLNegLayer &&) = default;
217 CLNegLayer &CLNegLayer::operator=(CLNegLayer &&) = default;
218 CLNegLayer::~CLNegLayer() = default;
219
configure(const ICLTensor * input,ICLTensor * output)220 void CLNegLayer::configure(const ICLTensor *input, ICLTensor *output)
221 {
222 configure(CLKernelLibrary::get().get_compile_context(), input, output);
223 }
224
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)225 void CLNegLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
226 {
227 _impl->src = input;
228 _impl->dst = output;
229 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLNeg>();
230 _impl->op->configure(compile_context, input->info(), output->info());
231 }
validate(const ITensorInfo * input,const ITensorInfo * output)232 Status CLNegLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
233 {
234 return experimental::CLNeg::validate(input, output);
235 }
236
run()237 void CLNegLayer::run()
238 {
239 ITensorPack pack;
240 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
241 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
242 _impl->op->run(pack);
243 }
244
245 struct CLSinLayer::Impl
246 {
247 const ICLTensor *src{ nullptr };
248 ICLTensor *dst{ nullptr };
249 std::unique_ptr<experimental::CLSin> op{ nullptr };
250 };
251
CLSinLayer()252 CLSinLayer::CLSinLayer()
253 : _impl(support::cpp14::make_unique<Impl>())
254 {
255 }
256
257 CLSinLayer::CLSinLayer(CLSinLayer &&) = default;
258 CLSinLayer &CLSinLayer::operator=(CLSinLayer &&) = default;
259 CLSinLayer::~CLSinLayer() = default;
260
configure(const ICLTensor * input,ICLTensor * output)261 void CLSinLayer::configure(const ICLTensor *input, ICLTensor *output)
262 {
263 configure(CLKernelLibrary::get().get_compile_context(), input, output);
264 }
265
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)266 void CLSinLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
267 {
268 _impl->src = input;
269 _impl->dst = output;
270 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLSin>();
271 _impl->op->configure(compile_context, input->info(), output->info());
272 }
validate(const ITensorInfo * input,const ITensorInfo * output)273 Status CLSinLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
274 {
275 return experimental::CLSin::validate(input, output);
276 }
277
run()278 void CLSinLayer::run()
279 {
280 ITensorPack pack;
281 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
282 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
283 _impl->op->run(pack);
284 }
285
286 struct CLAbsLayer::Impl
287 {
288 const ICLTensor *src{ nullptr };
289 ICLTensor *dst{ nullptr };
290 std::unique_ptr<experimental::CLAbs> op{ nullptr };
291 };
292
CLAbsLayer()293 CLAbsLayer::CLAbsLayer()
294 : _impl(support::cpp14::make_unique<Impl>())
295 {
296 }
297
298 CLAbsLayer::CLAbsLayer(CLAbsLayer &&) = default;
299 CLAbsLayer &CLAbsLayer::operator=(CLAbsLayer &&) = default;
300 CLAbsLayer::~CLAbsLayer() = default;
301
configure(const ICLTensor * input,ICLTensor * output)302 void CLAbsLayer::configure(const ICLTensor *input, ICLTensor *output)
303 {
304 configure(CLKernelLibrary::get().get_compile_context(), input, output);
305 }
306
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)307 void CLAbsLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
308 {
309 _impl->src = input;
310 _impl->dst = output;
311 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLAbs>();
312 _impl->op->configure(compile_context, input->info(), output->info());
313 }
validate(const ITensorInfo * input,const ITensorInfo * output)314 Status CLAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
315 {
316 return experimental::CLAbs::validate(input, output);
317 }
318
run()319 void CLAbsLayer::run()
320 {
321 ITensorPack pack;
322 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
323 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
324 _impl->op->run(pack);
325 }
326
327 struct CLLogLayer::Impl
328 {
329 const ICLTensor *src{ nullptr };
330 ICLTensor *dst{ nullptr };
331 std::unique_ptr<experimental::CLLog> op{ nullptr };
332 };
333
CLLogLayer()334 CLLogLayer::CLLogLayer()
335 : _impl(support::cpp14::make_unique<Impl>())
336 {
337 }
338
339 CLLogLayer::CLLogLayer(CLLogLayer &&) = default;
340 CLLogLayer &CLLogLayer::operator=(CLLogLayer &&) = default;
341 CLLogLayer::~CLLogLayer() = default;
342
configure(const ICLTensor * input,ICLTensor * output)343 void CLLogLayer::configure(const ICLTensor *input, ICLTensor *output)
344 {
345 configure(CLKernelLibrary::get().get_compile_context(), input, output);
346 }
347
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)348 void CLLogLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
349 {
350 _impl->src = input;
351 _impl->dst = output;
352 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLLog>();
353 _impl->op->configure(compile_context, input->info(), output->info());
354 }
validate(const ITensorInfo * input,const ITensorInfo * output)355 Status CLLogLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
356 {
357 return experimental::CLLog::validate(input, output);
358 }
359
run()360 void CLLogLayer::run()
361 {
362 ITensorPack pack;
363 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
364 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
365 _impl->op->run(pack);
366 }
367
368 struct CLRoundLayer::Impl
369 {
370 const ICLTensor *src{ nullptr };
371 ICLTensor *dst{ nullptr };
372 std::unique_ptr<experimental::CLRound> op{ nullptr };
373 };
374
CLRoundLayer()375 CLRoundLayer::CLRoundLayer()
376 : _impl(support::cpp14::make_unique<Impl>())
377 {
378 }
379
380 CLRoundLayer::CLRoundLayer(CLRoundLayer &&) = default;
381 CLRoundLayer &CLRoundLayer::operator=(CLRoundLayer &&) = default;
382 CLRoundLayer::~CLRoundLayer() = default;
383
configure(const ICLTensor * input,ICLTensor * output)384 void CLRoundLayer::configure(const ICLTensor *input, ICLTensor *output)
385 {
386 configure(CLKernelLibrary::get().get_compile_context(), input, output);
387 }
388
configure(const CLCompileContext & compile_context,const ICLTensor * input,ICLTensor * output)389 void CLRoundLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
390 {
391 _impl->src = input;
392 _impl->dst = output;
393 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLRound>();
394 _impl->op->configure(compile_context, input->info(), output->info());
395 }
validate(const ITensorInfo * input,const ITensorInfo * output)396 Status CLRoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
397 {
398 return experimental::CLRound::validate(input, output);
399 }
400
run()401 void CLRoundLayer::run()
402 {
403 ITensorPack pack;
404 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
405 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
406 _impl->op->run(pack);
407 }
408 } // namespace arm_compute
409