blob: 402b9648a7495c0e76c3e8585aeda1a24f458879 [file] [log] [blame]
Michalis Spyroue9362622018-11-23 17:41:37 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Michalis Spyroue9362622018-11-23 17:41:37 +00003 *
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/kernels/CLElementWiseUnaryLayerKernel.h"
Matthew Bentham92046462020-03-07 22:15:55 +000027#include "support/MemorySupport.h"
Michalis Spyroue9362622018-11-23 17:41:37 +000028
29#include <utility>
30
31namespace arm_compute
32{
Michalis Spyrouf738fe62020-07-15 18:10:17 +010033namespace experimental
34{
35void CLRsqrtLayer::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
42Status CLRsqrtLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
43{
44 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::RSQRT);
45}
46
47MemoryRequirements CLRsqrtLayer::workspace() const
48{
49 return MemoryRequirements{};
50}
51
52void CLExpLayer::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
53{
54 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
55 k->configure(compile_context, input, output, ElementWiseUnary::EXP);
56 _kernel = std::move(k);
57}
58
59Status CLExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
60{
61 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::EXP);
62}
63
64MemoryRequirements CLExpLayer::workspace() const
65{
66 return MemoryRequirements{};
67}
68
69void CLNegLayer::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
70{
71 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
72 k->configure(compile_context, input, output, ElementWiseUnary::NEG);
73 _kernel = std::move(k);
74}
75
76Status CLNegLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
77{
78 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::NEG);
79}
80
81MemoryRequirements CLNegLayer::workspace() const
82{
83 return MemoryRequirements{};
84}
85
86void CLSinLayer::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
87{
88 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
89 k->configure(compile_context, input, output, ElementWiseUnary::SIN);
90 _kernel = std::move(k);
91}
92
93Status CLSinLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
94{
95 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::SIN);
96}
97
98MemoryRequirements CLSinLayer::workspace() const
99{
100 return MemoryRequirements{};
101}
102
103void CLAbsLayer::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
104{
105 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
106 k->configure(compile_context, input, output, ElementWiseUnary::ABS);
107 _kernel = std::move(k);
108}
109
110Status CLAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
111{
112 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::ABS);
113}
114
115MemoryRequirements CLAbsLayer::workspace() const
116{
117 return MemoryRequirements{};
118}
119
120void CLLogLayer::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
121{
122 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
123 k->configure(compile_context, input, output, ElementWiseUnary::LOG);
124 _kernel = std::move(k);
125}
126
127Status CLLogLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
128{
129 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::LOG);
130}
131
132MemoryRequirements CLLogLayer::workspace() const
133{
134 return MemoryRequirements{};
135}
136
137void CLRoundLayer::configure(const CLCompileContext &compile_context, const ITensorInfo *input, ITensorInfo *output)
138{
139 auto k = arm_compute::support::cpp14::make_unique<CLElementWiseUnaryLayerKernel>();
140 k->configure(compile_context, input, output, ElementWiseUnary::ROUND);
141 _kernel = std::move(k);
142}
143
144Status CLRoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
145{
146 return arm_compute::CLElementWiseUnaryLayerKernel::validate(input, output, ElementWiseUnary::ROUND);
147}
148
149MemoryRequirements CLRoundLayer::workspace() const
150{
151 return MemoryRequirements{};
152}
153} // namespace experimental
154
155struct CLRsqrtLayer::Impl
156{
157 const ICLTensor *src{ nullptr };
158 ICLTensor *dst{ nullptr };
159 std::unique_ptr<experimental::CLRsqrtLayer> op{ nullptr };
160};
161
162CLRsqrtLayer::CLRsqrtLayer()
163 : _impl(support::cpp14::make_unique<Impl>())
164{
165}
166
167CLRsqrtLayer::CLRsqrtLayer(CLRsqrtLayer &&) = default;
168CLRsqrtLayer &CLRsqrtLayer::operator=(CLRsqrtLayer &&) = default;
169CLRsqrtLayer::~CLRsqrtLayer() = default;
170
Michalis Spyroue9362622018-11-23 17:41:37 +0000171void CLRsqrtLayer::configure(const ICLTensor *input, ICLTensor *output)
172{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100173 configure(CLKernelLibrary::get().get_compile_context(), input, output);
174}
175
176void CLRsqrtLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
177{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100178 _impl->src = input;
179 _impl->dst = output;
180 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLRsqrtLayer>();
181 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyroue9362622018-11-23 17:41:37 +0000182}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100183
Michalis Spyroue9362622018-11-23 17:41:37 +0000184Status CLRsqrtLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
185{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100186 return experimental::CLRsqrtLayer::validate(input, output);
Michalis Spyroue9362622018-11-23 17:41:37 +0000187}
188
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100189void CLRsqrtLayer::run()
190{
191 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
192 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
193
194 _impl->op->run(src, dst, {});
195}
196
197struct CLExpLayer::Impl
198{
199 const ICLTensor *src{ nullptr };
200 ICLTensor *dst{ nullptr };
201 std::unique_ptr<experimental::CLExpLayer> op{ nullptr };
202};
203
204CLExpLayer::CLExpLayer()
205 : _impl(support::cpp14::make_unique<Impl>())
206{
207}
208
209CLExpLayer::CLExpLayer(CLExpLayer &&) = default;
210CLExpLayer &CLExpLayer::operator=(CLExpLayer &&) = default;
211CLExpLayer::~CLExpLayer() = default;
212
Michalis Spyroue9362622018-11-23 17:41:37 +0000213void CLExpLayer::configure(const ICLTensor *input, ICLTensor *output)
214{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100215 configure(CLKernelLibrary::get().get_compile_context(), input, output);
216}
217
218void CLExpLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
219{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100220 _impl->src = input;
221 _impl->dst = output;
222 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLExpLayer>();
223 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyroue9362622018-11-23 17:41:37 +0000224}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100225
Michalis Spyroue9362622018-11-23 17:41:37 +0000226Status CLExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
227{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100228 return experimental::CLExpLayer::validate(input, output);
Michalis Spyroue9362622018-11-23 17:41:37 +0000229}
Usama Arifeb312ef2019-05-13 17:45:54 +0100230
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100231void CLExpLayer::run()
232{
233 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
234 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
235
236 _impl->op->run(src, dst, {});
237}
238
239struct CLNegLayer::Impl
240{
241 const ICLTensor *src{ nullptr };
242 ICLTensor *dst{ nullptr };
243 std::unique_ptr<experimental::CLNegLayer> op{ nullptr };
244};
245
246CLNegLayer::CLNegLayer()
247 : _impl(support::cpp14::make_unique<Impl>())
248{
249}
250
251CLNegLayer::CLNegLayer(CLNegLayer &&) = default;
252CLNegLayer &CLNegLayer::operator=(CLNegLayer &&) = default;
253CLNegLayer::~CLNegLayer() = default;
254
Usama Arifeb312ef2019-05-13 17:45:54 +0100255void CLNegLayer::configure(const ICLTensor *input, ICLTensor *output)
256{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100257 configure(CLKernelLibrary::get().get_compile_context(), input, output);
258}
259
260void CLNegLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
261{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100262 _impl->src = input;
263 _impl->dst = output;
264 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLNegLayer>();
265 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arifeb312ef2019-05-13 17:45:54 +0100266}
267Status CLNegLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
268{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100269 return experimental::CLNegLayer::validate(input, output);
Usama Arifeb312ef2019-05-13 17:45:54 +0100270}
271
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100272void CLNegLayer::run()
273{
274 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
275 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
276
277 _impl->op->run(src, dst, {});
278}
279
280struct CLSinLayer::Impl
281{
282 const ICLTensor *src{ nullptr };
283 ICLTensor *dst{ nullptr };
284 std::unique_ptr<experimental::CLSinLayer> op{ nullptr };
285};
286
287CLSinLayer::CLSinLayer()
288 : _impl(support::cpp14::make_unique<Impl>())
289{
290}
291
292CLSinLayer::CLSinLayer(CLSinLayer &&) = default;
293CLSinLayer &CLSinLayer::operator=(CLSinLayer &&) = default;
294CLSinLayer::~CLSinLayer() = default;
295
Michalis Spyrou0af44182019-05-17 14:04:47 +0100296void CLSinLayer::configure(const ICLTensor *input, ICLTensor *output)
297{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100298 configure(CLKernelLibrary::get().get_compile_context(), input, output);
299}
300
301void CLSinLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
302{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100303 _impl->src = input;
304 _impl->dst = output;
305 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLSinLayer>();
306 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyrou0af44182019-05-17 14:04:47 +0100307}
308Status CLSinLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
309{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100310 return experimental::CLSinLayer::validate(input, output);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100311}
312
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100313void CLSinLayer::run()
314{
315 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
316 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
317
318 _impl->op->run(src, dst, {});
319}
320
321struct CLAbsLayer::Impl
322{
323 const ICLTensor *src{ nullptr };
324 ICLTensor *dst{ nullptr };
325 std::unique_ptr<experimental::CLAbsLayer> op{ nullptr };
326};
327
328CLAbsLayer::CLAbsLayer()
329 : _impl(support::cpp14::make_unique<Impl>())
330{
331}
332
333CLAbsLayer::CLAbsLayer(CLAbsLayer &&) = default;
334CLAbsLayer &CLAbsLayer::operator=(CLAbsLayer &&) = default;
335CLAbsLayer::~CLAbsLayer() = default;
336
giuros01f24411f2019-05-16 11:47:13 +0100337void CLAbsLayer::configure(const ICLTensor *input, ICLTensor *output)
338{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100339 configure(CLKernelLibrary::get().get_compile_context(), input, output);
340}
341
342void CLAbsLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
343{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100344 _impl->src = input;
345 _impl->dst = output;
346 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLAbsLayer>();
347 _impl->op->configure(compile_context, input->info(), output->info());
giuros01f24411f2019-05-16 11:47:13 +0100348}
349Status CLAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
350{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100351 return experimental::CLAbsLayer::validate(input, output);
giuros01f24411f2019-05-16 11:47:13 +0100352}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100353
354void CLAbsLayer::run()
355{
356 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
357 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
358
359 _impl->op->run(src, dst, {});
360}
361
362struct CLLogLayer::Impl
363{
364 const ICLTensor *src{ nullptr };
365 ICLTensor *dst{ nullptr };
366 std::unique_ptr<experimental::CLLogLayer> op{ nullptr };
367};
368
369CLLogLayer::CLLogLayer()
370 : _impl(support::cpp14::make_unique<Impl>())
371{
372}
373
374CLLogLayer::CLLogLayer(CLLogLayer &&) = default;
375CLLogLayer &CLLogLayer::operator=(CLLogLayer &&) = default;
376CLLogLayer::~CLLogLayer() = default;
377
Usama Arifac33d7e2019-05-20 14:21:40 +0100378void CLLogLayer::configure(const ICLTensor *input, ICLTensor *output)
379{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100380 configure(CLKernelLibrary::get().get_compile_context(), input, output);
381}
382
383void CLLogLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
384{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100385 _impl->src = input;
386 _impl->dst = output;
387 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLLogLayer>();
388 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arifac33d7e2019-05-20 14:21:40 +0100389}
390Status CLLogLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
391{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100392 return experimental::CLLogLayer::validate(input, output);
Usama Arifac33d7e2019-05-20 14:21:40 +0100393}
giuros01f24411f2019-05-16 11:47:13 +0100394
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100395void CLLogLayer::run()
396{
397 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
398 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
399
400 _impl->op->run(src, dst, {});
401}
402
403struct CLRoundLayer::Impl
404{
405 const ICLTensor *src{ nullptr };
406 ICLTensor *dst{ nullptr };
407 std::unique_ptr<experimental::CLRoundLayer> op{ nullptr };
408};
409
410CLRoundLayer::CLRoundLayer()
411 : _impl(support::cpp14::make_unique<Impl>())
412{
413}
414
415CLRoundLayer::CLRoundLayer(CLRoundLayer &&) = default;
416CLRoundLayer &CLRoundLayer::operator=(CLRoundLayer &&) = default;
417CLRoundLayer::~CLRoundLayer() = default;
418
Usama Arif6a4d5422019-05-24 14:53:59 +0100419void CLRoundLayer::configure(const ICLTensor *input, ICLTensor *output)
420{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100421 configure(CLKernelLibrary::get().get_compile_context(), input, output);
422}
423
424void CLRoundLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
425{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100426 _impl->src = input;
427 _impl->dst = output;
428 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLRoundLayer>();
429 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arif6a4d5422019-05-24 14:53:59 +0100430}
431Status CLRoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
432{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100433 return experimental::CLRoundLayer::validate(input, output);
Usama Arif6a4d5422019-05-24 14:53:59 +0100434}
435
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100436void CLRoundLayer::run()
437{
438 const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } };
439 const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } };
440
441 _impl->op->run(src, dst, {});
442}
Michalis Spyroue9362622018-11-23 17:41:37 +0000443} // namespace arm_compute