Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2016-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 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 Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/ICLTensor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/kernels/CLActivationLayerKernel.h" |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Types.h" |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/CL/CLRuntimeContext.h" |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 30 | #include "support/MemorySupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 32 | namespace arm_compute |
| 33 | { |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 34 | namespace experimental |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 35 | { |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 36 | void CLActivationLayer::configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *output, ActivationLayerInfo act_info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 37 | { |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 38 | auto k = arm_compute::support::cpp14::make_unique<CLActivationLayerKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 39 | k->configure(compile_context, input, output, act_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | _kernel = std::move(k); |
| 41 | } |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 42 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 43 | Status CLActivationLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 44 | { |
| 45 | return CLActivationLayerKernel::validate(input, output, act_info); |
| 46 | } |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 47 | |
| 48 | MemoryRequirements CLActivationLayer::workspace() const |
| 49 | { |
| 50 | return MemoryRequirements{}; |
| 51 | } |
| 52 | } // namespace experimental |
| 53 | |
| 54 | struct CLActivationLayer::Impl |
| 55 | { |
| 56 | const ICLTensor *src{ nullptr }; |
| 57 | ICLTensor *dst{ nullptr }; |
| 58 | CLRuntimeContext *ctx{ nullptr }; |
| 59 | std::unique_ptr<experimental::CLActivationLayer> op{ nullptr }; |
| 60 | }; |
| 61 | |
| 62 | CLActivationLayer::CLActivationLayer(CLRuntimeContext *ctx) |
| 63 | : _impl(support::cpp14::make_unique<Impl>()) |
| 64 | { |
| 65 | _impl->ctx = ctx; |
| 66 | } |
| 67 | |
| 68 | CLActivationLayer::CLActivationLayer(CLActivationLayer &&) = default; |
| 69 | |
| 70 | CLActivationLayer &CLActivationLayer::operator=(CLActivationLayer &&) = default; |
| 71 | |
| 72 | CLActivationLayer::~CLActivationLayer() = default; |
| 73 | |
| 74 | void CLActivationLayer::configure(ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info) |
| 75 | { |
| 76 | configure(CLKernelLibrary::get().get_compile_context(), input, output, act_info); |
| 77 | } |
| 78 | |
| 79 | void CLActivationLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info) |
| 80 | { |
| 81 | ARM_COMPUTE_ERROR_ON_NULLPTR(input); |
| 82 | |
| 83 | _impl->src = input; |
| 84 | _impl->dst = output == nullptr ? input : output; |
| 85 | |
| 86 | _impl->op = arm_compute::support::cpp14::make_unique<experimental::CLActivationLayer>(); |
| 87 | _impl->op->configure(compile_context, _impl->src->info(), _impl->dst->info(), act_info); |
| 88 | } |
| 89 | |
| 90 | Status CLActivationLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
| 91 | { |
| 92 | return experimental::CLActivationLayer::validate(input, output, act_info); |
| 93 | } |
| 94 | |
| 95 | void CLActivationLayer::run() |
| 96 | { |
| 97 | const InputTensorMap src{ { TensorType::ACL_SRC, _impl->src } }; |
| 98 | const OutputTensorMap dst{ { TensorType::ACL_DST, _impl->dst } }; |
| 99 | |
| 100 | _impl->op->run(src, dst, {}); |
| 101 | } |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 102 | } // namespace arm_compute |