arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "HalPolicy.hpp" |
| 7 | |
| 8 | #include "../1.0/HalPolicy.hpp" |
| 9 | |
| 10 | namespace armnn_driver |
| 11 | { |
| 12 | namespace hal_1_1 |
| 13 | { |
| 14 | |
| 15 | bool HalPolicy::ConvertOperation(const Operation& operation, const Model& model, ConversionData& data) |
| 16 | { |
| 17 | if (compliantWithV1_0(operation)) |
| 18 | { |
| 19 | hal_1_0::HalPolicy::Operation v10Operation = convertToV1_0(operation); |
| 20 | hal_1_0::HalPolicy::Model v10Model = convertToV1_0(model); |
| 21 | |
| 22 | return hal_1_0::HalPolicy::ConvertOperation(v10Operation, v10Model, data); |
| 23 | } |
| 24 | else |
| 25 | { |
| 26 | switch (operation.type) |
| 27 | { |
| 28 | case V1_1::OperationType::DIV: |
| 29 | return ConvertDiv(operation, model, data); |
| 30 | default: |
| 31 | return Fail("%s: Operation type %s not supported in ArmnnDriver", |
| 32 | __func__, toString(operation.type).c_str()); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | bool HalPolicy::ConvertDiv(const Operation& operation, const Model& model, ConversionData& data) |
| 38 | { |
| 39 | LayerInputHandle input0 = ConvertToLayerInputHandle(operation, 0, model, data); |
| 40 | LayerInputHandle input1 = ConvertToLayerInputHandle(operation, 1, model, data); |
| 41 | |
| 42 | if (!input0.IsValid() || !input1.IsValid()) |
| 43 | { |
| 44 | return Fail("%s: Operation has invalid inputs", __func__); |
| 45 | } |
| 46 | |
| 47 | // The FuseActivation parameter is always the input index 2 |
| 48 | // and it should be optional |
| 49 | ActivationFn activationFunction; |
| 50 | if (!GetOptionalInputActivation(operation, 2, activationFunction, model, data)) |
| 51 | { |
| 52 | return Fail("%s: Operation has invalid inputs", __func__); |
| 53 | } |
| 54 | |
| 55 | const Operand* outputOperand = GetOutputOperand(operation, 0, model); |
| 56 | if (!outputOperand) |
| 57 | { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | const armnn::TensorInfo& outInfo = GetTensorInfoForOperand(*outputOperand); |
| 62 | |
| 63 | if (!IsLayerSupported(__func__, |
| 64 | armnn::IsDivisionSupported, |
| 65 | data.m_Compute, |
| 66 | input0.GetTensorInfo(), |
| 67 | input1.GetTensorInfo(), |
| 68 | outInfo)) |
| 69 | { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | armnn::IConnectableLayer* const startLayer = data.m_Network->AddDivisionLayer(); |
| 74 | armnn::IConnectableLayer* const endLayer = ProcessActivation(outInfo, activationFunction, startLayer, data); |
| 75 | |
| 76 | const armnn::TensorInfo& inputTensorInfo0 = input0.GetTensorInfo(); |
| 77 | const armnn::TensorInfo& inputTensorInfo1 = input1.GetTensorInfo(); |
| 78 | |
| 79 | if (endLayer) |
| 80 | { |
| 81 | BroadcastTensor(input0, input1, startLayer, *data.m_Network); |
| 82 | return SetupAndTrackLayerOutputSlot(operation, 0, *endLayer, model, data); |
| 83 | } |
| 84 | |
| 85 | return Fail("%s: ProcessActivation failed", __func__); |
| 86 | } |
| 87 | |
| 88 | } // namespace hal_1_1 |
| 89 | } // namespace armnn_driver |