blob: 99d07dc8dae2f5abe23dcabcc39c2cf523122f73 [file] [log] [blame]
Georgios Pinitas6f669f02017-09-26 12:32:57 +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/NormalizationLayer.h"
25
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/functions/CLNormalizationLayer.h"
28#include "arm_compute/runtime/NEON/functions/NENormalizationLayer.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{
Georgios Pinitasff421f22017-10-04 16:53:58 +010037template <typename NormalizationType, typename TensorType, TargetHint target_hint>
Georgios Pinitas6f669f02017-09-26 12:32:57 +010038std::unique_ptr<arm_compute::IFunction> instantiate_function(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info)
39{
40 auto norm = arm_compute::support::cpp14::make_unique<NormalizationType>();
41 norm->configure(
42 dynamic_cast<TensorType *>(input),
43 dynamic_cast<TensorType *>(output),
44 norm_info);
45
46 return std::move(norm);
47}
48
Georgios Pinitasff421f22017-10-04 16:53:58 +010049template <TargetHint target_hint>
Georgios Pinitas6f669f02017-09-26 12:32:57 +010050std::unique_ptr<arm_compute::IFunction> instantiate(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info);
51
52template <>
Georgios Pinitasff421f22017-10-04 16:53:58 +010053std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::OPENCL>(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010054{
Georgios Pinitasff421f22017-10-04 16:53:58 +010055 return instantiate_function<arm_compute::CLNormalizationLayer, arm_compute::CLTensor, TargetHint::OPENCL>(input, output, norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010056}
57
58template <>
Georgios Pinitasff421f22017-10-04 16:53:58 +010059std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::NEON>(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010060{
Georgios Pinitasff421f22017-10-04 16:53:58 +010061 return instantiate_function<arm_compute::NENormalizationLayer, arm_compute::Tensor, TargetHint::NEON>(input, output, norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010062}
63} // namespace
64
65NormalizationLayer::NormalizationLayer(const NormalizationLayerInfo norm_info)
66 : _norm_info(norm_info)
67{
68}
69
Georgios Pinitasff421f22017-10-04 16:53:58 +010070std::unique_ptr<arm_compute::IFunction> NormalizationLayer::instantiate_node(GraphContext &ctx, ITensor *input, ITensor *output)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010071{
72 std::unique_ptr<arm_compute::IFunction> func;
Georgios Pinitasff421f22017-10-04 16:53:58 +010073 _target_hint = ctx.hints().target_hint();
74 _input = input;
75 _output = output;
Georgios Pinitas6f669f02017-09-26 12:32:57 +010076
Georgios Pinitasff421f22017-10-04 16:53:58 +010077 if(_target_hint == TargetHint::OPENCL)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010078 {
Georgios Pinitasff421f22017-10-04 16:53:58 +010079 func = instantiate<TargetHint::OPENCL>(input, output, _norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010080 }
81 else
82 {
Georgios Pinitasff421f22017-10-04 16:53:58 +010083 func = instantiate<TargetHint::NEON>(input, output, _norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010084 }
85
86 return func;
87}
88
89void NormalizationLayer::print_info()
90{
Georgios Pinitasff421f22017-10-04 16:53:58 +010091 if(_target_hint == TargetHint::OPENCL)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010092 {
93 std::cout << "Instantiating CLNormalizationLayer";
94 }
95 else
96 {
97 std::cout << "Instantiating NENormalizationLayer";
98 }
99
100 std::cout << " Data Type: " << _input->info()->data_type()
101 << " Input shape: " << _input->info()->tensor_shape()
102 << " Output shape: " << _output->info()->tensor_shape()
103 << " Normalization info: " << _norm_info
104 << std::endl;
105}