blob: 9dcd2d18915edce2948ac2b8e95661bee6cfec56 [file] [log] [blame]
Michalis Spyroue9362622018-11-23 17:41:37 +00001/*
Michele Di Giorgioc9c89052021-01-26 10:20:17 +00002 * Copyright (c) 2018-2021 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 */
Jakub Sujakee301b32021-06-04 09:46:08 +010024#include "arm_compute/runtime/CL/functions/CLElementwiseUnaryLayer.h"
Michalis Spyroue9362622018-11-23 17:41:37 +000025
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000026#include "arm_compute/core/CL/CLKernelLibrary.h"
27#include "arm_compute/core/CL/ICLTensor.h"
28#include "src/core/CL/ICLKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/gpu/cl/operators/ClElementwiseUnary.h"
Michalis Spyroue9362622018-11-23 17:41:37 +000030
31namespace arm_compute
32{
Michalis Spyrouf738fe62020-07-15 18:10:17 +010033struct CLRsqrtLayer::Impl
34{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000035 const ICLTensor *src{ nullptr };
36 ICLTensor *dst{ nullptr };
37 std::unique_ptr<opencl::ClRsqrt> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +010038};
39
40CLRsqrtLayer::CLRsqrtLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +000041 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +010042{
43}
44
45CLRsqrtLayer::CLRsqrtLayer(CLRsqrtLayer &&) = default;
46CLRsqrtLayer &CLRsqrtLayer::operator=(CLRsqrtLayer &&) = default;
47CLRsqrtLayer::~CLRsqrtLayer() = default;
48
Michalis Spyroue9362622018-11-23 17:41:37 +000049void CLRsqrtLayer::configure(const ICLTensor *input, ICLTensor *output)
50{
Manuel Bottini2b84be52020-04-08 10:15:51 +010051 configure(CLKernelLibrary::get().get_compile_context(), input, output);
52}
53
54void CLRsqrtLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
55{
Michalis Spyrouf738fe62020-07-15 18:10:17 +010056 _impl->src = input;
57 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000058 _impl->op = std::make_unique<opencl::ClRsqrt>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +010059 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyroue9362622018-11-23 17:41:37 +000060}
Michalis Spyrouf738fe62020-07-15 18:10:17 +010061
Michalis Spyroue9362622018-11-23 17:41:37 +000062Status CLRsqrtLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
63{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000064 return opencl::ClRsqrt::validate(input, output);
Michalis Spyroue9362622018-11-23 17:41:37 +000065}
66
Michalis Spyrouf738fe62020-07-15 18:10:17 +010067void CLRsqrtLayer::run()
68{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010069 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +010073}
74
75struct CLExpLayer::Impl
76{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000077 const ICLTensor *src{ nullptr };
78 ICLTensor *dst{ nullptr };
79 std::unique_ptr<opencl::ClExp> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +010080};
81
82CLExpLayer::CLExpLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +000083 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +010084{
85}
86
87CLExpLayer::CLExpLayer(CLExpLayer &&) = default;
88CLExpLayer &CLExpLayer::operator=(CLExpLayer &&) = default;
89CLExpLayer::~CLExpLayer() = default;
90
Michalis Spyroue9362622018-11-23 17:41:37 +000091void CLExpLayer::configure(const ICLTensor *input, ICLTensor *output)
92{
Manuel Bottini2b84be52020-04-08 10:15:51 +010093 configure(CLKernelLibrary::get().get_compile_context(), input, output);
94}
95
96void CLExpLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
97{
Michalis Spyrouf738fe62020-07-15 18:10:17 +010098 _impl->src = input;
99 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000100 _impl->op = std::make_unique<opencl::ClExp>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100101 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyroue9362622018-11-23 17:41:37 +0000102}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100103
Michalis Spyroue9362622018-11-23 17:41:37 +0000104Status CLExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
105{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000106 return opencl::ClExp::validate(input, output);
Michalis Spyroue9362622018-11-23 17:41:37 +0000107}
Usama Arifeb312ef2019-05-13 17:45:54 +0100108
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100109void CLExpLayer::run()
110{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100111 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100115}
116
117struct CLNegLayer::Impl
118{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000119 const ICLTensor *src{ nullptr };
120 ICLTensor *dst{ nullptr };
121 std::unique_ptr<opencl::ClNeg> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100122};
123
124CLNegLayer::CLNegLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000125 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100126{
127}
128
129CLNegLayer::CLNegLayer(CLNegLayer &&) = default;
130CLNegLayer &CLNegLayer::operator=(CLNegLayer &&) = default;
131CLNegLayer::~CLNegLayer() = default;
132
Usama Arifeb312ef2019-05-13 17:45:54 +0100133void CLNegLayer::configure(const ICLTensor *input, ICLTensor *output)
134{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100135 configure(CLKernelLibrary::get().get_compile_context(), input, output);
136}
137
138void CLNegLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
139{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100140 _impl->src = input;
141 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000142 _impl->op = std::make_unique<opencl::ClNeg>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100143 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arifeb312ef2019-05-13 17:45:54 +0100144}
145Status CLNegLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
146{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000147 return opencl::ClNeg::validate(input, output);
Usama Arifeb312ef2019-05-13 17:45:54 +0100148}
149
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100150void CLNegLayer::run()
151{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100152 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100156}
157
158struct CLSinLayer::Impl
159{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000160 const ICLTensor *src{ nullptr };
161 ICLTensor *dst{ nullptr };
162 std::unique_ptr<opencl::ClSin> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100163};
164
165CLSinLayer::CLSinLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000166 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100167{
168}
169
170CLSinLayer::CLSinLayer(CLSinLayer &&) = default;
171CLSinLayer &CLSinLayer::operator=(CLSinLayer &&) = default;
172CLSinLayer::~CLSinLayer() = default;
173
Michalis Spyrou0af44182019-05-17 14:04:47 +0100174void CLSinLayer::configure(const ICLTensor *input, ICLTensor *output)
175{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100176 configure(CLKernelLibrary::get().get_compile_context(), input, output);
177}
178
179void CLSinLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
180{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100181 _impl->src = input;
182 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000183 _impl->op = std::make_unique<opencl::ClSin>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100184 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyrou0af44182019-05-17 14:04:47 +0100185}
186Status CLSinLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
187{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000188 return opencl::ClSin::validate(input, output);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100189}
190
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100191void CLSinLayer::run()
192{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100193 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100197}
198
199struct CLAbsLayer::Impl
200{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000201 const ICLTensor *src{ nullptr };
202 ICLTensor *dst{ nullptr };
203 std::unique_ptr<opencl::ClAbs> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100204};
205
206CLAbsLayer::CLAbsLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000207 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100208{
209}
210
211CLAbsLayer::CLAbsLayer(CLAbsLayer &&) = default;
212CLAbsLayer &CLAbsLayer::operator=(CLAbsLayer &&) = default;
213CLAbsLayer::~CLAbsLayer() = default;
214
giuros01f24411f2019-05-16 11:47:13 +0100215void CLAbsLayer::configure(const ICLTensor *input, ICLTensor *output)
216{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100217 configure(CLKernelLibrary::get().get_compile_context(), input, output);
218}
219
220void CLAbsLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
221{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100222 _impl->src = input;
223 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000224 _impl->op = std::make_unique<opencl::ClAbs>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100225 _impl->op->configure(compile_context, input->info(), output->info());
giuros01f24411f2019-05-16 11:47:13 +0100226}
227Status CLAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
228{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000229 return opencl::ClAbs::validate(input, output);
giuros01f24411f2019-05-16 11:47:13 +0100230}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100231
232void CLAbsLayer::run()
233{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100234 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100238}
239
240struct CLLogLayer::Impl
241{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000242 const ICLTensor *src{ nullptr };
243 ICLTensor *dst{ nullptr };
244 std::unique_ptr<opencl::ClLog> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100245};
246
247CLLogLayer::CLLogLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000248 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100249{
250}
251
252CLLogLayer::CLLogLayer(CLLogLayer &&) = default;
253CLLogLayer &CLLogLayer::operator=(CLLogLayer &&) = default;
254CLLogLayer::~CLLogLayer() = default;
255
Usama Arifac33d7e2019-05-20 14:21:40 +0100256void CLLogLayer::configure(const ICLTensor *input, ICLTensor *output)
257{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100258 configure(CLKernelLibrary::get().get_compile_context(), input, output);
259}
260
261void CLLogLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
262{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100263 _impl->src = input;
264 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000265 _impl->op = std::make_unique<opencl::ClLog>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100266 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arifac33d7e2019-05-20 14:21:40 +0100267}
268Status CLLogLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
269{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000270 return opencl::ClLog::validate(input, output);
Usama Arifac33d7e2019-05-20 14:21:40 +0100271}
giuros01f24411f2019-05-16 11:47:13 +0100272
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100273void CLLogLayer::run()
274{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100275 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100279}
280
281struct CLRoundLayer::Impl
282{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000283 const ICLTensor *src{ nullptr };
284 ICLTensor *dst{ nullptr };
285 std::unique_ptr<opencl::ClRound> op{ nullptr };
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100286};
287
288CLRoundLayer::CLRoundLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000289 : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100290{
291}
292
293CLRoundLayer::CLRoundLayer(CLRoundLayer &&) = default;
294CLRoundLayer &CLRoundLayer::operator=(CLRoundLayer &&) = default;
295CLRoundLayer::~CLRoundLayer() = default;
296
Usama Arif6a4d5422019-05-24 14:53:59 +0100297void CLRoundLayer::configure(const ICLTensor *input, ICLTensor *output)
298{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100299 configure(CLKernelLibrary::get().get_compile_context(), input, output);
300}
301
302void CLRoundLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
303{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100304 _impl->src = input;
305 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000306 _impl->op = std::make_unique<opencl::ClRound>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100307 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arif6a4d5422019-05-24 14:53:59 +0100308}
309Status CLRoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
310{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000311 return opencl::ClRound::validate(input, output);
Usama Arif6a4d5422019-05-24 14:53:59 +0100312}
313
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100314void CLRoundLayer::run()
315{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100316 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);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100320}
Michalis Spyroue9362622018-11-23 17:41:37 +0000321} // namespace arm_compute