blob: 5ddf22738249f9edcb092377cc2b1998c1f9d105 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
24#include "arm_compute/runtime/CL/functions/CLActivationLayer.h"
25
Georgios Pinitasab23dd02020-07-06 14:57:36 +010026#include "arm_compute/core/CL/ICLTensor.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/CL/kernels/CLActivationLayerKernel.h"
Michel Iwaniec00633802017-10-12 14:14:15 +010028#include "arm_compute/core/Types.h"
Pablo Tellodb8485a2019-09-24 11:03:47 +010029#include "arm_compute/runtime/CL/CLRuntimeContext.h"
Matthew Bentham92046462020-03-07 22:15:55 +000030#include "support/MemorySupport.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
Georgios Pinitas12833d02019-07-25 13:31:10 +010032namespace arm_compute
33{
Georgios Pinitasab23dd02020-07-06 14:57:36 +010034namespace experimental
Georgios Pinitas12833d02019-07-25 13:31:10 +010035{
Georgios Pinitas09cad722020-07-22 12:11:20 +010036void CLActivation::configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *output, ActivationLayerInfo act_info)
Manuel Bottini2b84be52020-04-08 10:15:51 +010037{
Manuel Bottini4c6bd512020-04-08 10:15:51 +010038 auto k = arm_compute::support::cpp14::make_unique<CLActivationLayerKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010039 k->configure(compile_context, input, output, act_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040 _kernel = std::move(k);
41}
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000042
Georgios Pinitas09cad722020-07-22 12:11:20 +010043Status CLActivation::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000044{
45 return CLActivationLayerKernel::validate(input, output, act_info);
46}
Georgios Pinitasab23dd02020-07-06 14:57:36 +010047} // namespace experimental
48
49struct CLActivationLayer::Impl
50{
Georgios Pinitas09cad722020-07-22 12:11:20 +010051 const ICLTensor *src{ nullptr };
52 ICLTensor *dst{ nullptr };
53 CLRuntimeContext *ctx{ nullptr };
54 std::unique_ptr<experimental::CLActivation> op{ nullptr };
Georgios Pinitasab23dd02020-07-06 14:57:36 +010055};
56
57CLActivationLayer::CLActivationLayer(CLRuntimeContext *ctx)
58 : _impl(support::cpp14::make_unique<Impl>())
59{
60 _impl->ctx = ctx;
61}
62
63CLActivationLayer::CLActivationLayer(CLActivationLayer &&) = default;
64
65CLActivationLayer &CLActivationLayer::operator=(CLActivationLayer &&) = default;
66
67CLActivationLayer::~CLActivationLayer() = default;
68
69void CLActivationLayer::configure(ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info)
70{
71 configure(CLKernelLibrary::get().get_compile_context(), input, output, act_info);
72}
73
74void CLActivationLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info)
75{
76 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
77
78 _impl->src = input;
79 _impl->dst = output == nullptr ? input : output;
80
Georgios Pinitas09cad722020-07-22 12:11:20 +010081 _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLActivation>();
Georgios Pinitasab23dd02020-07-06 14:57:36 +010082 _impl->op->configure(compile_context, _impl->src->info(), _impl->dst->info(), act_info);
83}
84
85Status CLActivationLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
86{
Georgios Pinitas09cad722020-07-22 12:11:20 +010087 return experimental::CLActivation::validate(input, output, act_info);
Georgios Pinitasab23dd02020-07-06 14:57:36 +010088}
89
90void CLActivationLayer::run()
91{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010092 ITensorPack pack;
93 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
94 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
95 _impl->op->run(pack);
Georgios Pinitasab23dd02020-07-06 14:57:36 +010096}
Georgios Pinitas12833d02019-07-25 13:31:10 +010097} // namespace arm_compute