blob: c5689e159a2a5bf4a702df0bc551129963dc0f33 [file] [log] [blame]
Michalis Spyroua4a96012017-10-09 15:46:30 +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/L2NormalizeLayer.h"
25
Michalis Spyroua4a96012017-10-09 15:46:30 +010026#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/functions/CLL2Normalize.h"
28#include "arm_compute/runtime/NEON/functions/NEL2Normalize.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 L2NormalizeType, typename TensorType, TargetHint hint>
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010038std::unique_ptr<arm_compute::IFunction> instantiate_function(arm_compute::ITensor *input, arm_compute::ITensor *output, unsigned int axis, float epsilon)
Michalis Spyroua4a96012017-10-09 15:46:30 +010039{
40 auto l2norm = arm_compute::support::cpp14::make_unique<L2NormalizeType>();
41 l2norm->configure(
42 dynamic_cast<TensorType *>(input),
43 dynamic_cast<TensorType *>(output),
44 axis,
45 epsilon);
46
47 return std::move(l2norm);
48}
49
50template <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, unsigned int axis, float epsilon);
Michalis Spyroua4a96012017-10-09 15:46:30 +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, unsigned int axis, float epsilon)
Michalis Spyroua4a96012017-10-09 15:46:30 +010055{
56 return instantiate_function<arm_compute::CLL2Normalize, arm_compute::ICLTensor, TargetHint::OPENCL>(input, output, axis, epsilon);
57}
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, unsigned int axis, float epsilon)
Michalis Spyroua4a96012017-10-09 15:46:30 +010061{
62 return instantiate_function<arm_compute::NEL2Normalize, arm_compute::ITensor, TargetHint::NEON>(input, output, axis, epsilon);
63}
64} // namespace
65
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010066std::unique_ptr<arm_compute::IFunction> L2NormalizeLayer::instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output)
Michalis Spyroua4a96012017-10-09 15:46:30 +010067{
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010068 ARM_COMPUTE_ERROR_ON(input == nullptr || input->tensor() == nullptr);
69 ARM_COMPUTE_ERROR_ON(output == nullptr || output->tensor() == nullptr);
70
Michalis Spyroua4a96012017-10-09 15:46:30 +010071 std::unique_ptr<arm_compute::IFunction> func;
72 _target_hint = ctx.hints().target_hint();
73
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010074 arm_compute::ITensor *in = input->tensor();
75 arm_compute::ITensor *out = output->tensor();
76
Michalis Spyroua4a96012017-10-09 15:46:30 +010077 if(_target_hint == TargetHint::OPENCL)
78 {
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010079 func = instantiate<TargetHint::OPENCL>(in, out, _axis, _epsilon);
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010080 ARM_COMPUTE_LOG_GRAPH_INFO("Instantiating CLL2NormalizeLayer");
Michalis Spyroua4a96012017-10-09 15:46:30 +010081 }
82 else
83 {
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010084 func = instantiate<TargetHint::NEON>(in, out, _axis, _epsilon);
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010085 ARM_COMPUTE_LOG_GRAPH_INFO("Instantiating NEL2NormalizeLayer");
Michalis Spyroua4a96012017-10-09 15:46:30 +010086 }
87
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010088 ARM_COMPUTE_LOG_GRAPH_INFO(" Data Type: " << in->info()->data_type()
89 << " Input shape: " << in->info()->tensor_shape()
90 << " Output shape: " << out->info()->tensor_shape()
91 << std::endl);
Michalis Spyroua4a96012017-10-09 15:46:30 +010092
93 return func;
94}