blob: 319a4252b64244aaba79e0b544d7e3b3f3ead00c [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
Michalis Spyroue4720822017-10-02 17:44:52 +010026#include "arm_compute/core/Logger.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010027#include "arm_compute/runtime/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/functions/CLNormalizationLayer.h"
29#include "arm_compute/runtime/NEON/functions/NENormalizationLayer.h"
30#include "arm_compute/runtime/Tensor.h"
31#include "support/ToolchainSupport.h"
32#include "utils/TypePrinter.h"
33
34using namespace arm_compute::graph;
35
36namespace
37{
Georgios Pinitasff421f22017-10-04 16:53:58 +010038template <typename NormalizationType, typename TensorType, TargetHint target_hint>
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010039std::unique_ptr<arm_compute::IFunction> instantiate_function(arm_compute::ITensor *input, arm_compute::ITensor *output, const NormalizationLayerInfo &norm_info)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010040{
41 auto norm = arm_compute::support::cpp14::make_unique<NormalizationType>();
42 norm->configure(
43 dynamic_cast<TensorType *>(input),
44 dynamic_cast<TensorType *>(output),
45 norm_info);
46
47 return std::move(norm);
48}
49
Georgios Pinitasff421f22017-10-04 16:53:58 +010050template <TargetHint target_hint>
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010051std::unique_ptr<arm_compute::IFunction> instantiate(arm_compute::ITensor *input, arm_compute::ITensor *output, const NormalizationLayerInfo &norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010052
53template <>
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010054std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::OPENCL>(arm_compute::ITensor *input, arm_compute::ITensor *output, const NormalizationLayerInfo &norm_info)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010055{
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010056 return instantiate_function<arm_compute::CLNormalizationLayer, arm_compute::ICLTensor, TargetHint::OPENCL>(input, output, norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010057}
58
59template <>
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010060std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::NEON>(arm_compute::ITensor *input, arm_compute::ITensor *output, const NormalizationLayerInfo &norm_info)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010061{
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010062 return instantiate_function<arm_compute::NENormalizationLayer, arm_compute::ITensor, TargetHint::NEON>(input, output, norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010063}
64} // namespace
65
66NormalizationLayer::NormalizationLayer(const NormalizationLayerInfo norm_info)
67 : _norm_info(norm_info)
68{
69}
70
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010071std::unique_ptr<arm_compute::IFunction> NormalizationLayer::instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010072{
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010073 ARM_COMPUTE_ERROR_ON(input == nullptr || input->tensor() == nullptr);
74 ARM_COMPUTE_ERROR_ON(output == nullptr || output->tensor() == nullptr);
75
Georgios Pinitas6f669f02017-09-26 12:32:57 +010076 std::unique_ptr<arm_compute::IFunction> func;
Georgios Pinitasff421f22017-10-04 16:53:58 +010077 _target_hint = ctx.hints().target_hint();
Georgios Pinitas6f669f02017-09-26 12:32:57 +010078
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010079 arm_compute::ITensor *in = input->tensor();
80 arm_compute::ITensor *out = output->tensor();
81
Georgios Pinitasff421f22017-10-04 16:53:58 +010082 if(_target_hint == TargetHint::OPENCL)
Georgios Pinitas6f669f02017-09-26 12:32:57 +010083 {
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010084 func = instantiate<TargetHint::OPENCL>(in, out, _norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010085 }
86 else
87 {
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010088 func = instantiate<TargetHint::NEON>(in, out, _norm_info);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010089 }
90
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010091 ARM_COMPUTE_LOG(" Data Type: " << in->info()->data_type()
92 << " Input shape: " << in->info()->tensor_shape()
93 << " Output shape: " << out->info()->tensor_shape()
Michalis Spyroue4720822017-10-02 17:44:52 +010094 << " Normalization info: " << _norm_info
95 << std::endl);
96
Georgios Pinitas6f669f02017-09-26 12:32:57 +010097 return func;
98}