blob: b71e22c6018463b89d6e20f5a0b0911dc3f39618 [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
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/graph/nodes/ActivationLayer.h"
25
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/functions/CLActivationLayer.h"
28#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h"
29#include "arm_compute/runtime/Tensor.h"
30#include "support/ToolchainSupport.h"
31#include "utils/TypePrinter.h"
32
33using namespace arm_compute::graph;
34
35namespace
36{
37template <typename ActivationType, typename TensorType, Hint hint>
38std::unique_ptr<arm_compute::IFunction> instantiate_function(ITensor *input, ITensor *output, const ActivationLayerInfo &activation_info)
39{
40 auto activation = arm_compute::support::cpp14::make_unique<ActivationType>();
41 activation->configure(
42 dynamic_cast<TensorType *>(input),
43 dynamic_cast<TensorType *>(output),
44 activation_info);
45
46 return std::move(activation);
47}
48
49template <Hint hint>
50std::unique_ptr<arm_compute::IFunction> instantiate(ITensor *input, ITensor *output, const ActivationLayerInfo &activation_info);
51
52template <>
53std::unique_ptr<arm_compute::IFunction> instantiate<Hint::OPENCL>(ITensor *input, ITensor *output, const ActivationLayerInfo &activation_info)
54{
55 return instantiate_function<arm_compute::CLActivationLayer, arm_compute::CLTensor, Hint::OPENCL>(input, output, activation_info);
56}
57
58template <>
59std::unique_ptr<arm_compute::IFunction> instantiate<Hint::NEON>(ITensor *input, ITensor *output, const ActivationLayerInfo &activation_info)
60{
61 return instantiate_function<arm_compute::NEActivationLayer, arm_compute::Tensor, Hint::NEON>(input, output, activation_info);
62}
63} // namespace
64
65ActivationLayer::ActivationLayer(const ActivationLayerInfo activation_info)
66 : _activation_info(activation_info)
67{
68}
69
70std::unique_ptr<arm_compute::IFunction> ActivationLayer::instantiate_node(Hint hint, ITensor *input, ITensor *output)
71{
72 std::unique_ptr<arm_compute::IFunction> func;
73 _hint = hint;
74 _input = input;
75 _output = output;
76
77 if(_hint == Hint::OPENCL)
78 {
79 func = instantiate<Hint::OPENCL>(input, output, _activation_info);
80 }
81 else
82 {
83 func = instantiate<Hint::NEON>(input, output, _activation_info);
84 }
85 return func;
86}
87
88void ActivationLayer::print_info()
89{
90 if(_hint == Hint::OPENCL)
91 {
92 std::cout << "Instantiating CLActivationLayer";
93 }
94 else
95 {
96 std::cout << "Instantiating NEActivationLayer";
97 }
98
99 std::cout << " Data Type: " << _input->info()->data_type()
100 << " Input shape: " << _input->info()->tensor_shape()
101 << " Output shape: " << _output->info()->tensor_shape()
102 << " Activation function: " << _activation_info.activation()
103 << " a: " << _activation_info.a()
104 << " b: " << _activation_info.b()
105 << std::endl;
106}