blob: 60cf4d1a2dc0016d68ac4a30b0adfcb4f111876f [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"
Matthew Bentham92046462020-03-07 22:15:55 +000029#include "support/MemorySupport.h"
giuros011e6e1b82019-05-14 16:12:53 +010030
31namespace arm_compute
32{
Michalis Spyrouad7515d2020-07-24 00:02:23 +010033namespace experimental
giuros011e6e1b82019-05-14 16:12:53 +010034{
Michalis Spyrouad7515d2020-07-24 00:02:23 +010035CLPReluLayer::CLPReluLayer()
Michalis Spyrouad7515d2020-07-24 00:02:23 +010036{
Manuel Bottini2b84be52020-04-08 10:15:51 +010037}
38
Michalis Spyrouad7515d2020-07-24 00:02:23 +010039void CLPReluLayer::configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *alpha, ITensorInfo *output)
Manuel Bottini2b84be52020-04-08 10:15:51 +010040{
giuros011e6e1b82019-05-14 16:12:53 +010041 auto k = arm_compute::support::cpp14::make_unique<CLArithmeticOperationKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010042 k->configure(compile_context, ArithmeticOperation::PRELU, input, alpha, output);
giuros011e6e1b82019-05-14 16:12:53 +010043 _kernel = std::move(k);
giuros011e6e1b82019-05-14 16:12:53 +010044}
45
46Status CLPReluLayer::validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output)
47{
48 return CLArithmeticOperationKernel::validate(ArithmeticOperation::PRELU, input, alpha, output);
49}
Michalis Spyrouad7515d2020-07-24 00:02:23 +010050
Georgios Pinitas0499dff2020-07-31 22:21:38 +010051void CLPReluLayer::run(ITensorPack &tensors)
Michalis Spyrouad7515d2020-07-24 00:02:23 +010052{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010053 ICLOperator::run(tensors);
Michalis Spyrouad7515d2020-07-24 00:02:23 +010054}
55} // namespace experimental
56
57struct CLPReluLayer::Impl
58{
59 const ICLTensor *src_0{ nullptr };
60 const ICLTensor *src_1{ nullptr };
61 ICLTensor *dst{ nullptr };
62 std::unique_ptr<experimental::CLPReluLayer> op{ nullptr };
63};
64
65CLPReluLayer::CLPReluLayer()
66 : _impl(support::cpp14::make_unique<Impl>())
67{
68}
69CLPReluLayer::CLPReluLayer(CLPReluLayer &&) = default;
70CLPReluLayer &CLPReluLayer::operator=(CLPReluLayer &&) = default;
71CLPReluLayer::~CLPReluLayer() = default;
72
73void CLPReluLayer::configure(ICLTensor *input, ICLTensor *alpha, ICLTensor *output)
74{
75 configure(CLKernelLibrary::get().get_compile_context(), input, alpha, output);
76}
77
78void CLPReluLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *alpha, ICLTensor *output)
79{
80 _impl->src_0 = input;
81 _impl->src_1 = alpha;
82 _impl->dst = output;
83 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLPReluLayer>();
84 _impl->op->configure(compile_context, input->info(), alpha->info(), output->info());
85}
86
87Status CLPReluLayer::validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output)
88{
89 return experimental::CLPReluLayer::validate(input, alpha, output);
90}
91
92void CLPReluLayer::run()
93{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010094 ITensorPack pack;
95 pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0);
96 pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1);
97 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
Michalis Spyrouad7515d2020-07-24 00:02:23 +010098
Georgios Pinitas0499dff2020-07-31 22:21:38 +010099 _impl->op->run(pack);
Michalis Spyrouad7515d2020-07-24 00:02:23 +0100100}
giuros011e6e1b82019-05-14 16:12:53 +0100101} // namespace arm_compute