Kaizen | bf8b01d | 2017-10-12 14:26:51 +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/L2NormalizeLayer.h" |
| 25 | |
| 26 | #include "arm_compute/core/Logger.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLL2Normalize.h" |
| 29 | #include "arm_compute/runtime/NEON/functions/NEL2Normalize.h" |
| 30 | #include "arm_compute/runtime/Tensor.h" |
| 31 | #include "support/ToolchainSupport.h" |
| 32 | #include "utils/TypePrinter.h" |
| 33 | |
| 34 | using namespace arm_compute::graph; |
| 35 | |
| 36 | namespace |
| 37 | { |
| 38 | template <typename L2NormalizeType, typename TensorType, TargetHint hint> |
| 39 | std::unique_ptr<arm_compute::IFunction> instantiate_function(ITensor *input, ITensor *output, unsigned int axis, float epsilon) |
| 40 | { |
| 41 | auto l2norm = arm_compute::support::cpp14::make_unique<L2NormalizeType>(); |
| 42 | l2norm->configure( |
| 43 | dynamic_cast<TensorType *>(input), |
| 44 | dynamic_cast<TensorType *>(output), |
| 45 | axis, |
| 46 | epsilon); |
| 47 | |
| 48 | return std::move(l2norm); |
| 49 | } |
| 50 | |
| 51 | template <TargetHint target_hint> |
| 52 | std::unique_ptr<arm_compute::IFunction> instantiate(ITensor *input, ITensor *output, unsigned int axis, float epsilon); |
| 53 | |
| 54 | template <> |
| 55 | std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::OPENCL>(ITensor *input, ITensor *output, unsigned int axis, float epsilon) |
| 56 | { |
| 57 | return instantiate_function<arm_compute::CLL2Normalize, arm_compute::ICLTensor, TargetHint::OPENCL>(input, output, axis, epsilon); |
| 58 | } |
| 59 | |
| 60 | template <> |
| 61 | std::unique_ptr<arm_compute::IFunction> instantiate<TargetHint::NEON>(ITensor *input, ITensor *output, unsigned int axis, float epsilon) |
| 62 | { |
| 63 | return instantiate_function<arm_compute::NEL2Normalize, arm_compute::ITensor, TargetHint::NEON>(input, output, axis, epsilon); |
| 64 | } |
| 65 | } // namespace |
| 66 | |
| 67 | std::unique_ptr<arm_compute::IFunction> L2NormalizeLayer::instantiate_node(GraphContext &ctx, ITensor *input, ITensor *output) |
| 68 | { |
| 69 | std::unique_ptr<arm_compute::IFunction> func; |
| 70 | _target_hint = ctx.hints().target_hint(); |
| 71 | |
| 72 | if(_target_hint == TargetHint::OPENCL) |
| 73 | { |
| 74 | func = instantiate<TargetHint::OPENCL>(input, output, _axis, _epsilon); |
| 75 | ARM_COMPUTE_LOG("Instantiating CLL2NormalizeLayer"); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | func = instantiate<TargetHint::NEON>(input, output, _axis, _epsilon); |
| 80 | ARM_COMPUTE_LOG("Instantiating NEL2NormalizeLayer"); |
| 81 | } |
| 82 | |
| 83 | ARM_COMPUTE_LOG(" Data Type: " << input->info()->data_type() |
| 84 | << " Input shape: " << input->info()->tensor_shape() |
| 85 | << " Output shape: " << output->info()->tensor_shape() |
| 86 | << std::endl); |
| 87 | |
| 88 | return func; |
| 89 | } |