blob: 876b5de0f7dc11ff2e8ae17d88a0351fb9d837eb [file] [log] [blame]
giuros011e6e1b82019-05-14 16:12:53 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
giuros011e6e1b82019-05-14 16:12:53 +01003 *
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 */
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010024#include "src/core/CL/kernels/CLElementwiseOperationKernel.h"
giuros011e6e1b82019-05-14 16:12:53 +010025
26#include "arm_compute/core/CL/ICLTensor.h"
Michalis Spyrouad7515d2020-07-24 00:02:23 +010027#include "arm_compute/runtime/CL/CLScheduler.h"
giuros011e6e1b82019-05-14 16:12:53 +010028#include "arm_compute/runtime/CL/functions/CLPReluLayer.h"
giuros011e6e1b82019-05-14 16:12:53 +010029
30namespace arm_compute
31{
Michalis Spyrouad7515d2020-07-24 00:02:23 +010032namespace experimental
giuros011e6e1b82019-05-14 16:12:53 +010033{
Michalis Spyrouad7515d2020-07-24 00:02:23 +010034CLPReluLayer::CLPReluLayer()
Michalis Spyrouad7515d2020-07-24 00:02:23 +010035{
Manuel Bottini2b84be52020-04-08 10:15:51 +010036}
37
Michalis Spyrouad7515d2020-07-24 00:02:23 +010038void CLPReluLayer::configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *alpha, ITensorInfo *output)
Manuel Bottini2b84be52020-04-08 10:15:51 +010039{
Georgios Pinitas40f51a62020-11-21 03:04:18 +000040 auto k = std::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010041 k->configure(compile_context, ArithmeticOperation::PRELU, input, alpha, output);
giuros011e6e1b82019-05-14 16:12:53 +010042 _kernel = std::move(k);
giuros011e6e1b82019-05-14 16:12:53 +010043}
44
45Status CLPReluLayer::validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output)
46{
47 return CLArithmeticOperationKernel::validate(ArithmeticOperation::PRELU, input, alpha, output);
48}
Michalis Spyrouad7515d2020-07-24 00:02:23 +010049
Georgios Pinitas0499dff2020-07-31 22:21:38 +010050void CLPReluLayer::run(ITensorPack &tensors)
Michalis Spyrouad7515d2020-07-24 00:02:23 +010051{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010052 ICLOperator::run(tensors);
Michalis Spyrouad7515d2020-07-24 00:02:23 +010053}
54} // namespace experimental
55
56struct CLPReluLayer::Impl
57{
58 const ICLTensor *src_0{ nullptr };
59 const ICLTensor *src_1{ nullptr };
60 ICLTensor *dst{ nullptr };
61 std::unique_ptr<experimental::CLPReluLayer> op{ nullptr };
62};
63
64CLPReluLayer::CLPReluLayer()
Georgios Pinitas40f51a62020-11-21 03:04:18 +000065 : _impl(std::make_unique<Impl>())
Michalis Spyrouad7515d2020-07-24 00:02:23 +010066{
67}
68CLPReluLayer::CLPReluLayer(CLPReluLayer &&) = default;
69CLPReluLayer &CLPReluLayer::operator=(CLPReluLayer &&) = default;
70CLPReluLayer::~CLPReluLayer() = default;
71
72void CLPReluLayer::configure(ICLTensor *input, ICLTensor *alpha, ICLTensor *output)
73{
74 configure(CLKernelLibrary::get().get_compile_context(), input, alpha, output);
75}
76
77void CLPReluLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *alpha, ICLTensor *output)
78{
79 _impl->src_0 = input;
80 _impl->src_1 = alpha;
81 _impl->dst = output;
Georgios Pinitas40f51a62020-11-21 03:04:18 +000082 _impl->op = std::make_unique<experimental::CLPReluLayer>();
Michalis Spyrouad7515d2020-07-24 00:02:23 +010083 _impl->op->configure(compile_context, input->info(), alpha->info(), output->info());
84}
85
86Status CLPReluLayer::validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output)
87{
88 return experimental::CLPReluLayer::validate(input, alpha, output);
89}
90
91void CLPReluLayer::run()
92{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010093 ITensorPack pack;
94 pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0);
95 pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1);
96 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
Michalis Spyrouad7515d2020-07-24 00:02:23 +010097
Georgios Pinitas0499dff2020-07-31 22:21:38 +010098 _impl->op->run(pack);
Michalis Spyrouad7515d2020-07-24 00:02:23 +010099}
giuros011e6e1b82019-05-14 16:12:53 +0100100} // namespace arm_compute