Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 33 | using namespace arm_compute::graph; |
| 34 | |
| 35 | namespace |
| 36 | { |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 37 | template <typename NormalizationType, typename TensorType, TargetHint target_hint> |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 38 | std::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 Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 49 | template <TargetHint target_hint> |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 50 | std::unique_ptr<arm_compute::IFunction> instantiate(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info); |
| 51 | |
| 52 | template <> |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 53 | std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::OPENCL>(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info) |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 54 | { |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 55 | return instantiate_function<arm_compute::CLNormalizationLayer, arm_compute::CLTensor, TargetHint::OPENCL>(input, output, norm_info); |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | template <> |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 59 | std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::NEON>(ITensor *input, ITensor *output, const NormalizationLayerInfo &norm_info) |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 60 | { |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 61 | return instantiate_function<arm_compute::NENormalizationLayer, arm_compute::Tensor, TargetHint::NEON>(input, output, norm_info); |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 62 | } |
| 63 | } // namespace |
| 64 | |
| 65 | NormalizationLayer::NormalizationLayer(const NormalizationLayerInfo norm_info) |
| 66 | : _norm_info(norm_info) |
| 67 | { |
| 68 | } |
| 69 | |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 70 | std::unique_ptr<arm_compute::IFunction> NormalizationLayer::instantiate_node(GraphContext &ctx, ITensor *input, ITensor *output) |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 71 | { |
| 72 | std::unique_ptr<arm_compute::IFunction> func; |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 73 | _target_hint = ctx.hints().target_hint(); |
| 74 | _input = input; |
| 75 | _output = output; |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 76 | |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 77 | if(_target_hint == TargetHint::OPENCL) |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 78 | { |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 79 | func = instantiate<TargetHint::OPENCL>(input, output, _norm_info); |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 80 | } |
| 81 | else |
| 82 | { |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 83 | func = instantiate<TargetHint::NEON>(input, output, _norm_info); |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return func; |
| 87 | } |
| 88 | |
| 89 | void NormalizationLayer::print_info() |
| 90 | { |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame^] | 91 | if(_target_hint == TargetHint::OPENCL) |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 92 | { |
| 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 | } |