telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 5 | |
| 6 | #include "CpuTensorHandle.hpp" |
| 7 | |
| 8 | #include <Layer.hpp> |
| 9 | #include <LayersFwd.hpp> |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 10 | |
David Beck | b4540be | 2018-09-24 13:18:27 +0100 | [diff] [blame] | 11 | #include <armnn/Types.hpp> |
| 12 | #include <armnn/LayerSupport.hpp> |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 13 | #include <armnn/ILayerSupport.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 14 | |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 15 | #include <backendsCommon/BackendRegistry.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 16 | #include <backendsCommon/WorkloadFactory.hpp> |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 17 | #include <backendsCommon/IBackendInternal.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | |
| 19 | #include <boost/cast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | #include <boost/iterator/transform_iterator.hpp> |
| 21 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 22 | #include <cstring> |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 23 | #include <sstream> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 24 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | namespace armnn |
| 26 | { |
| 27 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 28 | namespace |
| 29 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 30 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 31 | const TensorInfo OverrideDataType(const TensorInfo& info, Optional<DataType> type) |
| 32 | { |
| 33 | if (!type) |
| 34 | { |
| 35 | return info; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 36 | } |
| 37 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 38 | return TensorInfo(info.GetShape(), type.value(), info.GetQuantizationScale(), info.GetQuantizationOffset()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 39 | } |
| 40 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 41 | Optional<DataType> GetBiasTypeFromWeightsType(Optional<DataType> weightsType) |
| 42 | { |
| 43 | if (!weightsType) |
| 44 | { |
| 45 | return weightsType; |
| 46 | } |
| 47 | |
| 48 | switch(weightsType.value()) |
| 49 | { |
| 50 | case DataType::Float16: |
| 51 | case DataType::Float32: |
| 52 | return weightsType; |
| 53 | case DataType::QuantisedAsymm8: |
| 54 | return DataType::Signed32; |
| 55 | default: |
| 56 | BOOST_ASSERT_MSG(false, "GetBiasTypeFromWeightsType(): Unsupported data type."); |
| 57 | } |
| 58 | return EmptyOptional(); |
| 59 | } |
| 60 | |
| 61 | } // anonymous namespace |
| 62 | |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 63 | bool IWorkloadFactory::IsLayerSupported(const BackendId& backendId, |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 64 | const IConnectableLayer& connectableLayer, |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 65 | Optional<DataType> dataType, |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 66 | std::string& outReasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 67 | { |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 68 | Optional<std::string&> reason = outReasonIfUnsupported; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | bool result; |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 70 | const Layer& layer = *(boost::polymorphic_downcast<const Layer*>(&connectableLayer)); |
| 71 | |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 72 | auto const& backendRegistry = BackendRegistryInstance(); |
| 73 | if (!backendRegistry.IsBackendRegistered(backendId)) |
| 74 | { |
| 75 | std::stringstream ss; |
| 76 | ss << connectableLayer.GetName() << " is not supported on " << backendId |
| 77 | << " because this backend is not registered."; |
| 78 | |
| 79 | outReasonIfUnsupported = ss.str(); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | auto backendFactory = backendRegistry.GetFactory(backendId); |
| 84 | auto backendObject = backendFactory(); |
| 85 | auto layerSupportObject = backendObject->GetLayerSupport(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 86 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 87 | switch(layer.GetType()) |
| 88 | { |
| 89 | case LayerType::Activation: |
| 90 | { |
| 91 | auto cLayer = boost::polymorphic_downcast<const ActivationLayer*>(&layer); |
| 92 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 93 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 94 | result = layerSupportObject->IsActivationSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 95 | OverrideDataType(input, dataType), |
| 96 | OverrideDataType(output, dataType), |
| 97 | cLayer->GetParameters(), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 98 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 99 | break; |
| 100 | } |
| 101 | case LayerType::Addition: |
| 102 | { |
| 103 | const TensorInfo& input0 = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 104 | const TensorInfo& input1 = layer.GetInputSlot(1).GetConnection()->GetTensorInfo(); |
| 105 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 106 | result = layerSupportObject->IsAdditionSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 107 | OverrideDataType(input0, dataType), |
| 108 | OverrideDataType(input1, dataType), |
| 109 | OverrideDataType(output, dataType), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 110 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 111 | break; |
| 112 | } |
| 113 | case LayerType::BatchNormalization: |
| 114 | { |
| 115 | auto cLayer = boost::polymorphic_downcast<const BatchNormalizationLayer*>(&layer); |
| 116 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 117 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 118 | const TensorInfo& mean = cLayer->m_Mean->GetTensorInfo(); |
| 119 | const TensorInfo& var = cLayer->m_Variance->GetTensorInfo(); |
| 120 | const TensorInfo& beta = cLayer->m_Beta->GetTensorInfo(); |
| 121 | const TensorInfo& gamma = cLayer->m_Gamma->GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 122 | result = layerSupportObject->IsBatchNormalizationSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 123 | OverrideDataType(input, dataType), |
| 124 | OverrideDataType(output, dataType), |
| 125 | OverrideDataType(mean, dataType), |
| 126 | OverrideDataType(var, dataType), |
| 127 | OverrideDataType(beta, dataType), |
| 128 | OverrideDataType(gamma, dataType), |
| 129 | cLayer->GetParameters(), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 130 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 131 | break; |
| 132 | } |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 133 | case LayerType::BatchToSpaceNd: |
| 134 | { |
| 135 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 136 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 137 | auto cLayer = boost::polymorphic_downcast<const BatchToSpaceNdLayer*>(&layer); |
| 138 | |
| 139 | result = layerSupportObject->IsBatchToSpaceNdSupported(OverrideDataType(input, dataType), |
| 140 | OverrideDataType(output, dataType), |
| 141 | cLayer->GetParameters(), |
| 142 | reason); |
| 143 | break; |
| 144 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 145 | case LayerType::Constant: |
| 146 | { |
| 147 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 148 | result = layerSupportObject->IsConstantSupported(OverrideDataType(output, dataType), reason); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | case LayerType::ConvertFp16ToFp32: |
| 152 | { |
| 153 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 154 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 155 | result = layerSupportObject->IsConvertFp16ToFp32Supported(input, output, reason); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 156 | break; |
| 157 | } |
| 158 | case LayerType::ConvertFp32ToFp16: |
| 159 | { |
| 160 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 161 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 162 | result = layerSupportObject->IsConvertFp32ToFp16Supported(input, output, reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 163 | break; |
| 164 | } |
| 165 | case LayerType::Convolution2d: |
| 166 | { |
| 167 | auto cLayer = boost::polymorphic_downcast<const Convolution2dLayer*>(&layer); |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 168 | |
| 169 | const TensorInfo input = OverrideDataType(layer.GetInputSlot(0).GetConnection()->GetTensorInfo(), |
| 170 | dataType); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 171 | const TensorInfo output = OverrideDataType(layer.GetOutputSlot(0).GetTensorInfo(), dataType); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 172 | BOOST_ASSERT(cLayer->m_Weight.get() != nullptr); |
| 173 | |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 174 | const Convolution2dDescriptor& descriptor = cLayer->GetParameters(); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 175 | |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 176 | // Construct optional biases object based on the value of m_BiasEnabled |
David Beck | 5eec11d | 2018-10-04 15:43:17 +0100 | [diff] [blame] | 177 | Optional<TensorInfo> biases; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 178 | if (descriptor.m_BiasEnabled) |
| 179 | { |
David Beck | 5eec11d | 2018-10-04 15:43:17 +0100 | [diff] [blame] | 180 | biases = |
| 181 | OverrideDataType(cLayer->m_Bias->GetTensorInfo(), GetBiasTypeFromWeightsType(dataType)); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 182 | } |
| 183 | |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 184 | result = layerSupportObject->IsConvolution2dSupported( |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 185 | input, |
| 186 | output, |
| 187 | descriptor, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 188 | OverrideDataType(cLayer->m_Weight->GetTensorInfo(), dataType), |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 189 | biases, |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 190 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | case LayerType::MemCopy: |
| 194 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 195 | // MemCopy supported for CpuRef, CpuAcc and GpuAcc backends, |
| 196 | // (also treat Undefined as CpuRef to avoid breaking lots of Unit tests). |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 197 | result = backendId == Compute::CpuRef || backendId == Compute::Undefined |
| 198 | || backendId == Compute::CpuAcc || backendId == Compute::GpuAcc; |
| 199 | reason.value() = "Unsupported backend type"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 200 | break; |
| 201 | } |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 202 | case LayerType::Debug: |
| 203 | { |
Nattapat Chaimanowong | ac5aa1f | 2018-12-05 15:17:18 +0000 | [diff] [blame] | 204 | auto cLayer = boost::polymorphic_downcast<const DebugLayer*>(&layer); |
| 205 | const DebugDescriptor& descriptor = cLayer->GetParameters(); |
| 206 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 207 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 208 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 209 | |
| 210 | result = layerSupportObject->IsDebugSupported(OverrideDataType(input, dataType), |
| 211 | OverrideDataType(output, dataType), |
Nattapat Chaimanowong | ac5aa1f | 2018-12-05 15:17:18 +0000 | [diff] [blame] | 212 | descriptor, |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 213 | reason); |
| 214 | break; |
| 215 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 216 | case LayerType::DepthwiseConvolution2d: |
| 217 | { |
| 218 | auto cLayer = boost::polymorphic_downcast<const DepthwiseConvolution2dLayer*>(&layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 219 | const TensorInfo& input = OverrideDataType(layer.GetInputSlot(0).GetConnection()->GetTensorInfo(), |
| 220 | dataType); |
| 221 | const TensorInfo& output = OverrideDataType(layer.GetOutputSlot(0).GetTensorInfo(), dataType); |
| 222 | BOOST_ASSERT(cLayer->m_Weight.get() != nullptr); |
| 223 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 224 | const DepthwiseConvolution2dDescriptor& descriptor = cLayer->GetParameters(); |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 225 | |
| 226 | // Construct optional biases object based on the value of m_BiasEnabled |
David Beck | 5eec11d | 2018-10-04 15:43:17 +0100 | [diff] [blame] | 227 | Optional<TensorInfo> biases; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 228 | if (descriptor.m_BiasEnabled) |
| 229 | { |
David Beck | 5eec11d | 2018-10-04 15:43:17 +0100 | [diff] [blame] | 230 | biases = |
| 231 | OverrideDataType(cLayer->m_Bias->GetTensorInfo(), GetBiasTypeFromWeightsType(dataType)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 232 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 233 | |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 234 | result = layerSupportObject->IsDepthwiseConvolutionSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 235 | input, |
| 236 | output, |
| 237 | descriptor, |
| 238 | OverrideDataType(cLayer->m_Weight->GetTensorInfo(), dataType), |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 239 | biases, |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 240 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 241 | break; |
| 242 | } |
| 243 | case LayerType::FakeQuantization: |
| 244 | { |
| 245 | auto cLayer = boost::polymorphic_downcast<const FakeQuantizationLayer*>(&layer); |
| 246 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 247 | result = layerSupportObject->IsFakeQuantizationSupported(OverrideDataType(input, dataType), |
| 248 | cLayer->GetParameters(), |
| 249 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 250 | break; |
| 251 | } |
| 252 | case LayerType::Floor: |
| 253 | { |
| 254 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 255 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 256 | result = layerSupportObject->IsFloorSupported(OverrideDataType(input, dataType), |
| 257 | OverrideDataType(output, dataType), |
| 258 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 259 | break; |
| 260 | } |
| 261 | case LayerType::FullyConnected: |
| 262 | { |
| 263 | auto cLayer = boost::polymorphic_downcast<const FullyConnectedLayer*>(&layer); |
| 264 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 265 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 266 | BOOST_ASSERT(cLayer->m_Weight.get() != nullptr); |
| 267 | |
| 268 | TensorInfo biasInfo; |
| 269 | const TensorInfo * biasInfoPtr = nullptr; |
| 270 | static const TensorInfo dummyFloat16Bias(TensorShape({1,1,1,1}), DataType::Float16); |
| 271 | static const TensorInfo dummyFloat32Bias(TensorShape({1,1,1,1}), DataType::Float32); |
| 272 | static const TensorInfo dummyQA8Bias(TensorShape({1,1,1,1}), DataType::Signed32); |
| 273 | |
| 274 | const FullyConnectedDescriptor& descriptor = cLayer->GetParameters(); |
| 275 | if (descriptor.m_BiasEnabled) |
| 276 | { |
| 277 | BOOST_ASSERT(cLayer->m_Bias.get() != nullptr); |
| 278 | biasInfo = OverrideDataType(cLayer->m_Bias->GetTensorInfo(), GetBiasTypeFromWeightsType(dataType)); |
| 279 | biasInfoPtr = &biasInfo; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | // If biases are not enabled pass a dummy tensorinfo for the validation |
| 284 | switch(input.GetDataType()) |
| 285 | { |
| 286 | case DataType::Float16: |
| 287 | { |
| 288 | biasInfoPtr = &dummyFloat16Bias; |
| 289 | break; |
| 290 | } |
| 291 | case DataType::Float32: |
| 292 | { |
| 293 | biasInfoPtr = &dummyFloat32Bias; |
| 294 | break; |
| 295 | } |
| 296 | case DataType::QuantisedAsymm8: |
| 297 | { |
| 298 | biasInfoPtr = &dummyQA8Bias; |
| 299 | break; |
| 300 | } |
| 301 | default: |
| 302 | { |
| 303 | BOOST_ASSERT_MSG(false, "Unexpected bias type"); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 308 | result = layerSupportObject->IsFullyConnectedSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 309 | OverrideDataType(input, dataType), |
| 310 | OverrideDataType(output, dataType), |
| 311 | OverrideDataType(cLayer->m_Weight->GetTensorInfo(), dataType), |
| 312 | *biasInfoPtr, |
| 313 | descriptor, |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 314 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 315 | break; |
| 316 | } |
| 317 | case LayerType::Input: |
| 318 | { |
| 319 | const TensorInfo& input = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 320 | result = layerSupportObject->IsInputSupported(OverrideDataType(input, dataType), reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 321 | break; |
| 322 | } |
| 323 | case LayerType::L2Normalization: |
| 324 | { |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 325 | auto cLayer = boost::polymorphic_downcast<const L2NormalizationLayer*>(&layer); |
| 326 | const L2NormalizationDescriptor& descriptor = cLayer->GetParameters(); |
| 327 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 328 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 329 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 330 | |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 331 | result = layerSupportObject->IsL2NormalizationSupported( |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 332 | OverrideDataType(input, dataType), |
| 333 | OverrideDataType(output, dataType), |
| 334 | descriptor, |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 335 | reason); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 336 | break; |
| 337 | } |
| 338 | case LayerType::Lstm: |
| 339 | { |
| 340 | auto cLayer = boost::polymorphic_downcast<const LstmLayer*>(&layer); |
| 341 | const LstmDescriptor& descriptor = cLayer->GetParameters(); |
| 342 | |
| 343 | // All inputs. |
| 344 | const TensorInfo& input = OverrideDataType(layer.GetInputSlot(0).GetConnection()->GetTensorInfo(), |
| 345 | dataType); |
| 346 | const TensorInfo& outputStateIn = OverrideDataType(layer.GetInputSlot(1).GetConnection()->GetTensorInfo(), |
| 347 | dataType); |
| 348 | const TensorInfo& cellStateIn = OverrideDataType(layer.GetInputSlot(2).GetConnection()->GetTensorInfo(), |
| 349 | dataType); |
| 350 | // All outputs |
| 351 | const TensorInfo& scratchBuffer = OverrideDataType(layer.GetOutputSlot(0).GetTensorInfo(), dataType); |
| 352 | const TensorInfo& outputStateOut = OverrideDataType(layer.GetOutputSlot(1).GetTensorInfo(), dataType); |
| 353 | const TensorInfo& cellStateOut = OverrideDataType(layer.GetOutputSlot(2).GetTensorInfo(), dataType); |
| 354 | const TensorInfo& output = OverrideDataType(layer.GetOutputSlot(3).GetTensorInfo(), dataType); |
| 355 | |
| 356 | // Basic parameters |
| 357 | const TensorInfo& inputToForgetWeights |
| 358 | = OverrideDataType(cLayer->m_BasicParameters.m_InputToForgetWeights->GetTensorInfo(), dataType); |
| 359 | const TensorInfo& inputToCellWeights |
| 360 | = OverrideDataType(cLayer->m_BasicParameters.m_InputToCellWeights->GetTensorInfo(), dataType); |
| 361 | const TensorInfo& inputToOutputWeights |
| 362 | = OverrideDataType(cLayer->m_BasicParameters.m_InputToOutputWeights->GetTensorInfo(), dataType); |
| 363 | const TensorInfo& recurrentToForgetWeights |
| 364 | = OverrideDataType(cLayer->m_BasicParameters.m_RecurrentToForgetWeights->GetTensorInfo(), dataType); |
| 365 | const TensorInfo& recurrentToCellWeights |
| 366 | = OverrideDataType(cLayer->m_BasicParameters.m_RecurrentToCellWeights->GetTensorInfo(), dataType); |
| 367 | const TensorInfo& recurrentToOutputWeights |
| 368 | = OverrideDataType(cLayer->m_BasicParameters.m_RecurrentToOutputWeights->GetTensorInfo(), dataType); |
| 369 | const TensorInfo& forgetGateBias |
| 370 | = OverrideDataType(cLayer->m_BasicParameters.m_ForgetGateBias->GetTensorInfo(), dataType); |
| 371 | const TensorInfo& cellBias |
| 372 | = OverrideDataType(cLayer->m_BasicParameters.m_CellBias->GetTensorInfo(), dataType); |
| 373 | const TensorInfo& outputGateBias |
| 374 | = OverrideDataType(cLayer->m_BasicParameters.m_OutputGateBias->GetTensorInfo(), dataType); |
| 375 | |
| 376 | // Optional parameters |
| 377 | const TensorInfo* inputToInputWeights = nullptr; |
| 378 | const TensorInfo* recurrentToInputWeights = nullptr; |
| 379 | const TensorInfo* cellToInputWeights = nullptr; |
| 380 | const TensorInfo* inputGateBias = nullptr; |
| 381 | const TensorInfo* projectionWeights = nullptr; |
| 382 | const TensorInfo* projectionBias = nullptr; |
| 383 | const TensorInfo* cellToForgetWeights = nullptr; |
| 384 | const TensorInfo* cellToOutputWeights = nullptr; |
| 385 | |
| 386 | TensorInfo optInputToInputWeights; |
| 387 | TensorInfo optRecurrentToInputWeights; |
| 388 | TensorInfo optCellToInputWeights; |
| 389 | TensorInfo optInputGateBias; |
| 390 | TensorInfo optProjectionWeights; |
| 391 | TensorInfo optProjectionBias; |
| 392 | TensorInfo optCellToForgetWeights; |
| 393 | TensorInfo optCellToOutputWeights; |
| 394 | |
| 395 | if(!descriptor.m_CifgEnabled) |
| 396 | { |
| 397 | optInputToInputWeights = |
| 398 | OverrideDataType(cLayer->m_CifgParameters.m_InputToInputWeights->GetTensorInfo(), dataType); |
| 399 | inputToInputWeights = &optInputToInputWeights; |
| 400 | |
| 401 | optRecurrentToInputWeights = |
| 402 | OverrideDataType(cLayer->m_CifgParameters.m_RecurrentToInputWeights->GetTensorInfo(), dataType); |
| 403 | recurrentToInputWeights = &optRecurrentToInputWeights; |
| 404 | if (cLayer->m_CifgParameters.m_CellToInputWeights != nullptr) |
| 405 | { |
| 406 | optCellToInputWeights = |
| 407 | OverrideDataType(cLayer->m_CifgParameters.m_CellToInputWeights->GetTensorInfo(), dataType); |
| 408 | cellToInputWeights = &optCellToInputWeights; |
| 409 | } |
| 410 | optInputGateBias = |
| 411 | OverrideDataType(cLayer->m_CifgParameters.m_InputGateBias->GetTensorInfo(), dataType); |
| 412 | inputGateBias = &optInputGateBias; |
| 413 | } |
| 414 | |
| 415 | if(descriptor.m_ProjectionEnabled) |
| 416 | { |
| 417 | optProjectionWeights = |
| 418 | OverrideDataType(cLayer->m_ProjectionParameters.m_ProjectionWeights->GetTensorInfo(), dataType); |
| 419 | projectionWeights = &optProjectionWeights; |
| 420 | if (cLayer->m_ProjectionParameters.m_ProjectionBias != nullptr) |
| 421 | { |
| 422 | optProjectionBias = |
| 423 | OverrideDataType(cLayer->m_ProjectionParameters.m_ProjectionBias->GetTensorInfo(), dataType); |
| 424 | projectionBias = &optProjectionBias; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | if(descriptor.m_PeepholeEnabled) |
| 429 | { |
| 430 | optCellToForgetWeights = |
| 431 | OverrideDataType(cLayer->m_PeepholeParameters.m_CellToForgetWeights->GetTensorInfo(), dataType); |
| 432 | cellToForgetWeights = &optCellToForgetWeights; |
| 433 | optCellToOutputWeights = |
| 434 | OverrideDataType(cLayer->m_PeepholeParameters.m_CellToOutputWeights->GetTensorInfo(), dataType); |
| 435 | cellToOutputWeights = &optCellToOutputWeights; |
| 436 | } |
| 437 | |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 438 | result = layerSupportObject->IsLstmSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 439 | input, |
| 440 | outputStateIn, |
| 441 | cellStateIn, |
| 442 | scratchBuffer, |
| 443 | outputStateOut, |
| 444 | cellStateOut, |
| 445 | output, |
| 446 | descriptor, |
| 447 | inputToForgetWeights, |
| 448 | inputToCellWeights, |
| 449 | inputToOutputWeights, |
| 450 | recurrentToForgetWeights, |
| 451 | recurrentToCellWeights, |
| 452 | recurrentToOutputWeights, |
| 453 | forgetGateBias, |
| 454 | cellBias, |
| 455 | outputGateBias, |
| 456 | inputToInputWeights, |
| 457 | recurrentToInputWeights, |
| 458 | cellToInputWeights, |
| 459 | inputGateBias, |
| 460 | projectionWeights, |
| 461 | projectionBias, |
| 462 | cellToForgetWeights, |
| 463 | cellToOutputWeights, |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 464 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 465 | break; |
| 466 | } |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 467 | case LayerType::Maximum: |
| 468 | { |
| 469 | const TensorInfo& input0 = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 470 | const TensorInfo& input1 = layer.GetInputSlot(1).GetConnection()->GetTensorInfo(); |
| 471 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 472 | |
| 473 | result = layerSupportObject->IsMaximumSupported(OverrideDataType(input0, dataType), |
| 474 | OverrideDataType(input1, dataType), |
| 475 | OverrideDataType(output, dataType), |
| 476 | reason); |
| 477 | break; |
| 478 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 479 | case LayerType::Merger: |
| 480 | { |
| 481 | auto cLayer = boost::polymorphic_downcast<const MergerLayer*>(&layer); |
| 482 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 483 | // Get vector of all inputs. |
| 484 | auto getTensorInfo = [&dataType](const InputSlot& slot) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 485 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 486 | return OverrideDataType(slot.GetConnectedOutputSlot()->GetTensorInfo(), dataType); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 487 | }; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 488 | auto beginI = boost::make_transform_iterator(layer.GetInputSlots().begin(), getTensorInfo); |
| 489 | auto endI = boost::make_transform_iterator(layer.GetInputSlots().end(), getTensorInfo); |
| 490 | std::vector<TensorInfo> inputs(beginI, endI); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 491 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 492 | auto getTensorInfoPtr = [](const TensorInfo& info) |
| 493 | { |
| 494 | return &info; |
| 495 | }; |
| 496 | auto beginPtr = boost::make_transform_iterator(inputs.begin(), getTensorInfoPtr); |
| 497 | auto endPtr = boost::make_transform_iterator(inputs.end(), getTensorInfoPtr); |
| 498 | std::vector<const TensorInfo*> inputPtrs(beginPtr, endPtr); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 499 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 500 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 501 | |
| 502 | result = layerSupportObject->IsMergerSupported(inputPtrs, output, cLayer->GetParameters(), reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 503 | break; |
| 504 | } |
| 505 | case LayerType::Multiplication: |
| 506 | { |
| 507 | const TensorInfo& input0 = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 508 | const TensorInfo& input1 = layer.GetInputSlot(1).GetConnection()->GetTensorInfo(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 509 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 510 | result = layerSupportObject->IsMultiplicationSupported( |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 511 | OverrideDataType(input0, dataType), |
| 512 | OverrideDataType(input1, dataType), |
| 513 | OverrideDataType(output, dataType), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 514 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | case LayerType::Normalization: |
| 518 | { |
| 519 | auto cLayer = boost::polymorphic_downcast<const NormalizationLayer*>(&layer); |
| 520 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 521 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 522 | result = layerSupportObject->IsNormalizationSupported(OverrideDataType(input, dataType), |
| 523 | OverrideDataType(output, dataType), |
| 524 | cLayer->GetParameters(), |
| 525 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | case LayerType::Output: |
| 529 | { |
| 530 | const TensorInfo& output = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 531 | result = layerSupportObject->IsOutputSupported(OverrideDataType(output, dataType), reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 532 | break; |
| 533 | } |
| 534 | case LayerType::Permute: |
| 535 | { |
| 536 | auto cLayer = boost::polymorphic_downcast<const PermuteLayer*>(&layer); |
| 537 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 538 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 539 | result = layerSupportObject->IsPermuteSupported(OverrideDataType(input, dataType), |
| 540 | OverrideDataType(output, dataType), |
| 541 | cLayer->GetParameters(), |
| 542 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 543 | break; |
| 544 | } |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 545 | case LayerType::Pad: |
| 546 | { |
| 547 | auto cLayer = boost::polymorphic_downcast<const PadLayer*>(&layer); |
| 548 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 549 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 550 | result = layerSupportObject->IsPadSupported( |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 551 | OverrideDataType(input, dataType), |
| 552 | OverrideDataType(output, dataType), |
| 553 | cLayer->GetParameters(), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 554 | reason); |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 555 | break; |
| 556 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 557 | case LayerType::Pooling2d: |
| 558 | { |
| 559 | auto cLayer = boost::polymorphic_downcast<const Pooling2dLayer*>(&layer); |
| 560 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 561 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 562 | result = layerSupportObject->IsPooling2dSupported(OverrideDataType(input, dataType), |
| 563 | OverrideDataType(output, dataType), |
| 564 | cLayer->GetParameters(), |
| 565 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 566 | break; |
| 567 | } |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 568 | case LayerType::Division: |
| 569 | { |
| 570 | const TensorInfo& input0 = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 571 | const TensorInfo& input1 = layer.GetInputSlot(1).GetConnection()->GetTensorInfo(); |
| 572 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 573 | result = layerSupportObject->IsDivisionSupported( |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 574 | OverrideDataType(input0, dataType), |
| 575 | OverrideDataType(input1, dataType), |
| 576 | OverrideDataType(output, dataType), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 577 | reason); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 578 | break; |
| 579 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 580 | case LayerType::Reshape: |
| 581 | { |
| 582 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 583 | result = layerSupportObject->IsReshapeSupported(OverrideDataType(input, dataType), reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 584 | break; |
| 585 | } |
| 586 | case LayerType::ResizeBilinear: |
| 587 | { |
| 588 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 589 | result = layerSupportObject->IsResizeBilinearSupported(OverrideDataType(input, dataType), reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 590 | break; |
| 591 | } |
| 592 | case LayerType::Softmax: |
| 593 | { |
| 594 | auto cLayer = boost::polymorphic_downcast<const SoftmaxLayer*>(&layer); |
| 595 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 596 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 597 | result = layerSupportObject->IsSoftmaxSupported(OverrideDataType(input, dataType), |
| 598 | OverrideDataType(output, dataType), |
| 599 | cLayer->GetParameters(), |
| 600 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 601 | break; |
| 602 | } |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 603 | case LayerType::SpaceToBatchNd: |
| 604 | { |
| 605 | auto cLayer = boost::polymorphic_downcast<const SpaceToBatchNdLayer*>(&layer); |
| 606 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 607 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 608 | result = layerSupportObject->IsSpaceToBatchNdSupported(OverrideDataType(input, dataType), |
| 609 | OverrideDataType(output, dataType), |
| 610 | cLayer->GetParameters(), |
| 611 | reason); |
| 612 | break; |
| 613 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 614 | case LayerType::Splitter: |
| 615 | { |
| 616 | auto cLayer = boost::polymorphic_downcast<const SplitterLayer*>(&layer); |
| 617 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 618 | result = layerSupportObject->IsSplitterSupported(OverrideDataType(input, dataType), |
| 619 | cLayer->GetParameters(), |
| 620 | reason); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 621 | break; |
| 622 | } |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 623 | case LayerType::StridedSlice: |
| 624 | { |
| 625 | auto cLayer = boost::polymorphic_downcast<const StridedSliceLayer*>(&layer); |
| 626 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 627 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 628 | result = layerSupportObject->IsStridedSliceSupported(OverrideDataType(input, dataType), |
| 629 | OverrideDataType(output, dataType), |
| 630 | cLayer->GetParameters(), |
| 631 | reason); |
| 632 | break; |
| 633 | } |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 634 | case LayerType::Subtraction: |
| 635 | { |
| 636 | const TensorInfo& input0 = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 637 | const TensorInfo& input1 = layer.GetInputSlot(1).GetConnection()->GetTensorInfo(); |
| 638 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 639 | result = layerSupportObject->IsSubtractionSupported( |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 640 | OverrideDataType(input0, dataType), |
| 641 | OverrideDataType(input1, dataType), |
| 642 | OverrideDataType(output, dataType), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 643 | reason); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 644 | break; |
| 645 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 646 | case LayerType::Mean: |
| 647 | { |
| 648 | auto cLayer = boost::polymorphic_downcast<const MeanLayer*>(&layer); |
| 649 | const TensorInfo& input = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 650 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 651 | result = layerSupportObject->IsMeanSupported( |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 652 | OverrideDataType(input, dataType), |
| 653 | OverrideDataType(output, dataType), |
| 654 | cLayer->GetParameters(), |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 655 | reason); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 656 | break; |
| 657 | } |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 658 | case LayerType::Minimum: |
| 659 | { |
| 660 | const TensorInfo& input0 = layer.GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 661 | const TensorInfo& input1 = layer.GetInputSlot(1).GetConnection()->GetTensorInfo(); |
| 662 | const TensorInfo& output = layer.GetOutputSlot(0).GetTensorInfo(); |
| 663 | result = layerSupportObject->IsMinimumSupported(OverrideDataType(input0, dataType), |
| 664 | OverrideDataType(input1, dataType), |
| 665 | OverrideDataType(output, dataType), |
| 666 | reason); |
| 667 | break; |
| 668 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 669 | default: |
| 670 | { |
| 671 | BOOST_ASSERT_MSG(false, "WorkloadFactory did not recognise type of layer."); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 672 | reason.value() = "Unrecognised layer type"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 673 | result = false; |
| 674 | break; |
| 675 | } |
| 676 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 677 | return result; |
| 678 | } |
| 679 | |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 680 | bool IWorkloadFactory::IsLayerSupported(const IConnectableLayer& connectableLayer, |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 681 | Optional<DataType> dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 682 | std::string& outReasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 683 | { |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 684 | auto layer = boost::polymorphic_downcast<const Layer*>(&connectableLayer); |
David Beck | 33f0ae0 | 2018-10-18 15:13:56 +0100 | [diff] [blame] | 685 | return IsLayerSupported(layer->GetBackendId(), connectableLayer, dataType, outReasonIfUnsupported); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 686 | } |
| 687 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 688 | } |