blob: 3043c26febdd58e9e095c5b220220750a0268212 [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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000029#include "src/core/CL/ICLKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010030#include "src/gpu/cl/operators/ClElementwiseUnary.h"
Michalis Spyroue9362622018-11-23 17:41:37 +000031
32namespace arm_compute
33{
Michalis Spyrouf738fe62020-07-15 18:10:17 +010034struct CLRsqrtLayer::Impl
35{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010036 const ICLTensor *src{nullptr};
37 ICLTensor *dst{nullptr};
38 std::unique_ptr<opencl::ClRsqrt> op{nullptr};
Michalis Spyrouf738fe62020-07-15 18:10:17 +010039};
40
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010041CLRsqrtLayer::CLRsqrtLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +010042{
43}
44
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010045CLRsqrtLayer::CLRsqrtLayer(CLRsqrtLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +010046CLRsqrtLayer &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{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010077 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
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082CLExpLayer::CLExpLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +010083{
84}
85
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010086CLExpLayer::CLExpLayer(CLExpLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +010087CLExpLayer &CLExpLayer::operator=(CLExpLayer &&) = default;
88CLExpLayer::~CLExpLayer() = default;
89
Michalis Spyroue9362622018-11-23 17:41:37 +000090void CLExpLayer::configure(const ICLTensor *input, ICLTensor *output)
91{
Manuel Bottini2b84be52020-04-08 10:15:51 +010092 configure(CLKernelLibrary::get().get_compile_context(), input, output);
93}
94
95void CLExpLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
96{
Michalis Spyrouf738fe62020-07-15 18:10:17 +010097 _impl->src = input;
98 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +000099 _impl->op = std::make_unique<opencl::ClExp>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100100 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyroue9362622018-11-23 17:41:37 +0000101}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100102
Michalis Spyroue9362622018-11-23 17:41:37 +0000103Status CLExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
104{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000105 return opencl::ClExp::validate(input, output);
Michalis Spyroue9362622018-11-23 17:41:37 +0000106}
Usama Arifeb312ef2019-05-13 17:45:54 +0100107
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100108void CLExpLayer::run()
109{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100110 ITensorPack pack;
111 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
112 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
113 _impl->op->run(pack);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100114}
115
116struct CLNegLayer::Impl
117{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100118 const ICLTensor *src{nullptr};
119 ICLTensor *dst{nullptr};
120 std::unique_ptr<opencl::ClNeg> op{nullptr};
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100121};
122
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100123CLNegLayer::CLNegLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100124{
125}
126
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100127CLNegLayer::CLNegLayer(CLNegLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100128CLNegLayer &CLNegLayer::operator=(CLNegLayer &&) = default;
129CLNegLayer::~CLNegLayer() = default;
130
Usama Arifeb312ef2019-05-13 17:45:54 +0100131void CLNegLayer::configure(const ICLTensor *input, ICLTensor *output)
132{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100133 configure(CLKernelLibrary::get().get_compile_context(), input, output);
134}
135
136void CLNegLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
137{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100138 _impl->src = input;
139 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000140 _impl->op = std::make_unique<opencl::ClNeg>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100141 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arifeb312ef2019-05-13 17:45:54 +0100142}
143Status CLNegLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
144{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000145 return opencl::ClNeg::validate(input, output);
Usama Arifeb312ef2019-05-13 17:45:54 +0100146}
147
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100148void CLNegLayer::run()
149{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100150 ITensorPack pack;
151 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
152 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
153 _impl->op->run(pack);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100154}
155
156struct CLSinLayer::Impl
157{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100158 const ICLTensor *src{nullptr};
159 ICLTensor *dst{nullptr};
160 std::unique_ptr<opencl::ClSin> op{nullptr};
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100161};
162
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100163CLSinLayer::CLSinLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100164{
165}
166
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100167CLSinLayer::CLSinLayer(CLSinLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100168CLSinLayer &CLSinLayer::operator=(CLSinLayer &&) = default;
169CLSinLayer::~CLSinLayer() = default;
170
Michalis Spyrou0af44182019-05-17 14:04:47 +0100171void CLSinLayer::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 CLSinLayer::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;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000180 _impl->op = std::make_unique<opencl::ClSin>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100181 _impl->op->configure(compile_context, input->info(), output->info());
Michalis Spyrou0af44182019-05-17 14:04:47 +0100182}
183Status CLSinLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
184{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000185 return opencl::ClSin::validate(input, output);
Michalis Spyrou0af44182019-05-17 14:04:47 +0100186}
187
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100188void CLSinLayer::run()
189{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100190 ITensorPack pack;
191 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
192 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
193 _impl->op->run(pack);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100194}
195
196struct CLAbsLayer::Impl
197{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100198 const ICLTensor *src{nullptr};
199 ICLTensor *dst{nullptr};
200 std::unique_ptr<opencl::ClAbs> op{nullptr};
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100201};
202
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100203CLAbsLayer::CLAbsLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100204{
205}
206
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100207CLAbsLayer::CLAbsLayer(CLAbsLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100208CLAbsLayer &CLAbsLayer::operator=(CLAbsLayer &&) = default;
209CLAbsLayer::~CLAbsLayer() = default;
210
giuros01f24411f2019-05-16 11:47:13 +0100211void CLAbsLayer::configure(const ICLTensor *input, ICLTensor *output)
212{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100213 configure(CLKernelLibrary::get().get_compile_context(), input, output);
214}
215
216void CLAbsLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
217{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100218 _impl->src = input;
219 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000220 _impl->op = std::make_unique<opencl::ClAbs>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100221 _impl->op->configure(compile_context, input->info(), output->info());
giuros01f24411f2019-05-16 11:47:13 +0100222}
223Status CLAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
224{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000225 return opencl::ClAbs::validate(input, output);
giuros01f24411f2019-05-16 11:47:13 +0100226}
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100227
228void CLAbsLayer::run()
229{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100230 ITensorPack pack;
231 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
232 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
233 _impl->op->run(pack);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100234}
235
236struct CLLogLayer::Impl
237{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100238 const ICLTensor *src{nullptr};
239 ICLTensor *dst{nullptr};
240 std::unique_ptr<opencl::ClLog> op{nullptr};
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100241};
242
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100243CLLogLayer::CLLogLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100244{
245}
246
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100247CLLogLayer::CLLogLayer(CLLogLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100248CLLogLayer &CLLogLayer::operator=(CLLogLayer &&) = default;
249CLLogLayer::~CLLogLayer() = default;
250
Usama Arifac33d7e2019-05-20 14:21:40 +0100251void CLLogLayer::configure(const ICLTensor *input, ICLTensor *output)
252{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100253 configure(CLKernelLibrary::get().get_compile_context(), input, output);
254}
255
256void CLLogLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
257{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100258 _impl->src = input;
259 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000260 _impl->op = std::make_unique<opencl::ClLog>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100261 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arifac33d7e2019-05-20 14:21:40 +0100262}
263Status CLLogLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
264{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000265 return opencl::ClLog::validate(input, output);
Usama Arifac33d7e2019-05-20 14:21:40 +0100266}
giuros01f24411f2019-05-16 11:47:13 +0100267
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100268void CLLogLayer::run()
269{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100270 ITensorPack pack;
271 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
272 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
273 _impl->op->run(pack);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100274}
275
276struct CLRoundLayer::Impl
277{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100278 const ICLTensor *src{nullptr};
279 ICLTensor *dst{nullptr};
280 std::unique_ptr<opencl::ClRound> op{nullptr};
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100281};
282
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100283CLRoundLayer::CLRoundLayer() : _impl(std::make_unique<Impl>())
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100284{
285}
286
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100287CLRoundLayer::CLRoundLayer(CLRoundLayer &&) = default;
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100288CLRoundLayer &CLRoundLayer::operator=(CLRoundLayer &&) = default;
289CLRoundLayer::~CLRoundLayer() = default;
290
Usama Arif6a4d5422019-05-24 14:53:59 +0100291void CLRoundLayer::configure(const ICLTensor *input, ICLTensor *output)
292{
Manuel Bottini2b84be52020-04-08 10:15:51 +0100293 configure(CLKernelLibrary::get().get_compile_context(), input, output);
294}
295
296void CLRoundLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
297{
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100298 _impl->src = input;
299 _impl->dst = output;
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000300 _impl->op = std::make_unique<opencl::ClRound>();
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100301 _impl->op->configure(compile_context, input->info(), output->info());
Usama Arif6a4d5422019-05-24 14:53:59 +0100302}
303Status CLRoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
304{
Michele Di Giorgioc9c89052021-01-26 10:20:17 +0000305 return opencl::ClRound::validate(input, output);
Usama Arif6a4d5422019-05-24 14:53:59 +0100306}
307
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100308void CLRoundLayer::run()
309{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100310 ITensorPack pack;
311 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
312 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
313 _impl->op->run(pack);
Michalis Spyrouf738fe62020-07-15 18:10:17 +0100314}
Michalis Spyroue9362622018-11-23 17:41:37 +0000315} // namespace arm_compute