Mike Kelly | b5fdf38 | 2019-06-11 16:35: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 | |
Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 8 | #include "OutputShapeUtils.hpp" |
| 9 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 10 | #include "../1.0/HalPolicy.hpp" |
| 11 | #include "../1.1/HalPolicy.hpp" |
| 12 | |
Aron Virginas-Tar | 7a6d11b | 2019-07-03 15:27:08 +0100 | [diff] [blame] | 13 | #include <DataLayoutIndexed.hpp> |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 14 | #include <Half.hpp> |
Aron Virginas-Tar | 7a6d11b | 2019-07-03 15:27:08 +0100 | [diff] [blame] | 15 | |
| 16 | #include <cmath> |
| 17 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 18 | namespace armnn_driver |
| 19 | { |
| 20 | namespace hal_1_2 |
| 21 | { |
| 22 | |
| 23 | bool HandledByV1_0(V1_2::OperationType operationType) |
| 24 | { |
| 25 | switch (static_cast<V1_0::OperationType>(operationType)) |
| 26 | { |
| 27 | case V1_0::OperationType::ADD: |
| 28 | case V1_0::OperationType::AVERAGE_POOL_2D: |
| 29 | case V1_0::OperationType::CONCATENATION: |
| 30 | case V1_0::OperationType::DEPTH_TO_SPACE: |
| 31 | case V1_0::OperationType::DEQUANTIZE: |
| 32 | case V1_0::OperationType::EMBEDDING_LOOKUP: |
| 33 | case V1_0::OperationType::FLOOR: |
| 34 | case V1_0::OperationType::FULLY_CONNECTED: |
| 35 | case V1_0::OperationType::HASHTABLE_LOOKUP: |
| 36 | case V1_0::OperationType::L2_NORMALIZATION: |
| 37 | case V1_0::OperationType::L2_POOL_2D: |
| 38 | case V1_0::OperationType::LOCAL_RESPONSE_NORMALIZATION: |
| 39 | case V1_0::OperationType::LOGISTIC: |
| 40 | case V1_0::OperationType::LSH_PROJECTION: |
| 41 | case V1_0::OperationType::LSTM: |
| 42 | case V1_0::OperationType::MAX_POOL_2D: |
| 43 | case V1_0::OperationType::MUL: |
| 44 | case V1_0::OperationType::RELU: |
| 45 | case V1_0::OperationType::RELU1: |
| 46 | case V1_0::OperationType::RELU6: |
| 47 | case V1_0::OperationType::RESHAPE: |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 48 | case V1_0::OperationType::RNN: |
| 49 | case V1_0::OperationType::SOFTMAX: |
| 50 | case V1_0::OperationType::SPACE_TO_DEPTH: |
| 51 | case V1_0::OperationType::SVDF: |
| 52 | case V1_0::OperationType::TANH: |
| 53 | case V1_0::OperationType::OEM_OPERATION: |
| 54 | return true; |
| 55 | default: |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | bool HandledByV1_1(V1_2::OperationType operationType) |
| 61 | { |
| 62 | if (HandledByV1_0(operationType)) |
| 63 | { |
| 64 | return true; |
| 65 | } |
| 66 | switch (static_cast<V1_1::OperationType>(operationType)) |
| 67 | { |
| 68 | case V1_1::OperationType::BATCH_TO_SPACE_ND: |
| 69 | case V1_1::OperationType::DIV: |
| 70 | case V1_1::OperationType::MEAN: |
| 71 | case V1_1::OperationType::PAD: |
| 72 | case V1_1::OperationType::SPACE_TO_BATCH_ND: |
| 73 | case V1_1::OperationType::SQUEEZE: |
| 74 | case V1_1::OperationType::STRIDED_SLICE: |
| 75 | case V1_1::OperationType::SUB: |
| 76 | case V1_1::OperationType::TRANSPOSE: |
| 77 | return true; |
| 78 | default: |
| 79 | return false; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | bool HandledByV1_0(const V1_2::Operation& operation) |
| 84 | { |
| 85 | return HandledByV1_0(operation.type); |
| 86 | } |
| 87 | |
| 88 | bool HandledByV1_1(const V1_2::Operation& operation) |
| 89 | { |
| 90 | return HandledByV1_1(operation.type); |
| 91 | } |
| 92 | |
| 93 | V1_0::OperationType CastToV1_0(V1_2::OperationType type) |
| 94 | { |
| 95 | return static_cast<V1_0::OperationType>(type); |
| 96 | } |
| 97 | |
| 98 | V1_1::OperationType CastToV1_1(V1_2::OperationType type) |
| 99 | { |
| 100 | return static_cast<V1_1::OperationType>(type); |
| 101 | } |
| 102 | |
| 103 | V1_0::Operation ConvertToV1_0(const V1_2::Operation& operation) |
| 104 | { |
| 105 | V1_0::Operation op; |
| 106 | op.type = CastToV1_0(operation.type); |
| 107 | op.inputs = operation.inputs; |
| 108 | op.outputs = operation.outputs; |
| 109 | return op; |
| 110 | } |
| 111 | |
| 112 | V1_1::Operation ConvertToV1_1(const V1_2::Operation& operation) |
| 113 | { |
| 114 | V1_1::Operation op; |
| 115 | op.type = CastToV1_1(operation.type); |
| 116 | op.inputs = operation.inputs; |
| 117 | op.outputs = operation.outputs; |
| 118 | return op; |
| 119 | } |
| 120 | |
| 121 | bool HalPolicy::ConvertOperation(const Operation& operation, const Model& model, ConversionData& data) |
| 122 | { |
| 123 | if (HandledByV1_0(operation) && compliantWithV1_0(model)) |
| 124 | { |
| 125 | hal_1_0::HalPolicy::Operation v10Operation = ConvertToV1_0(operation); |
| 126 | hal_1_0::HalPolicy::Model v10Model = convertToV1_0(model); |
| 127 | |
| 128 | return hal_1_0::HalPolicy::ConvertOperation(v10Operation, v10Model, data); |
| 129 | } |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 130 | |
| 131 | if (HandledByV1_1(operation) && compliantWithV1_1(model)) |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 132 | { |
| 133 | hal_1_1::HalPolicy::Operation v11Operation = ConvertToV1_1(operation); |
| 134 | hal_1_1::HalPolicy::Model v11Model = convertToV1_1(model); |
| 135 | |
| 136 | return hal_1_1::HalPolicy::ConvertOperation(v11Operation, v11Model, data); |
| 137 | } |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 138 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 139 | switch (operation.type) |
| 140 | { |
| 141 | case V1_2::OperationType::CONV_2D: |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 142 | return ConvertConv2d(operation, model, data); |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 143 | case V1_2::OperationType::DEPTHWISE_CONV_2D: |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 144 | return ConvertDepthwiseConv2d(operation, model, data); |
Narumol Prangnawarat | 95b1ef6 | 2019-07-15 12:02:20 +0100 | [diff] [blame^] | 145 | case V1_2::OperationType::MAXIMUM: |
| 146 | return ConvertMaximum(operation, model, data); |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 147 | case V1_2::OperationType::PAD_V2: |
| 148 | return ConvertPadV2(operation, model, data); |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 149 | case V1_2::OperationType::PRELU: |
| 150 | return ConvertPrelu(operation, model, data); |
Aron Virginas-Tar | fb2fa29 | 2019-07-04 11:59:48 +0100 | [diff] [blame] | 151 | case V1_2::OperationType::RESIZE_BILINEAR: |
| 152 | return ConvertResize(operation, model, data, armnn::ResizeMethod::Bilinear); |
Aron Virginas-Tar | 7a6d11b | 2019-07-03 15:27:08 +0100 | [diff] [blame] | 153 | case V1_2::OperationType::RESIZE_NEAREST_NEIGHBOR: |
Aron Virginas-Tar | fb2fa29 | 2019-07-04 11:59:48 +0100 | [diff] [blame] | 154 | return ConvertResize(operation, model, data, armnn::ResizeMethod::NearestNeighbor); |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 155 | default: |
| 156 | return Fail("%s: Operation type %s not supported in ArmnnDriver", |
| 157 | __func__, toString(operation.type).c_str()); |
| 158 | } |
| 159 | } |
| 160 | |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 161 | bool HalPolicy::ConvertConv2d(const Operation& operation, const Model& model, ConversionData& data) |
| 162 | { |
| 163 | LayerInputHandle input = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 164 | if (!input.IsValid()) |
| 165 | { |
| 166 | return Fail("%s: Operation has invalid inputs", __func__); |
| 167 | } |
| 168 | |
| 169 | const Operand* output = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 170 | if (!output) |
| 171 | { |
| 172 | return Fail("%s: Could not read output 0", __func__); |
| 173 | } |
| 174 | |
| 175 | const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); |
| 176 | const armnn::TensorInfo& outputInfo = GetTensorInfoForOperand(*output); |
| 177 | |
Aron Virginas-Tar | 366e0a6 | 2019-07-10 13:01:41 +0100 | [diff] [blame] | 178 | if (IsDynamicOutput(outputInfo)) |
| 179 | { |
| 180 | return Fail("%s: Dynamic output not supported", __func__); |
| 181 | } |
| 182 | |
Mike Kelly | e1d60bb | 2019-07-11 11:44:52 +0100 | [diff] [blame] | 183 | armnn::Convolution2dDescriptor desc; |
| 184 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 185 | |
| 186 | // Determine whether padding is implicit or explicit |
| 187 | bool implicitPadding = operation.inputs.size() == 7 || |
| 188 | (operation.inputs.size() >= 8 && |
| 189 | GetInputOperand<hal_1_2::HalPolicy>(operation, 7, model)->type == OperandType::BOOL); |
| 190 | |
| 191 | if (implicitPadding) |
| 192 | { |
| 193 | desc.m_DataLayout = OptionalDataLayout<hal_1_2::HalPolicy>(operation, 7, model, data); |
| 194 | } |
| 195 | else if (operation.inputs.size() >= 10) |
| 196 | { |
| 197 | desc.m_DataLayout = OptionalDataLayout<hal_1_2::HalPolicy>(operation, 10, model, data); |
| 198 | } |
| 199 | |
| 200 | const armnn::PermutationVector OHWIToOIHW = {0, 2, 3, 1}; |
| 201 | |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 202 | // ArmNN does not currently support non-fixed weights or bias |
Mike Kelly | e1d60bb | 2019-07-11 11:44:52 +0100 | [diff] [blame] | 203 | // The NNAPI filter is always OHWI [depth_out, filter_height, filter_width, depth_in] but ArmNN expects the |
| 204 | // filter's height and width indices to match the input's height and width indices so we permute it to OIHW if |
| 205 | // the DataLayout is NCHW |
| 206 | const ConstTensorPin weightsPin = (desc.m_DataLayout == armnn::DataLayout::NCHW) ? |
| 207 | ConvertOperationInputToConstTensorPin<hal_1_2::HalPolicy>(operation, 1, model, data, OHWIToOIHW) : |
| 208 | ConvertOperationInputToConstTensorPin<hal_1_2::HalPolicy>(operation, 1, model, data); |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 209 | const ConstTensorPin biasPin = |
Mike Kelly | e1d60bb | 2019-07-11 11:44:52 +0100 | [diff] [blame] | 210 | ConvertOperationInputToConstTensorPin<hal_1_2::HalPolicy>(operation, 2, model, data); |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 211 | |
| 212 | if (!weightsPin.IsValid()) |
| 213 | { |
| 214 | return Fail("%s: Operation has invalid weights", __func__); |
| 215 | } |
| 216 | |
| 217 | if (!biasPin.IsValid()) |
| 218 | { |
| 219 | return Fail("%s: Operation has invalid biases", __func__); |
| 220 | } |
| 221 | |
| 222 | armnn::ConstTensor weights = weightsPin.GetConstTensor(); |
| 223 | armnn::ConstTensor bias = biasPin.GetConstTensor(); |
| 224 | SanitizeBiasQuantizationScale(bias.GetInfo(), weights.GetInfo(), inputInfo); |
| 225 | |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 226 | ActivationFn activation; |
| 227 | |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 228 | if (implicitPadding) |
| 229 | { |
| 230 | android::nn::PaddingScheme paddingScheme; |
| 231 | if (!GetInputPaddingScheme<hal_1_2::HalPolicy>(operation, 3, paddingScheme, model, data) || |
| 232 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 4, OperandType::INT32, desc.m_StrideX, model, data) || |
| 233 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 5, OperandType::INT32, desc.m_StrideY, model, data) || |
| 234 | !GetInputActivationFunction<hal_1_2::HalPolicy>(operation, 6, activation, model, data) || |
| 235 | !GetOptionalConvolutionDilationParams<hal_1_2::HalPolicy>(operation, 8, desc, model, data)) |
| 236 | { |
| 237 | return Fail("%s: Operation has invalid inputs (implicit padding)", __func__); |
| 238 | } |
| 239 | |
Mike Kelly | e1d60bb | 2019-07-11 11:44:52 +0100 | [diff] [blame] | 240 | armnnUtils::DataLayoutIndexed dataLayoutIndexed(desc.m_DataLayout); |
| 241 | unsigned int widthIndex = dataLayoutIndexed.GetWidthIndex(); |
| 242 | unsigned int heightIndex = dataLayoutIndexed.GetHeightIndex(); |
| 243 | const uint32_t kernelX = weights.GetShape()[widthIndex]; |
| 244 | const uint32_t kernelY = weights.GetShape()[heightIndex]; |
| 245 | const uint32_t inputX = inputInfo.GetShape()[widthIndex]; |
| 246 | const uint32_t inputY = inputInfo.GetShape()[heightIndex]; |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 247 | |
Mike Kelly | 86b36d4 | 2019-07-12 16:39:33 +0100 | [diff] [blame] | 248 | CalcPadding(inputX, kernelX, desc.m_StrideX, desc.m_DilationX, desc.m_PadLeft, desc.m_PadRight, paddingScheme); |
| 249 | CalcPadding(inputY, kernelY, desc.m_StrideY, desc.m_DilationY, desc.m_PadTop, desc.m_PadBottom, paddingScheme); |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 250 | |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 251 | } |
| 252 | else if (operation.inputs.size() >= 10) |
| 253 | { |
| 254 | // explicit padding |
| 255 | if (!GetInputScalar<hal_1_2::HalPolicy>(operation, 3, OperandType::INT32, desc.m_PadLeft, model, data) || |
| 256 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 4, OperandType::INT32, desc.m_PadRight, model, data) || |
| 257 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 5, OperandType::INT32, desc.m_PadTop, model, data) || |
| 258 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 6, OperandType::INT32, desc.m_PadBottom, model, data) || |
| 259 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 7, OperandType::INT32, desc.m_StrideX, model, data) || |
| 260 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 8, OperandType::INT32, desc.m_StrideY, model, data) || |
| 261 | !GetInputActivationFunction<hal_1_2::HalPolicy>(operation, 9, activation, model, data) || |
| 262 | !GetOptionalConvolutionDilationParams<hal_1_2::HalPolicy>(operation, 11, desc, model, data)) |
| 263 | { |
| 264 | return Fail("%s: Operation has invalid inputs (explicit padding)", __func__); |
| 265 | } |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 266 | } |
| 267 | else |
| 268 | { |
| 269 | return Fail("%s: Unsupported number of operation inputs", __func__); |
| 270 | } |
| 271 | |
| 272 | desc.m_BiasEnabled = true; |
| 273 | armnn::Optional<armnn::TensorInfo> biases(bias.GetInfo()); |
| 274 | |
| 275 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 276 | armnn::IsConvolution2dSupported, |
| 277 | data.m_Backends, |
| 278 | inputInfo, |
| 279 | outputInfo, |
| 280 | desc, |
| 281 | weights.GetInfo(), |
| 282 | biases)) |
| 283 | { |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | armnn::IConnectableLayer* startLayer = |
| 288 | data.m_Network->AddConvolution2dLayer(desc, weights, armnn::Optional<armnn::ConstTensor>(bias)); |
| 289 | |
| 290 | if (!startLayer) |
| 291 | { |
| 292 | return Fail("%s: AddConvolution2dLayer failed", __func__); |
| 293 | } |
| 294 | |
| 295 | armnn::IConnectableLayer* endLayer = ProcessActivation(outputInfo, activation, startLayer, data); |
| 296 | |
| 297 | if (!endLayer) |
| 298 | { |
| 299 | return Fail("%s: ProcessActivation failed", __func__); |
| 300 | } |
| 301 | |
| 302 | input.Connect(startLayer->GetInputSlot(0)); |
| 303 | |
| 304 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, 0, *endLayer, model, data); |
| 305 | } |
| 306 | |
| 307 | bool HalPolicy::ConvertDepthwiseConv2d(const Operation& operation, const Model& model, ConversionData& data) |
| 308 | { |
| 309 | LayerInputHandle input = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 310 | |
| 311 | if (!input.IsValid()) |
| 312 | { |
| 313 | return Fail("%s: Operation has invalid inputs", __func__); |
| 314 | } |
| 315 | |
| 316 | const Operand* output = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 317 | |
| 318 | if (!output) |
| 319 | { |
| 320 | return Fail("%s: Could not read output 0", __func__); |
| 321 | } |
| 322 | |
| 323 | const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); |
| 324 | const armnn::TensorInfo& outputInfo = GetTensorInfoForOperand(*output); |
| 325 | |
| 326 | // ArmNN does not currently support non-fixed weights or bias |
| 327 | // Find the shape of the weights tensor. In AndroidNN this will be [ 1, H, W, I * M ] |
| 328 | const Operand* weightsOperand = GetInputOperand<hal_1_2::HalPolicy>(operation, 1, model); |
| 329 | |
| 330 | if (weightsOperand == nullptr) |
| 331 | { |
| 332 | return Fail("%s: Operand is invalid", __func__); |
| 333 | } |
| 334 | armnn::DepthwiseConvolution2dDescriptor desc; |
| 335 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 336 | |
| 337 | // Determine whether padding is implicit or explicit |
| 338 | bool implicitPadding = operation.inputs.size() == 8 || |
| 339 | (operation.inputs.size() >= 9 && |
| 340 | GetInputOperand<hal_1_2::HalPolicy>(operation, 8, model)->type == OperandType::BOOL); |
| 341 | |
| 342 | // Look ahead to find the optional DataLayout, if present |
| 343 | const uint32_t dataLayoutFlagIndex = implicitPadding ? 8 : 11; |
| 344 | desc.m_DataLayout = OptionalDataLayout<hal_1_2::HalPolicy>(operation, dataLayoutFlagIndex, model, data); |
| 345 | |
| 346 | armnnUtils::DataLayoutIndexed dataLayoutIndexed(desc.m_DataLayout); |
| 347 | unsigned int channelsIndex = dataLayoutIndexed.GetChannelsIndex(); |
| 348 | unsigned int widthIndex = dataLayoutIndexed.GetWidthIndex(); |
| 349 | unsigned int heightIndex = dataLayoutIndexed.GetHeightIndex(); |
| 350 | |
| 351 | // Reinterpret weight data as [ H, W, I, M ] |
| 352 | armnn::TensorShape weightsShape({ weightsOperand->dimensions[1], |
| 353 | weightsOperand->dimensions[2], |
| 354 | inputInfo.GetShape()[channelsIndex], |
| 355 | weightsOperand->dimensions[3] / inputInfo.GetShape()[channelsIndex] }); |
| 356 | |
| 357 | // Swizzle weight data [ H, W, I, M ] -> [ M, I, H, W ] |
| 358 | const armnn::PermutationVector HWIMToMIHW = { 2U, 3U, 1U, 0U }; |
| 359 | |
| 360 | const ConstTensorPin weightsPin = |
| 361 | ConvertOperationInputToConstTensorPin<hal_1_2::HalPolicy>(operation, |
| 362 | 1, |
| 363 | model, |
| 364 | data, |
| 365 | HWIMToMIHW, |
| 366 | &weightsShape); |
| 367 | |
| 368 | // Bias is a 1D tensor |
| 369 | const ConstTensorPin biasPin = |
| 370 | ConvertOperationInputToConstTensorPin<hal_1_2::HalPolicy>(operation, 2, model, data); |
| 371 | |
| 372 | if (!weightsPin.IsValid()) |
| 373 | { |
| 374 | return Fail("%s: Operation has invalid weights", __func__); |
| 375 | } |
| 376 | |
| 377 | if (!biasPin.IsValid()) |
| 378 | { |
| 379 | return Fail("%s: Operation has invalid biases", __func__); |
| 380 | } |
| 381 | |
| 382 | armnn::ConstTensor weights = weightsPin.GetConstTensor(); |
| 383 | armnn::ConstTensor bias = biasPin.GetConstTensor(); |
| 384 | SanitizeBiasQuantizationScale(bias.GetInfo(), weights.GetInfo(), inputInfo); |
| 385 | |
| 386 | ActivationFn activation; |
| 387 | |
| 388 | if (implicitPadding) |
| 389 | { |
| 390 | android::nn::PaddingScheme paddingScheme; |
| 391 | if (!GetInputPaddingScheme<hal_1_2::HalPolicy>(operation, 3, paddingScheme, model, data) || |
| 392 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 4, OperandType::INT32, desc.m_StrideX, model, data) || |
| 393 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 5, OperandType::INT32, desc.m_StrideY, model, data) || |
| 394 | !GetInputActivationFunction<hal_1_2::HalPolicy>(operation, 7, activation, model, data) || |
| 395 | !GetOptionalConvolutionDilationParams<hal_1_2::HalPolicy>(operation, 9, desc, model, data)) |
| 396 | { |
| 397 | return Fail("%s: Operation has invalid inputs (implicit padding)", __func__); |
| 398 | } |
| 399 | |
| 400 | const uint32_t kernelX = weights.GetShape()[3]; |
| 401 | const uint32_t kernelY = weights.GetShape()[2]; |
| 402 | const uint32_t inputX = inputInfo.GetShape()[widthIndex]; |
| 403 | const uint32_t inputY = inputInfo.GetShape()[heightIndex]; |
| 404 | |
Mike Kelly | 86b36d4 | 2019-07-12 16:39:33 +0100 | [diff] [blame] | 405 | CalcPadding(inputX, kernelX, desc.m_StrideX, desc.m_DilationX, desc.m_PadLeft, desc.m_PadRight, paddingScheme); |
| 406 | CalcPadding(inputY, kernelY, desc.m_StrideY, desc.m_DilationY, desc.m_PadTop, desc.m_PadBottom, paddingScheme); |
Aron Virginas-Tar | 24e699d | 2019-06-17 14:47:46 +0100 | [diff] [blame] | 407 | } |
| 408 | else if (operation.inputs.size() >= 11) |
| 409 | { |
| 410 | // explicit padding |
| 411 | if (!GetInputScalar<hal_1_2::HalPolicy>(operation, 3, OperandType::INT32, desc.m_PadLeft, model, data) || |
| 412 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 4, OperandType::INT32, desc.m_PadRight, model, data) || |
| 413 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 5, OperandType::INT32, desc.m_PadTop, model, data) || |
| 414 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 6, OperandType::INT32, desc.m_PadBottom, model, data) || |
| 415 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 7, OperandType::INT32, desc.m_StrideX, model, data) || |
| 416 | !GetInputScalar<hal_1_2::HalPolicy>(operation, 8, OperandType::INT32, desc.m_StrideY, model, data) || |
| 417 | !GetInputActivationFunction<hal_1_2::HalPolicy>(operation, 10, activation, model, data) || |
| 418 | !GetOptionalConvolutionDilationParams<hal_1_2::HalPolicy>(operation, 12, desc, model, data)) |
| 419 | { |
| 420 | return Fail("%s: Operation has invalid inputs (explicit padding)", __func__); |
| 421 | } |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | return Fail("%s: Unsupported number of operation inputs", __func__); |
| 426 | } |
| 427 | |
| 428 | desc.m_BiasEnabled = true; |
| 429 | armnn::Optional<armnn::TensorInfo> biases(bias.GetInfo()); |
| 430 | |
| 431 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 432 | armnn::IsDepthwiseConvolutionSupported, |
| 433 | data.m_Backends, |
| 434 | inputInfo, |
| 435 | outputInfo, |
| 436 | desc, |
| 437 | weights.GetInfo(), |
| 438 | biases)) |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | armnn::IConnectableLayer* startLayer = |
| 444 | data.m_Network->AddDepthwiseConvolution2dLayer(desc, weights, armnn::Optional<armnn::ConstTensor>(bias)); |
| 445 | if (!startLayer) |
| 446 | { |
| 447 | return Fail("%s: AddDepthwiseConvolution2dLayer failed", __func__); |
| 448 | } |
| 449 | |
| 450 | armnn::IConnectableLayer* endLayer = ProcessActivation(outputInfo, activation, startLayer, data); |
| 451 | if (!endLayer) |
| 452 | { |
| 453 | return Fail("%s: ProcessActivation failed", __func__); |
| 454 | } |
| 455 | |
| 456 | input.Connect(startLayer->GetInputSlot(0)); |
| 457 | |
| 458 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, 0, *endLayer, model, data); |
| 459 | } |
| 460 | |
Narumol Prangnawarat | 95b1ef6 | 2019-07-15 12:02:20 +0100 | [diff] [blame^] | 461 | bool HalPolicy::ConvertMaximum(const Operation& operation, const Model& model, ConversionData& data) |
| 462 | { |
| 463 | LayerInputHandle input0 = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 464 | LayerInputHandle input1 = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 1, model, data); |
| 465 | |
| 466 | if (!input0.IsValid() || !input1.IsValid()) |
| 467 | { |
| 468 | return Fail("%s: Operation has invalid inputs", __func__); |
| 469 | } |
| 470 | |
| 471 | const Operand* outputOperand = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 472 | if (!outputOperand) |
| 473 | { |
| 474 | return Fail("%s: Could not read output", __func__); |
| 475 | } |
| 476 | |
| 477 | const armnn::TensorInfo& outInfo = GetTensorInfoForOperand(*outputOperand); |
| 478 | if (IsDynamicOutput(outInfo)) |
| 479 | { |
| 480 | ALOGD("Output shape not set, will infer from inputs"); |
| 481 | outInfo.SetShape(InferMaximumOutputShape(input0.GetTensorInfo().GetShape(), input1.GetTensorInfo().GetShape())); |
| 482 | } |
| 483 | |
| 484 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 485 | armnn::IsMaximumSupported, |
| 486 | data.m_Backends, |
| 487 | input0.GetTensorInfo(), |
| 488 | input1.GetTensorInfo(), |
| 489 | outInfo)) |
| 490 | { |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | armnn::IConnectableLayer* layer = data.m_Network->AddMaximumLayer(); |
| 495 | assert(layer != nullptr); |
| 496 | BroadcastTensor(input0, input1, layer, *data.m_Network); |
| 497 | |
| 498 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, |
| 499 | 0, |
| 500 | *layer, |
| 501 | model, |
| 502 | data, |
| 503 | armnn::Optional<armnn::TensorInfo>(outInfo)); |
| 504 | } |
| 505 | |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 506 | bool HalPolicy::ConvertPadV2(const Operation& operation, const Model& model, ConversionData& data) |
| 507 | { |
| 508 | LayerInputHandle input = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 509 | if (!input.IsValid()) |
| 510 | { |
| 511 | return Fail("%s: Could not read input 0", __func__); |
| 512 | } |
| 513 | |
Aron Virginas-Tar | 366e0a6 | 2019-07-10 13:01:41 +0100 | [diff] [blame] | 514 | const Operand* output = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 515 | if (!output) |
| 516 | { |
| 517 | return Fail("%s: Could not read output", __func__); |
| 518 | } |
| 519 | |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 520 | const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); |
| 521 | unsigned int rank = inputInfo.GetNumDimensions(); |
| 522 | |
| 523 | armnn::PadDescriptor descriptor; |
| 524 | if (!ConvertPaddings<hal_1_2::HalPolicy>(operation, model, data, rank, descriptor)) |
| 525 | { |
| 526 | return Fail("%s: Could not convert paddings", __func__); |
| 527 | } |
| 528 | |
Sadik Armagan | 310d8ff | 2019-07-11 10:53:38 +0100 | [diff] [blame] | 529 | armnn::TensorInfo outputInfo = GetTensorInfoForOperand(*output); |
| 530 | if (IsDynamicOutput(outputInfo)) |
| 531 | { |
| 532 | ALOGD("Output shape not set, will infer from inputs"); |
| 533 | outputInfo.SetShape(InferPadOutputShape(inputInfo.GetShape(), descriptor.m_PadList)); |
| 534 | } |
| 535 | |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 536 | // Determine type of padding value |
| 537 | OperandType operandType0; |
| 538 | OperandType operandType2; |
| 539 | |
| 540 | if (!GetOperandType<hal_1_2::HalPolicy>(operation, 0, model, operandType0) || |
| 541 | !GetOperandType<hal_1_2::HalPolicy>(operation, 2, model, operandType2)) |
| 542 | { |
| 543 | return Fail("%s: Operation has invalid inputs", __func__); |
| 544 | } |
| 545 | |
| 546 | // Read value to use for padding |
| 547 | if (operandType0 == OperandType::TENSOR_FLOAT16 && operandType2 == OperandType::FLOAT16) |
| 548 | { |
| 549 | armnn::Half f16PadValue; |
| 550 | if (!GetInputScalar<hal_1_2::HalPolicy>(operation, 2, operandType2, f16PadValue, model, data)) |
| 551 | { |
| 552 | return Fail("%s: Could not read input 2 (FLOAT16)", __func__); |
| 553 | } |
| 554 | |
| 555 | descriptor.m_PadValue = f16PadValue; |
| 556 | } |
| 557 | else if (operandType0 == OperandType::TENSOR_FLOAT32 && operandType2 == OperandType::FLOAT32) |
| 558 | { |
| 559 | if (!GetInputFloat32<hal_1_2::HalPolicy>(operation, 2, descriptor.m_PadValue, model, data)) |
| 560 | { |
| 561 | return Fail("%s: Could not read input 2 (FLOAT32)", __func__); |
| 562 | } |
| 563 | } |
| 564 | else if (operandType0 == OperandType::TENSOR_QUANT8_ASYMM && operandType2 == OperandType::INT32) |
| 565 | { |
| 566 | int32_t quantizedPadValue = 0; |
| 567 | if (!GetInputInt32<hal_1_2::HalPolicy>(operation, 2, quantizedPadValue, model, data)) |
| 568 | { |
| 569 | return Fail("%s: Could not read input 2 (INT32)", __func__); |
| 570 | } |
| 571 | |
| 572 | descriptor.m_PadValue = armnn::Dequantize(quantizedPadValue, |
| 573 | inputInfo.GetQuantizationScale(), |
| 574 | inputInfo.GetQuantizationOffset()); |
| 575 | } |
| 576 | else |
| 577 | { |
| 578 | return Fail("%s: Operation has invalid inputs: type mismatch", __func__); |
| 579 | } |
| 580 | |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 581 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 582 | armnn::IsPadSupported, |
| 583 | data.m_Backends, |
| 584 | inputInfo, |
| 585 | outputInfo, |
| 586 | descriptor)) |
| 587 | { |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | armnn::IConnectableLayer* const layer = data.m_Network->AddPadLayer(descriptor); |
| 592 | assert(layer != nullptr); |
| 593 | input.Connect(layer->GetInputSlot(0)); |
| 594 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 595 | |
Sadik Armagan | 310d8ff | 2019-07-11 10:53:38 +0100 | [diff] [blame] | 596 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, |
| 597 | 0, |
| 598 | *layer, |
| 599 | model, |
| 600 | data, |
| 601 | armnn::Optional<armnn::TensorInfo>(outputInfo)); |
Aron Virginas-Tar | cb8ac84 | 2019-07-05 15:47:07 +0100 | [diff] [blame] | 602 | } |
| 603 | |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 604 | bool HalPolicy::ConvertPrelu(const Operation& operation, const Model& model, ConversionData& data) |
| 605 | { |
| 606 | LayerInputHandle input = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 607 | LayerInputHandle alpha = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 1, model, data); |
| 608 | |
| 609 | if (!input.IsValid() || !alpha.IsValid()) |
| 610 | { |
| 611 | return Fail("%s: Operation has invalid inputs", __func__); |
| 612 | } |
| 613 | |
| 614 | const Operand* output = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 615 | |
| 616 | if (!output) |
| 617 | { |
Matteo Martincigh | 0bd89a8 | 2019-07-02 16:53:10 +0100 | [diff] [blame] | 618 | return Fail("%s: Could not read output", __func__); |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); |
| 622 | const armnn::TensorInfo& alphaInfo = alpha.GetTensorInfo(); |
Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 623 | |
| 624 | armnn::TensorInfo outputInfo = GetTensorInfoForOperand(*output); |
Aron Virginas-Tar | 366e0a6 | 2019-07-10 13:01:41 +0100 | [diff] [blame] | 625 | if (IsDynamicOutput(outputInfo)) |
Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 626 | { |
| 627 | ALOGD("Output shape not set, will infer from inputs"); |
| 628 | outputInfo.SetShape(InferPreluOutputShape(inputInfo.GetShape(), alphaInfo.GetShape())); |
| 629 | } |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 630 | |
| 631 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 632 | armnn::IsPreluSupported, |
| 633 | data.m_Backends, |
| 634 | inputInfo, |
| 635 | alphaInfo, |
| 636 | outputInfo)) |
| 637 | { |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | armnn::IConnectableLayer* const layer = data.m_Network->AddPreluLayer(); |
| 642 | |
| 643 | if (!layer) |
| 644 | { |
| 645 | return Fail("%s: AddPreluLayer failed", __func__); |
| 646 | } |
| 647 | |
Matteo Martincigh | 0bd89a8 | 2019-07-02 16:53:10 +0100 | [diff] [blame] | 648 | BroadcastTensor(input, alpha, layer, *data.m_Network); |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 649 | |
Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 650 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, |
| 651 | 0, |
| 652 | *layer, |
| 653 | model, |
| 654 | data, |
| 655 | armnn::Optional<armnn::TensorInfo>(outputInfo)); |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Aron Virginas-Tar | fb2fa29 | 2019-07-04 11:59:48 +0100 | [diff] [blame] | 658 | bool HalPolicy::ConvertResize(const Operation& operation, |
| 659 | const Model& model, |
| 660 | ConversionData& data, |
| 661 | armnn::ResizeMethod resizeMethod) |
Aron Virginas-Tar | 7a6d11b | 2019-07-03 15:27:08 +0100 | [diff] [blame] | 662 | { |
| 663 | LayerInputHandle input = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 664 | if (!input.IsValid()) |
| 665 | { |
| 666 | return Fail("%s: Could not read input 0", __func__); |
| 667 | } |
| 668 | |
| 669 | const Operand* output = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 670 | if (!output) |
| 671 | { |
| 672 | return Fail("%s: Could not read output 0", __func__); |
| 673 | } |
| 674 | |
| 675 | const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); |
| 676 | const armnn::TensorInfo& outputInfo = GetTensorInfoForOperand(*output); |
| 677 | |
| 678 | armnn::ResizeDescriptor descriptor; |
Aron Virginas-Tar | fb2fa29 | 2019-07-04 11:59:48 +0100 | [diff] [blame] | 679 | descriptor.m_Method = resizeMethod; |
Aron Virginas-Tar | 7a6d11b | 2019-07-03 15:27:08 +0100 | [diff] [blame] | 680 | descriptor.m_DataLayout = OptionalDataLayout<hal_1_2::HalPolicy>(operation, 3, model, data); |
| 681 | |
| 682 | OperandType operandType1; |
| 683 | OperandType operandType2; |
| 684 | |
| 685 | if (!GetOperandType<hal_1_2::HalPolicy>(operation, 1, model, operandType1) || |
| 686 | !GetOperandType<hal_1_2::HalPolicy>(operation, 2, model, operandType2)) |
| 687 | { |
| 688 | return Fail("%s: Operation has invalid inputs", __func__); |
| 689 | } |
| 690 | |
| 691 | if (operandType1 != operandType2) |
| 692 | { |
| 693 | return Fail("%s: Operation has invalid inputs. Type of input 1 and 2 should be the same", __func__); |
| 694 | } |
| 695 | |
| 696 | if (operandType1 == OperandType::INT32) |
| 697 | { |
| 698 | // Case 1: resizing by shape |
| 699 | int32_t targetWidth = 0; |
| 700 | int32_t targetHeight = 0; |
| 701 | |
| 702 | if (!GetInputInt32<hal_1_2::HalPolicy>(operation, 1, targetWidth, model, data) || |
| 703 | !GetInputInt32<hal_1_2::HalPolicy>(operation, 2, targetHeight, model, data)) |
| 704 | { |
| 705 | return Fail("%s: Operation has invalid inputs for resizing by shape", __func__); |
| 706 | } |
| 707 | |
| 708 | if (targetWidth < 0 || targetHeight < 0) |
| 709 | { |
| 710 | return Fail("%s: Operation has invalid inputs for resizing by shape. " |
| 711 | "Target width/height cannot be < 0", __func__); |
| 712 | } |
| 713 | |
| 714 | descriptor.m_TargetWidth = static_cast<uint32_t>(targetWidth); |
| 715 | descriptor.m_TargetWidth = static_cast<uint32_t>(targetHeight); |
| 716 | } |
| 717 | else if (operandType1 == OperandType::FLOAT32) |
| 718 | { |
| 719 | // Case 2: resizing by scale |
| 720 | float widthScale = 1.0f; |
| 721 | float heightScale = 1.0f; |
| 722 | |
| 723 | if (!GetInputFloat32<hal_1_2::HalPolicy>(operation, 1, widthScale, model, data) || |
| 724 | !GetInputFloat32<hal_1_2::HalPolicy>(operation, 2, heightScale, model, data)) |
| 725 | { |
| 726 | return Fail("%s: Operation has invalid inputs for resizing by scale", __func__); |
| 727 | } |
| 728 | |
| 729 | const armnn::TensorShape& inputShape = inputInfo.GetShape(); |
| 730 | armnnUtils::DataLayoutIndexed dataLayoutIndexed(descriptor.m_DataLayout); |
| 731 | |
| 732 | float width = inputShape[dataLayoutIndexed.GetWidthIndex()]; |
| 733 | float height = inputShape[dataLayoutIndexed.GetHeightIndex()]; |
| 734 | |
| 735 | descriptor.m_TargetWidth = std::floor(width * widthScale); |
| 736 | descriptor.m_TargetHeight = std::floor(height * heightScale); |
| 737 | } |
| 738 | else |
| 739 | { |
| 740 | // NOTE: FLOAT16 scales are not supported |
| 741 | return false; |
| 742 | } |
| 743 | |
| 744 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 745 | armnn::IsResizeSupported, |
| 746 | data.m_Backends, |
| 747 | inputInfo, |
| 748 | outputInfo, |
| 749 | descriptor)) |
| 750 | { |
| 751 | return false; |
| 752 | } |
| 753 | |
| 754 | armnn::IConnectableLayer* layer = data.m_Network->AddResizeLayer(descriptor); |
| 755 | |
| 756 | assert(layer != nullptr); |
| 757 | |
| 758 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 759 | input.Connect(layer->GetInputSlot(0)); |
| 760 | |
| 761 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, 0, *layer, model, data); |
| 762 | } |
| 763 | |
Keith Davis | a6bc52f | 2019-06-26 09:39:49 +0100 | [diff] [blame] | 764 | bool HalPolicy::ConvertSpaceToDepth(const Operation& operation, const Model& model, ConversionData& data) |
| 765 | { |
| 766 | LayerInputHandle input = ConvertToLayerInputHandle<hal_1_2::HalPolicy>(operation, 0, model, data); |
| 767 | |
| 768 | if (!input.IsValid() ) |
| 769 | { |
| 770 | return Fail("%s: Operation has invalid inputs", __func__); |
| 771 | } |
| 772 | |
| 773 | const armnn::TensorInfo& inputInfo = input.GetTensorInfo(); |
| 774 | unsigned int rank = inputInfo.GetNumDimensions(); |
| 775 | |
| 776 | if (rank != 4) |
| 777 | { |
| 778 | return Fail("%s: Only inputs with rank 4 are supported", __func__); |
| 779 | } |
| 780 | |
| 781 | armnn::SpaceToDepthDescriptor desc; |
| 782 | |
| 783 | GetInputScalar<hal_1_2::HalPolicy>(operation, 1, OperandType::INT32, desc.m_BlockSize, model, data); |
| 784 | |
| 785 | if (desc.m_BlockSize <= 1) |
| 786 | { |
| 787 | return Fail("%s: Block size must be at least 1 in all dimensions"); |
| 788 | } |
| 789 | |
| 790 | desc.m_DataLayout = OptionalDataLayout<hal_1_2::HalPolicy>(operation, 2, model, data); |
| 791 | |
| 792 | const Operand* output = GetOutputOperand<hal_1_2::HalPolicy>(operation, 0, model); |
| 793 | if (!output) |
| 794 | { |
| 795 | return Fail("%s: Could not read output 0", __func__); |
| 796 | } |
| 797 | |
| 798 | const armnn::TensorInfo& outputInfo = GetTensorInfoForOperand(*output); |
| 799 | if (!IsLayerSupportedForAnyBackend(__func__, |
| 800 | armnn::IsSpaceToDepthSupported, |
| 801 | data.m_Backends, |
| 802 | inputInfo, |
| 803 | outputInfo, |
| 804 | desc)) |
| 805 | { |
| 806 | return false; |
| 807 | } |
| 808 | |
| 809 | armnn::IConnectableLayer* const layer = data.m_Network->AddSpaceToDepthLayer(desc); |
| 810 | assert(layer != nullptr); |
| 811 | input.Connect(layer->GetInputSlot(0)); |
| 812 | |
| 813 | return SetupAndTrackLayerOutputSlot<hal_1_2::HalPolicy>(operation, 0, *layer, model, data); |
| 814 | } |
| 815 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 816 | } // namespace hal_1_2 |
Matteo Martincigh | 17ffff3 | 2019-06-27 14:12:55 +0100 | [diff] [blame] | 817 | } // namespace armnn_driver |