blob: bf6986866342c44baa7270d4b44122aadf8acb7f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitasf47f7182021-01-15 09:29:50 +00002 * Copyright (c) 2016-2021 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"
Michel Iwaniec00633802017-10-12 14:14:15 +010027#include "arm_compute/core/Types.h"
Georgios Pinitasf47f7182021-01-15 09:29:50 +000028#include "arm_compute/core/Validate.h"
Pablo Tellodb8485a2019-09-24 11:03:47 +010029#include "arm_compute/runtime/CL/CLRuntimeContext.h"
Georgios Pinitasf47f7182021-01-15 09:29:50 +000030#include "src/core/CL/ICLKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010031#include "src/gpu/cl/operators/ClActivation.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
Georgios Pinitas12833d02019-07-25 13:31:10 +010033namespace arm_compute
34{
Georgios Pinitasab23dd02020-07-06 14:57:36 +010035struct CLActivationLayer::Impl
36{
Georgios Pinitasf47f7182021-01-15 09:29:50 +000037 const ICLTensor *src{ nullptr };
38 ICLTensor *dst{ nullptr };
39 CLRuntimeContext *ctx{ nullptr };
40 std::unique_ptr<opencl::ClActivation> op{ nullptr };
Georgios Pinitasab23dd02020-07-06 14:57:36 +010041};
42
43CLActivationLayer::CLActivationLayer(CLRuntimeContext *ctx)
Georgios Pinitas40f51a62020-11-21 03:04:18 +000044 : _impl(std::make_unique<Impl>())
Georgios Pinitasab23dd02020-07-06 14:57:36 +010045{
46 _impl->ctx = ctx;
47}
Georgios Pinitasab23dd02020-07-06 14:57:36 +010048CLActivationLayer::CLActivationLayer(CLActivationLayer &&) = default;
Georgios Pinitasab23dd02020-07-06 14:57:36 +010049CLActivationLayer &CLActivationLayer::operator=(CLActivationLayer &&) = default;
Georgios Pinitasf47f7182021-01-15 09:29:50 +000050CLActivationLayer::~CLActivationLayer() = default;
Georgios Pinitasab23dd02020-07-06 14:57:36 +010051
52void CLActivationLayer::configure(ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info)
53{
54 configure(CLKernelLibrary::get().get_compile_context(), input, output, act_info);
55}
56
57void CLActivationLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info)
58{
59 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
60
61 _impl->src = input;
62 _impl->dst = output == nullptr ? input : output;
63
Georgios Pinitasf47f7182021-01-15 09:29:50 +000064 _impl->op = std::make_unique<opencl::ClActivation>();
Georgios Pinitasab23dd02020-07-06 14:57:36 +010065 _impl->op->configure(compile_context, _impl->src->info(), _impl->dst->info(), act_info);
66}
67
68Status CLActivationLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
69{
Georgios Pinitasf47f7182021-01-15 09:29:50 +000070 return opencl::ClActivation::validate(input, output, act_info);
Georgios Pinitasab23dd02020-07-06 14:57:36 +010071}
72
73void CLActivationLayer::run()
74{
Georgios Pinitas0499dff2020-07-31 22:21:38 +010075 ITensorPack pack;
76 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
77 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
78 _impl->op->run(pack);
Georgios Pinitasab23dd02020-07-06 14:57:36 +010079}
Georgios Pinitas12833d02019-07-25 13:31:10 +010080} // namespace arm_compute