30 #include <client/include/IProfilingService.hpp> 32 #include <common/include/ProfilingGuid.hpp> 34 #include <fmt/format.h> 75 return pNetworkImpl->AddComparisonLayer(comparisonDescriptor, name);
82 return pNetworkImpl->AddConcatLayer(concatDescriptor, name);
89 return pNetworkImpl->AddConvolution2dLayer(convolution2dDescriptor, name);
95 return pNetworkImpl->AddConvolution3dLayer(convolution3dDescriptor, name);
102 return pNetworkImpl->AddDepthToSpaceLayer(depthToSpaceDescriptor, name);
110 return pNetworkImpl->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, name);
125 return pNetworkImpl->AddDetectionPostProcessLayer(descriptor, anchors, name);
132 return pNetworkImpl->AddElementwiseUnaryLayer(elementwiseUnaryDescriptor, name);
139 return pNetworkImpl->AddFillLayer(fillDescriptor, name);
145 return pNetworkImpl->AddFullyConnectedLayer(fullyConnectedDescriptor, name);
151 return pNetworkImpl->AddPermuteLayer(permuteDescriptor, name);
157 return pNetworkImpl->AddBatchToSpaceNdLayer(batchToSpaceNdDescriptor, name);
163 return pNetworkImpl->AddPooling2dLayer(pooling2dDescriptor, name);
169 return pNetworkImpl->AddPooling3dLayer(pooling3dDescriptor, name);
177 return pNetworkImpl->AddPrecompiledLayer(preCompiledDescriptor, std::move(compiledBlobPtr), backend, name);
183 return pNetworkImpl->AddActivationLayer(activationDescriptor, name);
189 return pNetworkImpl->AddNormalizationLayer(normalizationDescriptor, name);
194 return pNetworkImpl->AddSliceLayer(sliceDescriptor, name);
199 return pNetworkImpl->AddSoftmaxLayer(softmaxDescriptor, name);
205 return pNetworkImpl->AddSplitterLayer(splitterDescriptor, name);
230 return pNetworkImpl->AddBatchNormalizationLayer(desc, mean, variance, beta, gamma, name);
241 return pNetworkImpl->AddResizeLayer(resizeDescriptor, name);
247 return pNetworkImpl->AddReduceLayer(reduceDescriptor, name);
253 return pNetworkImpl->AddInstanceNormalizationLayer(desc, name);
259 return pNetworkImpl->AddL2NormalizationLayer(desc, name);
265 return pNetworkImpl->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
277 return pNetworkImpl->AddReshapeLayer(reshapeDescriptor, name);
283 return pNetworkImpl->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
289 return pNetworkImpl->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
305 return pNetworkImpl->AddLstmLayer(descriptor, params, name);
325 return pNetworkImpl->AddMeanLayer(meanDescriptor, name);
342 return pNetworkImpl->AddStridedSliceLayer(stridedSliceDescriptor, name);
376 return pNetworkImpl->AddTransposeConvolution2dLayer(descriptor, weights, biases, name);
382 return pNetworkImpl->AddTransposeLayer(transposeDescriptor, name);
405 return pNetworkImpl->AddQuantizedLstmLayer(params, name);
412 return pNetworkImpl->AddQLstmLayer(descriptor, params, name);
418 return pNetworkImpl->AddLogicalBinaryLayer(descriptor, name);
426 return pNetworkImpl->AddUnidirectionalSequenceLstmLayer(descriptor, params, name);
432 return pNetworkImpl->AddChannelShuffleLayer(descriptor, name);
438 return pNetworkImpl->AddBatchMatMulLayer(descriptor, name);
448 return new INetwork(networkOptions);
462 : pOptimizedNetworkImpl(new
OptimizedNetworkImpl(*other.pOptimizedNetworkImpl.get(), modelOptions)) {}
518 return m_Graph->SerializeToDot(stream);
523 return m_Graph->GetNumInputs();
528 return m_Graph->GetNumOutputs();
532 Optional<std::vector<std::string>&> errorMessages)
534 std::stringstream fullErrorMessage;
535 fullErrorMessage <<
"ERROR: " << errorMessage;
539 errorMessages.value().push_back(fullErrorMessage.str());
544 Optional<std::vector<std::string>&> warningMessages)
546 std::stringstream fullWarningMessage;
547 fullWarningMessage <<
"WARNING: " << warningMessage;
551 warningMessages.value().push_back(fullWarningMessage.str());
558 Optional<std::vector<std::string>&> errMessages)
560 std::stringstream failureMsg;
572 bool noErrors =
true;
574 for (
unsigned int i = 0; i < numOutputs; i++) {
582 std::stringstream ss;
584 <<
" (" << layer->
GetNameStr() <<
") is of type" 585 <<
" Quantized 8 bit but its scale parameter has not been set";
593 std::stringstream ss;
594 ss <<
"Quantization parameters for Softmax layer (Scale: " <<
596 ") are incorrect and have been updated to Scale: 0.00390625 and Offset: 0";
607 template <
typename LayerT>
610 LayerT* layer = PolymorphicDowncast<LayerT*>(l);
621 layer->m_Weight->template GetConstTensor<armnn::BFloat16>(), info.
GetNumElements(), newValues.data());
637 const std::vector<BackendId>& availablePreferredBackends,
638 std::string& reasonIfUnsupported,
639 Optional<std::vector<std::string>&> errMessages)
644 auto ReturnError = [&](
const Layer* layer)
660 auto ConstantLayerFromFp16ToFp32 = [](
Layer& layer)
664 ConstantLayer* constantLayer = PolymorphicDowncast<ConstantLayer*>(&layer);
670 std::vector<float> newValues(info.GetNumElements());
674 info.GetNumElements(),
687 bool checkType =
false;
691 auto connectedOutputSlot = inputSlot.GetConnectedOutputSlot();
694 if (connectedOutputSlot->GetNumConnections() == 1)
697 ConstantLayerFromFp16ToFp32(connectedOutputSlot->GetOwningLayer());
703 std::vector<ConvertFp16ToFp32Layer*> convertFp16ToFp32Layers;
706 convertFp16ToFp32Layers =
711 std::vector<ConvertFp32ToFp16Layer*> convertFp32ToFp16Layers;
714 convertFp32ToFp16Layers =
719 auto AssignFirstSupportedBackend = [&](
Layer* layer,
BackendId preferredBackend)
721 bool supportedBackendFound =
false;
722 std::string reasonIfUnsupported;
728 reasonIfUnsupported))
730 supportedBackendFound =
true;
734 for (
const auto& backend : availablePreferredBackends)
737 if (backend == preferredBackend)
745 reasonIfUnsupported))
747 supportedBackendFound =
true;
753 return supportedBackendFound;
758 if (!AssignFirstSupportedBackend(convertLayer, backend))
760 return ReturnError(convertLayer);
766 if (!AssignFirstSupportedBackend(convertLayer, backend))
768 return ReturnError(convertLayer);
777 const auto layerType = layer->
GetType();
786 std::vector<ConvertBf16ToFp32Layer*> convertBf16ToFp32Layers;
788 && !revertConstantWeightsConversion)
790 convertBf16ToFp32Layers =
794 ConvertBf16ToFp32Weight<Convolution2dLayer>(layer);
798 ConvertBf16ToFp32Weight<FullyConnectedLayer>(layer);
803 std::vector<ConvertFp32ToBf16Layer*> convertFp32ToBf16Layers;
806 convertFp32ToBf16Layers =
811 auto AssignFirstSupportedBackend = [&](
Layer* layer,
BackendId preferredBackend)
813 bool supportedBackendFound =
false;
814 std::string reasonIfUnsupported;
820 reasonIfUnsupported))
822 supportedBackendFound =
true;
826 for (
const auto& backend : availablePreferredBackends)
829 if (backend == preferredBackend)
837 reasonIfUnsupported))
839 supportedBackendFound =
true;
845 return supportedBackendFound;
850 if (!AssignFirstSupportedBackend(convertLayer, backend))
852 return ReturnError(convertLayer);
858 if (!AssignFirstSupportedBackend(convertLayer, backend))
860 return ReturnError(convertLayer);
868 std::stringstream warningMsg;
870 <<
" is not supported on requested backend " << layer->
GetBackendId().
Get()
873 <<
" (reason: " << reasonIfUnsupported
874 <<
"), falling back to the next backend.";
889 Optional<std::vector<std::string>&> errMessages,
892 std::vector<BackendId>& availablePreferredBackends)
894 auto ReturnError = [&](
const Layer* layer)
899 auto layer = PolymorphicDowncast<Layer*>(it);
907 layer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo().GetDataType();
909 layer->GetOutputSlot(0).GetTensorInfo().GetDataType();
911 std::string reasonIfUnsupported;
921 if (layer->GetBackendHint().has_value() &&
926 layer->GetBackendHint().value(),
929 availablePreferredBackends,
939 for (
const auto& backend : availablePreferredBackends)
941 if (layer->GetBackendHint().has_value() &&
942 layer->GetBackendHint().value() == backend)
953 availablePreferredBackends,
989 layer->SetBackendId(cpuBackendId);
994 result = ReturnError(layer);
1004 Optional<std::vector<std::string>&> errMessages)
1010 if (availablePreferredBackends.empty())
1012 std::stringstream failureMsg;
1013 failureMsg <<
"No preferred backends are available";
1020 for (
auto it = firstLayer; it != lastLayer; ++it)
1027 availablePreferredBackends);
1030 for (
auto it = firstLayer; it != lastLayer; ++it)
1032 auto layer = PolymorphicDowncast<Layer*>(*it);
1036 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1037 layer->SetBackendId(connectedBackendId);
1048 Optional<std::vector<std::string>&> errMessages)
1054 if (availablePreferredBackends.empty())
1056 std::stringstream failureMsg;
1057 failureMsg <<
"No preferred backends are available";
1064 for (
auto it = firstLayer; it != lastLayer; ++it)
1071 availablePreferredBackends);
1074 for (
auto it = firstLayer; it != lastLayer; ++it)
1076 auto layer = PolymorphicDowncast<Layer*>(*it);
1080 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1081 layer->SetBackendId(connectedBackendId);
1091 Optional<std::vector<std::string>&> errMessages)
1109 auto backendFactory = backendRegistry.GetFactory(selectedBackend);
1110 auto backendObjPtr = backendFactory();
1113 backendObjPtr->RegisterTensorHandleFactories(handleFactoryRegistry);
1115 backends[backendObjPtr->GetId()] = std::move(backendObjPtr);
1125 Optional<std::vector<std::string>&> errMessages)
1137 auto backendObjPtr = backends.find(selectedBackend)->second.get();
1150 [&backendObjPtr](
const Layer& layer)
1157 if (subgraphs.empty())
1164 for (
auto& subgraph : subgraphs)
1168 OptimizationViews optimizationViews = backendObjPtr->OptimizeSubgraphView(*subgraph, modelOptions);
1172 for (
auto& substitution : optimizationViews.GetSubstitutions())
1175 SubgraphView& replacementSubgraph = substitution.m_ReplacementSubgraph;
1176 SubgraphView& substitutableSubgraph = substitution.m_SubstitutableSubgraph;
1181 std::for_each(subgraphLayers.begin(), subgraphLayers.end(), [&selectedBackend](
IConnectableLayer* l)
1184 PolymorphicDowncast<Layer*>(l)->SetBackendId(selectedBackend);
1188 if (!optimizationViews.GetFailedSubgraphs().empty())
1190 std::stringstream warningMsg;
1191 warningMsg <<
"Some sub-graph(s) failed to optimized on " << backendObjPtr->GetId() <<
" backend.";
1196 if (!backendObjPtr->GetId().IsCpuRef())
1199 settingsCopy.m_IgnoredBackends.insert(backendObjPtr->GetId());
1203 for (
auto& failedSubgraph : optimizationViews.GetFailedSubgraphs())
1206 std::stringstream subgraphMsg;
1207 subgraphMsg <<
"Re-assigning backends to " << failedSubgraph.GetIConnectableLayers().size()
1208 <<
" layers inside sub-graph " << count++;
1215 if (reassignmentResult.m_Error)
1238 if (srcFactory && dstFactory &&
1264 if (frmBackend == backends.end() ||
1265 !frmBackend->second->SupportsTensorAllocatorAPI())
1272 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1279 const Layer& connectedLayer = connection->GetOwningLayer();
1281 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1282 ARMNN_ASSERT_MSG(toBackend != backends.end(),
"Backend id not found for the connected layer");
1284 if (!toBackend->second.get()->SupportsTensorAllocatorAPI())
1290 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1291 for (
auto&& dst : dstPrefs)
1305 auto it = factoryScores.find(dst);
1306 if (it == factoryScores.end())
1309 factoryScores[dst] = 0;
1318 factoryScores[dst]++;
1321 if (factoryScores[dst] > topScore)
1323 topScore = factoryScores[dst];
1352 if (frmBackend == backends.end() ||
1353 !frmBackend->second->SupportsTensorAllocatorAPI())
1358 bool outputConnection =
false;
1361 const Layer& connectedLayer = connection->GetOwningLayer();
1364 outputConnection =
true;
1372 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1373 for (
auto&& pref : srcPrefs)
1378 if (outputConnection)
1381 bool fallbackConnection =
false;
1384 if (inputSlot.GetConnectedOutputSlot()->GetOwningLayer().GetBackendId() != layer.
GetBackendId())
1386 fallbackConnection =
true;
1389 if (fallbackConnection)
1393 if (!factoryCap.empty())
1403 if (!outputConnection)
1407 if (!factoryCap.empty())
1426 auto it = factoryScores.find(pref);
1427 if (it == factoryScores.end())
1430 factoryScores[pref] = 0;
1437 const Layer& connectedLayer = connection->GetOwningLayer();
1439 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1440 ARMNN_ASSERT_MSG(toBackend != backends.end(),
"Backend id not found for the connected layer");
1442 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1443 for (
auto&& src : srcPrefs)
1445 if (factoryScores.find(src) == factoryScores.end())
1450 for (
auto&& dst : dstPrefs)
1455 factoryScores[src]++;
1463 int minScore = std::numeric_limits<int>::max();
1464 for (
auto it : factoryScores)
1466 minScore = std::min(minScore, it.second);
1470 std::vector<ITensorHandleFactory::FactoryId> optimalFactories;
1471 for (
auto it : factoryScores)
1473 if (it.second == minScore)
1475 optimalFactories.push_back(it.first);
1480 for (
auto&& srcPref : srcPrefs)
1482 for (
auto&& comp : optimalFactories)
1484 if (comp == srcPref)
1497 const Layer& connectedLayer,
1501 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1502 ARMNN_ASSERT_MSG(toBackend != backends.end(),
"Backend id not found for the connected layer");
1504 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1527 for (
auto&& pref : dstPrefs)
1529 if (pref == srcFactoryId)
1539 for (
auto&& pref : dstPrefs)
1558 if (srcCapability.empty() && dstCapability.empty() && srcFallback.empty() && dstFallback.empty())
1569 for (
auto&& pref : dstPrefs)
1588 Optional<std::vector<std::string>&> errMessages)
1593 optGraph.
ForEachLayer([&backends, ®istry, &result, &errMessages, importEnabled, exportEnabled](
Layer* layer)
1624 unsigned int connectionIdx = 0;
1627 const Layer& connectedLayer = connection->GetOwningLayer();
1630 registry, importEnabled);
1637 errMessages.value().emplace_back(
"Could not find valid strategy required for compatibility" 1638 " between backends.");
1654 const std::vector<BackendId>& backendPreferences,
1657 Optional<std::vector<std::string>&> messages)
1667 if (backendPreferences.empty())
1680 std::unique_ptr<Graph> graph = std::make_unique<Graph>(inGraph);
1688 optimizedOptions.push_back(importExport);
1705 using namespace optimizations;
1763 std::stringstream failureMsg;
1764 failureMsg <<
"None of the preferred backends " << backendPreferences
1782 if (assignBackendsResult.
m_Error)
1797 if (backendOptimizationResult.
m_Error)
1830 tensorHandleFactoryRegistry,
1851 const std::vector<BackendId>& backendPreferences,
1854 Optional<std::vector<std::string>&> messages)
1863 bool NetworkImpl::GetShapeInferenceMethod()
1865 bool shapeInferenceMethod =
false;
1869 if (name ==
"InferAndValidate")
1871 shapeInferenceMethod |= value.
AsBool();
1874 return shapeInferenceMethod;
1877 bool NetworkImpl::GetAllowExpandedDims()
1879 bool allowExpandedDims =
false;
1883 if (name ==
"AllowExpandedDims")
1885 allowExpandedDims |= value.
AsBool();
1888 return allowExpandedDims;
1892 : m_NetworkOptions(networkOptions),
1893 m_Graph(
std::make_unique<
Graph>(GetShapeInferenceMethod(), GetAllowExpandedDims()))
1908 return m_Graph->AddLayer<
InputLayer>(id, name);
1919 return m_Graph->AddLayer<
CastLayer>(name);
1930 return m_Graph->AddLayer<
ComparisonLayer>(comparisonDescriptor, name);
1942 return m_Graph->AddLayer<
FillLayer>(fillDescriptor, name);
1958 unsigned int numInputs = fullyConnectedDescriptor.
GetNumInputs();
1967 weightsInfo.SetConstant();
1983 biasInfo.SetConstant();
2001 if ( fullyConnectedDescriptor.m_BiasEnabled && numInputs == 3 )
2009 else if ( !fullyConnectedDescriptor.m_BiasEnabled && numInputs == 2 )
2012 layer->m_Bias =
nullptr;
2017 "AddFullyConnectedLayer: Value mismatch. When bias is enabled in the " 2018 "descriptor the number of inputs is expected to be 3 otherwise 2. " 2019 "BiasEnabled={}, numInputs={}",
2020 fullyConnectedDescriptor.m_BiasEnabled,
2030 return m_Graph->AddLayer<
ConcatLayer>(concatDescriptor, name);
2047 auto weightsTensorHandle = std::make_shared<ScopedTensorHandle>(weights);
2049 layer->m_Weight = weightsTensorHandle;
2051 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
2053 if (biases.
has_value() && convolution2dDescriptor.m_BiasEnabled)
2056 auto biasTensorHandle = std::make_shared<ScopedTensorHandle>(biases.
value());
2058 layer->m_Bias = biasTensorHandle;
2104 auto weightsTensorHandle = std::make_shared<ScopedTensorHandle>(weights);
2106 layer->m_Weight = weightsTensorHandle;
2109 weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
2112 if (biases.
has_value() && convolution2dDescriptor.m_BiasEnabled)
2115 auto biasTensorHandle = std::make_shared<ScopedTensorHandle>(biases.
value());
2117 layer->m_Bias = biasTensorHandle;
2131 layer->
m_Anchors = std::make_shared<ScopedTensorHandle>(anchors);
2139 return m_Graph->AddLayer<
PermuteLayer>(permuteDescriptor, name);
2145 return m_Graph->AddLayer<
Pooling2dLayer>(pooling2dDescriptor, name);
2151 return m_Graph->AddLayer<
Pooling3dLayer>(pooling3dDescriptor, name);
2157 return m_Graph->AddLayer<
ActivationLayer>(activationDescriptor, name);
2163 return m_Graph->AddLayer<
ArgMinMaxLayer>(argMinMaxDescriptor, name);
2167 normalizationDescriptor,
2175 return m_Graph->AddLayer<
SliceLayer>(sliceDescriptor, name);
2181 return m_Graph->AddLayer<
SoftmaxLayer>(softmaxDescriptor, name);
2187 return m_Graph->AddLayer<
SplitterLayer>(splitterDescriptor, name);
2224 layer->
m_Mean = std::make_shared<ScopedTensorHandle>(mean);
2225 layer->m_Variance = std::make_shared<ScopedTensorHandle>(variance);
2226 layer->m_Beta = std::make_shared<ScopedTensorHandle>(beta);
2227 layer->m_Gamma = std::make_shared<ScopedTensorHandle>(gamma);
2234 return m_Graph->AddLayer<
RankLayer>(name);
2240 return m_Graph->AddLayer<
ReduceLayer>(reduceDescriptor, name);
2245 return m_Graph->AddLayer<
ResizeLayer>(resizeDescriptor, name);
2275 layer->
m_LayerOutput = std::make_shared<ScopedTensorHandle>(input);
2283 return m_Graph->AddLayer<
ReshapeLayer>(reshapeDescriptor, name);
2307 const auto layer = m_Graph->AddLayer<
LstmLayer>(descriptor, name);
2312 layer->m_BasicParameters.m_InputToCellWeights =
2314 layer->m_BasicParameters.m_InputToOutputWeights =
2316 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2318 layer->m_BasicParameters.m_RecurrentToCellWeights =
2320 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2322 layer->m_BasicParameters.m_ForgetGateBias =
2324 layer->m_BasicParameters.m_CellBias =
2325 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2326 layer->m_BasicParameters.m_OutputGateBias =
2330 if(!descriptor.m_CifgEnabled)
2335 "when CIFG is disabled.");
2340 "AddLstmLayer: Recurrent To Input Weights cannot be NULL " 2341 "when CIFG is disabled.");
2346 "when CIFG is disabled.");
2348 layer->m_CifgParameters.m_InputToInputWeights =
2350 layer->m_CifgParameters.m_RecurrentToInputWeights =
2352 layer->m_CifgParameters.m_InputGateBias =
2357 if(descriptor.m_ProjectionEnabled)
2362 "when projection is enabled.");
2364 layer->m_ProjectionParameters.m_ProjectionWeights =
2368 layer->m_ProjectionParameters.m_ProjectionBias =
2374 if(descriptor.m_PeepholeEnabled)
2376 if(!descriptor.m_CifgEnabled)
2381 "when Peephole is enabled and CIFG disabled.");
2384 layer->m_PeepholeParameters.m_CellToInputWeights =
2391 "when Peephole is enabled.");
2396 "when Peephole is enabled.");
2399 layer->m_PeepholeParameters.m_CellToForgetWeights =
2401 layer->m_PeepholeParameters.m_CellToOutputWeights =
2406 if(descriptor.m_LayerNormEnabled)
2408 if(!descriptor.m_CifgEnabled)
2413 "when layer normalization is enabled and CIFG disabled.");
2415 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2422 "when layer normalization is enabled.");
2427 "when layer normalization is enabled.");
2432 "when layer normalization is enabled.");
2434 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2436 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2438 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
2456 return m_Graph->AddLayer<
MeanLayer>(meanDescriptor,name);
2461 return m_Graph->AddLayer<
PadLayer>(padDescriptor,name);
2483 return m_Graph->AddLayer<
GatherLayer>(gatherDescriptor, name);
2518 layer->
m_Weight = std::make_shared<ScopedTensorHandle>(weights);
2520 if (descriptor.m_BiasEnabled)
2522 layer->m_Bias = std::make_shared<ScopedTensorHandle>(biases.
value());
2531 return m_Graph->AddLayer<
TransposeLayer>(transposeDescriptor, name);
2537 return m_Graph->AddLayer<
StackLayer>(stackDescriptor, name);
2555 layer->m_QuantizedLstmParameters.m_InputToForgetWeights =
2557 layer->m_QuantizedLstmParameters.m_InputToCellWeights =
2559 layer->m_QuantizedLstmParameters.m_InputToOutputWeights =
2563 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights =
2565 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights =
2567 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights =
2569 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights =
2573 layer->m_QuantizedLstmParameters.m_InputGateBias =
2575 layer->m_QuantizedLstmParameters.m_ForgetGateBias =
2577 layer->m_QuantizedLstmParameters.m_CellBias =
2578 std::make_shared<ScopedTensorHandle>(params.
GetCellBias());
2579 layer->m_QuantizedLstmParameters.m_OutputGateBias =
2589 const auto layer = m_Graph->AddLayer<
QLstmLayer>(descriptor, name);
2594 layer->m_BasicParameters.m_InputToCellWeights =
2596 layer->m_BasicParameters.m_InputToOutputWeights =
2598 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2600 layer->m_BasicParameters.m_RecurrentToCellWeights =
2602 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2604 layer->m_BasicParameters.m_ForgetGateBias =
2606 layer->m_BasicParameters.m_CellBias =
2607 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2608 layer->m_BasicParameters.m_OutputGateBias =
2612 if(!descriptor.m_CifgEnabled)
2622 "AddQLstmLayer: Recurrent To Input Weights cannot be NULL");
2630 layer->m_CifgParameters.m_InputToInputWeights =
2632 layer->m_CifgParameters.m_RecurrentToInputWeights =
2634 layer->m_CifgParameters.m_InputGateBias =
2639 if(descriptor.m_ProjectionEnabled)
2646 layer->m_ProjectionParameters.m_ProjectionWeights =
2652 layer->m_ProjectionParameters.m_ProjectionBias =
2659 if(descriptor.m_PeepholeEnabled)
2671 if(!descriptor.m_CifgEnabled)
2678 layer->m_PeepholeParameters.m_CellToInputWeights =
2682 layer->m_PeepholeParameters.m_CellToForgetWeights =
2684 layer->m_PeepholeParameters.m_CellToOutputWeights =
2689 if(descriptor.m_LayerNormEnabled)
2706 if(!descriptor.m_CifgEnabled)
2713 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2717 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2719 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2721 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
2743 layer->m_BasicParameters.m_InputToCellWeights =
2745 layer->m_BasicParameters.m_InputToOutputWeights =
2747 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2749 layer->m_BasicParameters.m_RecurrentToCellWeights =
2751 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2753 layer->m_BasicParameters.m_ForgetGateBias =
2755 layer->m_BasicParameters.m_CellBias =
2756 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2757 layer->m_BasicParameters.m_OutputGateBias =
2761 if(!descriptor.m_CifgEnabled)
2766 "when CIFG is disabled.");
2771 "AddUnidirectionalSequenceLstmLayer: Recurrent To Input Weights cannot be NULL " 2772 "when CIFG is disabled.");
2777 "when CIFG is disabled.");
2779 layer->m_CifgParameters.m_InputToInputWeights =
2781 layer->m_CifgParameters.m_RecurrentToInputWeights =
2783 layer->m_CifgParameters.m_InputGateBias =
2788 if(descriptor.m_ProjectionEnabled)
2793 "when projection is enabled.");
2795 layer->m_ProjectionParameters.m_ProjectionWeights =
2799 layer->m_ProjectionParameters.m_ProjectionBias =
2805 if(descriptor.m_PeepholeEnabled)
2807 if(!descriptor.m_CifgEnabled)
2812 "cannot be NULL when Peephole is enabled and CIFG disabled.");
2815 layer->m_PeepholeParameters.m_CellToInputWeights =
2822 "when Peephole is enabled.");
2827 "when Peephole is enabled.");
2830 layer->m_PeepholeParameters.m_CellToForgetWeights =
2832 layer->m_PeepholeParameters.m_CellToOutputWeights =
2837 if(descriptor.m_LayerNormEnabled)
2839 if(!descriptor.m_CifgEnabled)
2844 "cannot be NULL when layer normalization is enabled and CIFG disabled.");
2846 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2853 "cannot be NULL when layer normalization is enabled.");
2858 "cannot be NULL when layer normalization is enabled.");
2863 "cannot be NULL when layer normalization is enabled.");
2865 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2867 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2869 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
2893 layer = m_Graph->AddLayer<
PreCompiledLayer>(preCompiledDescriptor,
"pre-compiled");
2917 layer->ExecuteStrategy(strategy);
2922 : m_Graph(new
Graph(*other.m_Graph.get()))
2923 , m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
2924 , m_ModelOptions(modelOptions)
2929 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
2934 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid()), m_ModelOptions(modelOptions)
2944 pOptimizedNetworkImpl->ExecuteStrategy(strategy);
2951 layer->ExecuteStrategy(strategy);
A layer that the constant data can be bound to.
OptimizeForConnection< Layer, PermuteLayer, SquashEqualSiblingsImpl< PermuteLayer > > SquashEqualPermuteSiblings
void ReportError(const std::string &errorMessage, Optional< std::vector< std::string > &> errorMessages)
Iterator begin()
Returns iterator pointing to the beginning of the list. Lowercase for range-based for loops...
IConnectableLayer * AddSubtractionLayer(const char *name=nullptr)
Adds a subtraction layer to the network.
IConnectableLayers::iterator IConnectableLayerIterator
IConnectableLayer * AddReduceLayer(const ReduceDescriptor &reduceDescriptor, const char *name=nullptr)
IConnectableLayerIterator endIConnectable()
IConnectableLayer * AddGatherNdLayer(const char *name=nullptr)
ModelOptions m_ModelOptions
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)
Adds an activation layer to the network.
This layer represents a minimum operation.
static const FactoryId DeferredFactoryId
Use the workload factory to create the tensor handle.
This layer represents a split operation.
OptimizationResult AssignBackends(OptimizedNetworkImpl *optNetObjPtr, BackendSettings &backendSettings, Graph::Iterator &firstLayer, Graph::Iterator &lastLayer, Optional< std::vector< std::string > &> errMessages)
IConnectableLayer * AddCastLayer(const char *name=nullptr)
Adds a cast layer to the network.
LstmBasicParameters m_BasicParameters
const std::vector< InputSlot * > & GetConnections() const
This layer represents a batch normalization operation.
static void Destroy(INetwork *network)
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
OptimizeForConnection< PermuteLayer, PermuteLayer, OptimizeInversePermutesImpl< PermuteLayer > > OptimizeInversePermutes
std::vector< ConvertFp32ToFp16Layer * > InsertConvertFp32ToFp16LayersAfter(Graph &graph, Layer &layer)
void ExecuteStrategy(IStrategy &strategy) const
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
Very basic type safe variant.
QuantizedLstmParameters m_QuantizedLstmParameters
This layer represents a 2D transpose convolution operation.
virtual Status PrintGraph()
No strategy has been defined. Used internally to verify integrity of optimizations.
std::vector< ConvertFp16ToFp32Layer * > InsertConvertFp16ToFp32LayersBefore(Graph &graph, Layer &layer, bool expectCorrectInputType)
IConnectableLayer * AddResizeLayer(const ResizeDescriptor &resizeDescriptor, const char *name=nullptr)
ShapeInferenceMethod m_shapeInferenceMethod
virtual ~OptimizedNetworkImpl()
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
static INetworkPtr Create(const NetworkOptions &networkOptions={})
const TensorShape & GetShape() const
CPU Execution: Reference C++ kernels.
IConnectableLayer * AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor &descriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr)
Adds a 2D transpose convolution layer to the network.
IConnectableLayer * AddQuantizeLayer(const char *name=nullptr)
IConnectableLayer * AddBatchMatMulLayer(const BatchMatMulDescriptor &desc, const char *name=nullptr)
OptimizeForExclusiveConnection< PadLayer, Convolution2dLayer, pad_fold::FoldPadIntoConvolution2dImpl > FoldPadIntoConvolution2d
Optimizer::Optimizations MakeOptimizations(Args &&... args)
IConnectableLayer * AddQLstmLayer(const QLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
Add a QLstm layer to the network.
Optional< BackendId > GetBackendHint() const
size_t GetNumInputs() const
IConnectableLayer * AddRankLayer(const char *name=nullptr)
A ReshapeDescriptor for the ReshapeLayer.
const IConnectableLayers & GetIConnectableLayers() const
OptimizeForConnection< TransposeLayer, TransposeLayer, OptimizeInversePermutesImpl< TransposeLayer > > OptimizeInverseTransposes
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
OptimizeForExclusiveConnection< PadLayer, DepthwiseConvolution2dLayer, pad_fold::FoldPadIntoDepthwiseConvolution2dImpl > FoldPadIntoDepthwiseConvolution2d
IConnectableLayer * AddChannelShuffleLayer(const ChannelShuffleDescriptor &channelShuffleDescriptor, const char *name=nullptr)
static INetwork * CreateRaw(const NetworkOptions &networkOptions={})
static ProfilerManager & GetInstance()
IConnectableLayer * AddGatherLayer(const GatherDescriptor &descriptor, const char *name=nullptr)
Add Gather layer to the network.
OptimizeForConnection< TransposeLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< TransposeLayer > > TransposeAndBatchToSpaceAsDepthToSpace
OptimizeForExclusiveConnection< DepthwiseConvolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< DepthwiseConvolution2dLayer, armnn::DataType::Float32 > > FuseBatchNormIntoDepthwiseConvolution2DFloat32
IConnectableLayer * AddConstantLayer(const ConstTensor &input, const char *name=nullptr)
Adds a layer with no inputs and a single output, which always corresponds to the passed in constant t...
IConnectableLayer * AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D depthwise convolution layer to the network.
NetworkImpl(const NetworkOptions &networkOptions={})
ITensorHandleFactory::FactoryId CalculateSlotOptionForOutput(BackendsMap &backends, OutputSlot &slot, TensorHandleFactoryRegistry ®istry)
A ComparisonDescriptor for the ComparisonLayer.
This layer represents a depthwise convolution 2d operation.
static void ConvertBFloat16ToFloat32(const void *srcBFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
bool RequiresCopy(ITensorHandleFactory::FactoryId src, ITensorHandleFactory::FactoryId dst, TensorHandleFactoryRegistry ®istry)
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)
IConnectableLayer * AddStackLayer(const StackDescriptor &descriptor, const char *name=nullptr)
Adds a stack layer to the network.
std::shared_ptr< ConstTensorHandle > m_LayerOutput
IConnectableLayer * AddShapeLayer(const char *name=nullptr)
Adds a shape layer to the network.
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
std::vector< BackendOptions > ModelOptions
IConnectableLayer * AddMergeLayer(const char *name=nullptr)
A Convolution2dDescriptor for the Convolution2dLayer.
Layer & GetOwningLayer() const
Source backends tensor data can be exported to destination backend tensor without copy...
IConnectableLayer * AddPrecompiledLayer(const PreCompiledDescriptor &preCompiledDescriptor, CompiledBlobPtr compiledBlobPtr, const Optional< BackendId > &backend, const char *name=nullptr)
IConnectableLayer * AddQuantizeLayer(const char *name=nullptr)
Add a quantize layer to the network.
This layer converts data type Float 16 to Float 32.
int Connect(InputSlot &destination)
IConnectableLayer * AddMinimumLayer(const char *name=nullptr)
Add a Minimum layer to the network.
IConnectableLayer * AddQuantizedLstmLayer(const QuantizedLstmInputParams ¶ms, const char *name=nullptr)
IConnectableLayer * AddL2NormalizationLayer(const L2NormalizationDescriptor &desc, const char *name=nullptr)
Adds an L2 normalization layer to the network.
bool m_BiasEnabled
Enable/disable bias.
IConnectableLayer * AddConstantLayer(const ConstTensor &input, const char *name=nullptr)
IConnectableLayer * AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor &elementwiseUnaryDescriptor, const char *name=nullptr)
IConnectableLayer * AddMergeLayer(const char *name=nullptr)
Adds a merge layer to the network.
IConnectableLayer * AddConvertFp32ToFp16Layer(const char *name=nullptr)
IConnectableLayer * AddPermuteLayer(const PermuteDescriptor &permuteDescriptor, const char *name=nullptr)
Adds a permute layer to the network.
IConnectableLayer * AddNormalizationLayer(const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr)
IConnectableLayer * AddSliceLayer(const SliceDescriptor &sliceDescriptor, const char *name=nullptr)
Adds a slice layer to the network.
static void Pass(Graph &graph, const Optimizations &optimizations)
OptimizeForExclusiveConnection< DepthwiseConvolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< DepthwiseConvolution2dLayer, armnn::DataType::Float16 > > FuseBatchNormIntoDepthwiseConvolution2DFloat16
IConnectableLayer * AddFloorLayer(const char *name=nullptr)
Adds a floor layer to the network.
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)
Adds a 2D pooling layer to the network.
This layer represents a SpaceToDepth operation.
IConnectableLayer * AddMeanLayer(const MeanDescriptor &meanDescriptor, const char *name=nullptr)
OptimizeForType< Layer, RedirectMembersToConstantInputsImpl > RedirectMembersToConstantInputs
This layer represents a reshape operation.
IConnectableLayerIterator beginIConnectable()
void ExecuteStrategy(IStrategy &strategy) const
OptimizeForExclusiveConnection< Convolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< Convolution2dLayer, armnn::DataType::Float16 > > FuseBatchNormIntoConvolution2DFloat16
OptimizeForExclusiveConnection< Convolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< Convolution2dLayer, armnn::DataType::Float32 > > FuseBatchNormIntoConvolution2DFloat32
#define ARMNN_LOG(severity)
IConnectableLayer * AddMinimumLayer(const char *name=nullptr)
IConnectableLayer * AddFillLayer(const FillDescriptor &fillDescriptor, const char *name=nullptr)
Add an Fill layer to the network.
Main network class which provides the interface for building up a neural network. ...
This layer represents an activation operation with the specified activation function.
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
IConnectableLayer * AddSpaceToDepthLayer(const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr)
BackendRegistry & BackendRegistryInstance()
This layer converts data type BFloat16 to Float32.
LayerT * ConvertBf16ToFp32Weight(Layer *l)
std::vector< BackendOptions > NetworkOptions
bool m_ReduceFp32ToBf16
Reduces all Fp32 operators in the model to Bf16 for faster processing.
std::shared_ptr< ConstTensorHandle > m_Mean
A unique pointer to store Mean values.
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
IConnectableLayer * AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
This layer represents an unknown operation in the input graph.
OptimizeForConnection< Layer, ReshapeLayer, SquashEqualSiblingsImpl< ReshapeLayer > > SquashEqualReshapeSiblings
IConnectableLayer * AddLogSoftmaxLayer(const LogSoftmaxDescriptor &logSoftmaxDescriptor, const char *name=nullptr)
Adds a log softmax layer to the network.
IConnectableLayer * AddResizeLayer(const ResizeDescriptor &resizeDescriptor, const char *name=nullptr)
Adds a resize layer to the network.
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)
This layer represents a detection postprocess operator.
BackendIdSet m_SupportedBackends
OptimizeForConnection< Layer, TransposeLayer, MoveTransposeUpImpl > MoveTransposeUp
IConnectableLayer * AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr)
Adds a batch to space ND layer to the network.
OptimizationResult ReturnWithError(OptimizationResult res, const Layer *layer, const BackendSettings &backendSettings, Optional< std::vector< std::string > &> errMessages)
Copyright (c) 2021 ARM Limited and Contributors.
This layer represents a pad operation.
This layer represents a LSTM operation.
void IgnoreUnused(Ts &&...)
IConnectableLayer * AddDivisionLayer(const char *name=nullptr)
Adds a division layer to the network.
void SetBackendId(const BackendId &id)
const std::vector< InputSlot > & GetInputSlots() const
bool IsBackendSupported(const BackendId &backend) const
LayerList::const_iterator Iterator
This layer represents a reduction operation.
IConnectableLayer * AddLogSoftmaxLayer(const LogSoftmaxDescriptor &logSoftmaxDescriptor, const char *name=nullptr)
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
This layer represents a permutation operation.
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
This layer represents a SpaceToBatchNd operation.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
OptimizeForType< Layer, AddDebugImpl > InsertDebugLayer
virtual Status SerializeToDot(std::ostream &stream) const
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const char *name=nullptr)
Adds a fully connected layer to the network.
OptimizeForConnection< ReshapeLayer, ReshapeLayer, OptimizeConsecutiveReshapesImpl > OptimizeConsecutiveReshapes
IConnectableLayer * AddMeanLayer(const MeanDescriptor &meanDescriptor, const char *name=nullptr)
Add a Mean layer to the network.
Private implementation of INetwork.
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Adds an input layer to the network.
This layer represents a elementwiseUnary operation.
constexpr const char * GetDataTypeName(DataType dataType)
IConnectableLayer * AddStridedSliceLayer(const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr)
Adds a strided slice layer to the network.
A ResizeDescriptor for the ResizeLayer.
A StackDescriptor for the StackLayer.
Destination backend can work directly with tensors on source backend.
std::unique_ptr< void, CompiledBlobDeleter > CompiledBlobPtr
IConnectableLayer * AddGatherLayer(const GatherDescriptor &gatherDescriptor, const char *name=nullptr)
virtual std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
IConnectableLayer * AddSpaceToDepthLayer(const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr)
Adds a space to depth layer to the network.
OptimizeForConnection< ConvertFp16ToFp32Layer, ConvertFp32ToFp16Layer, OptimizeInverseConversionsImpl > OptimizeInverseConversionsFp16
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
Adds a softmax layer to the network.
bool m_ReduceFp32ToFp16
Reduces all Fp32 operators in the model to Fp16 for faster processing.
The SubgraphView class represents a subgraph of a Graph.
IConnectableLayer * AddFloorLayer(const char *name=nullptr)
A PadDescriptor for the PadLayer.
const std::string ToString() const
This layer represents an instance normalization operation.
OptimizeForConnection< ConstantLayer, PermuteLayer, ConvertConstPermuteLayersToConstLayers > FusePermuteIntoConstLayer
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
IConnectableLayer * AddGatherNdLayer(const char *name=nullptr)
Add GatherNd layer to the network.
OptimizeForConnection< PermuteLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteLayer > > PermuteAndBatchToSpaceAsDepthToSpace
IConnectableLayer * AddQLstmLayer(const QLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
OptimizeForConnection< Layer, PermuteLayer, MovePermuteUpImpl > MovePermuteUp
This layer represents a Logical Binary operation.
IConnectableLayer * AddStridedSliceLayer(const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr)
std::unique_ptr< NetworkImpl > pNetworkImpl
void AssignBackendsIConnectable(OptimizedNetworkImpl *optNetObjPtr, IConnectableLayer *it, Optional< std::vector< std::string > &> errMessages, OptimizationResult &result, BackendSettings &backendSettings, std::vector< BackendId > &availablePreferredBackends)
A layer user-provided data can be bound to (e.g. inputs, outputs).
friend IOptimizedNetworkPtr Optimize(const INetwork &inNetwork, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options, Optional< std::vector< std::string > &> messages)
Create an optimized version of the network.
void ForEachLayer(Func func) const
std::list< IConnectableLayer * > IConnectableLayers
virtual std::vector< Capability > GetCapabilities(const IConnectableLayer *layer, const IConnectableLayer *connectedLayer, CapabilityClass capabilityClass)
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
This layer dequantizes the input tensor.
ConvertConstants< Float32ToFloat16, IsFloat16Layer > ConvertConstantsFloatToHalf
void SetPreCompiledObject(PreCompiledObjectPtr preCompiledObject)
OptimizeForType< TransposeLayer, TransposeAsReshapeImpl > TransposeAsReshape
This layer represents a Gather operator.
This layer represents a fully connected operation.
An LstmDescriptor for the LstmLayer.
IConnectableLayer * AddLstmLayer(const LstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
Add a Lstm layer to the network.
IConnectableLayer * AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor &descriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr)
#define ARMNN_ASSERT_MSG(COND, MSG)
IConnectableLayer * AddRankLayer(const char *name=nullptr)
Adds a rank layer to the network.
This layer represents a QuantizedLstm operation.
This layer represents a log softmax operation.
OptimizationResult ApplyBackendOptimizations(OptimizedNetworkImpl *optNetObjPtr, BackendSettings &backendSettings, BackendsMap &backends, const ModelOptions &modelOptions, Optional< std::vector< std::string > &> errMessages)
IConnectableLayer * AddPreluLayer(const char *name=nullptr)
std::string CreateDirectory(std::string sPath)
Returns full path to temporary folder.
IConnectableLayer * AddConvertFp16ToFp32Layer(const char *name=nullptr)
IConnectableLayer * AddConvolution3dLayer(const Convolution3dDescriptor &convolution3dDescriptor, const char *name=nullptr)
Adds a 3D convolution layer to the network.
A L2NormalizationDescriptor for the L2NormalizationLayer.
OptimizationResult SelectTensorHandleStrategy(Graph &optGraph, BackendsMap &backends, TensorHandleFactoryRegistry ®istry, bool importEnabled, bool exportEnabled, Optional< std::vector< std::string > &> errMessages)
int32_t GetQuantizationOffset() const
LstmBasicParameters m_BasicParameters
An ArgMinMaxDescriptor for ArgMinMaxLayer.
float GetQuantizationScale() const
DataType GetDataType() const
const std::shared_ptr< IProfiler > & GetProfiler() const
An OriginsDescriptor for the ConcatLayer.
A ReduceDescriptor for the REDUCE operators.
IConnectableLayer * AddDetectionPostProcessLayer(const DetectionPostProcessDescriptor &descriptor, const ConstTensor &anchors, const char *name=nullptr)
bool has_value() const noexcept
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
This layer represents a stack operation.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
bool RevertConstantWeightsToFP32(Layer *layer)
This layer represents a merge operation.
This layer represents a softmax operation.
Validate all output shapes.
IConnectableLayer * AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor &desc, const char *name=nullptr)
Adds an instance normalization layer to the network.
const std::string & GetNameStr() const
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
std::vector< ConvertBf16ToFp32Layer * > InsertConvertBf16ToFp32LayersBefore(Graph &graph, Layer &layer, bool expectCorrectInputType)
A GatherDescriptor for the GatherLayer.
std::unique_ptr< OptimizedNetworkImpl > pOptimizedNetworkImpl
IConnectableLayer * AddDivisionLayer(const char *name=nullptr)
This layer represents a BatchToSpaceNd operation.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Adds an output layer to the network.
std::vector< SubgraphViewPtr > Subgraphs
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
IConnectableLayer * AddPooling3dLayer(const Pooling3dDescriptor &pooling3dDescriptor, const char *name=nullptr)
virtual size_t GetNumOutputs() const
IConnectableLayer * AddArgMinMaxLayer(const ArgMinMaxDescriptor &desc, const char *name=nullptr)
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
IConnectableLayer * AddDequantizeLayer(const char *name=nullptr)
void SetQuantizationScale(float scale)
This layer represents a ArgMinMax operation.
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr)
#define ARMNN_ASSERT(COND)
A StandInDescriptor for the StandIn layer.
A QLstmDescriptor for the QLstmLayer.
BackendIdVector GetAvailablePreferredBackends() const
GPU Execution: OpenCL: ArmCompute.
Device specific knowledge to be passed to the optimizer.
IConnectableLayer * AddSwitchLayer(const char *name=nullptr)
static bool IsLayerSupported(const BackendId &backendId, const IConnectableLayer &layer, Optional< DataType > dataType, std::string &outReasonIfUnsupported)
ArmNN performs an optimization on each model/network before it gets loaded for execution.
static void ConvertFloat16To32(const void *srcFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
IConnectableLayer * AddBatchMatMulLayer(const BatchMatMulDescriptor &descriptor, const char *name=nullptr)
Add a BatchMatMul layer to the network.
IConnectableLayer * AddSubtractionLayer(const char *name=nullptr)
An ActivationDescriptor for the ActivationLayer.
IConnectableLayer * AddLogicalBinaryLayer(const LogicalBinaryDescriptor &logicalBinaryDescriptor, const char *name=nullptr)
IConnectableLayer * AddChannelShuffleLayer(const ChannelShuffleDescriptor &descriptor, const char *name=nullptr)
Add a ChannelShuffle layer to the network.
std::vector< ConvertFp32ToBf16Layer * > InsertConvertFp32ToBf16LayersAfter(Graph &graph, Layer &layer)
const BackendId & GetBackendId() const
This layer represents a floor operation.
IConnectableLayer * AddBatchNormalizationLayer(const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr)
Adds a batch normalization layer to the network.
INetwork(NetworkOptions networkOptions={})
A SliceDescriptor for the SliceLayer.
IConnectableLayer * AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr)
Adds a space to batch layer to the network.
A Convolution3dDescriptor for the Convolution3dLayer.
This layer represents a normalization operation.
virtual MemorySourceFlags GetExportFlags() const
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr)
This layer represents a pooling 2d operation.
This layer represents a pooling 3d operation.
This layer converts data type Float 32 to Float 16.
A BatchMatMulDescriptor for the BatchMatMul operator.
This layer represents a transpose operation.
IConnectableLayer * AddPermuteLayer(const PermuteDescriptor &permuteDescriptor, const char *name=nullptr)
This layer represents an addition operation.
IConnectableLayer * AddComparisonLayer(const ComparisonDescriptor &comparisonDescriptor, const char *name=nullptr)
Add a Comparison layer to the network.
void VerifyConstantLayerSetTensorInfo() const
For each ConstantLayer in Graph, ensures TensorInfo is set on all output slots.
QLstmBasicParameters m_BasicParameters
void SubstituteSubgraph(SubgraphView &subgraph, IConnectableLayer *substituteLayer)
Substitutes the given sub-graph with either a new layer or a new sub-graph.
const std::shared_ptr< IProfiler > & GetProfiler() const
A Pooling3dDescriptor for the Pooling3dLayer.
void ExecuteStrategy(IStrategy &strategy) const
IConnectableLayer * AddL2NormalizationLayer(const L2NormalizationDescriptor &desc, const char *name=nullptr)
IConnectableLayer * AddArgMinMaxLayer(const ArgMinMaxDescriptor &desc, const char *name=nullptr)
Adds an ArgMinMax layer to the network.
bool CheckScaleSetOnQuantizedType(Layer *layer, Optional< std::vector< std::string > &> errMessages)
This layer represents a GatherNd operator.
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
Adds a splitter layer to the network.
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
OptimizeForType< PermuteLayer, PermuteAsReshapeImpl > PermuteAsReshape
bool IsWarningOnly() const
OptimizeForConnection< Layer, TransposeLayer, SquashEqualSiblingsImpl< TransposeLayer > > SquashEqualTransposeSiblings
Struct for the users to pass backend specific options.
This layer represents a QLstm operation.
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
Adds an addition layer to the network.
BackendIdVector m_PreferredBackends
This layer represents a subtraction operation.
IConnectableLayer * AddUnidirectionalSequenceLstmLayer(const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
Add a UnidirectionalSequenceLstm layer to the network.
IConnectableLayer * AddTransposeLayer(const TransposeDescriptor &transposeDescriptor, const char *name=nullptr)
This layer calculates both true and false outputs for input.
uint32_t GetNumInputs() const
Get the number of inputs.
This layer represents a LSTM operation.
IConnectableLayer * AddReshapeLayer(const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr)
Adds a reshape layer to the network.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
void RegisterProfiler(IProfiler *profiler)
IConnectableLayer * AddPadLayer(const PadDescriptor &padDescriptor, const char *name=nullptr)
Adds a fully pad layer to the network.
ConvertConstants< Float16ToFloat32, IsFloat32Layer > ConvertConstantsHalfToFloat
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
IConnectableLayer * AddPooling3dLayer(const Pooling3dDescriptor &pooling3dDescriptor, const char *name=nullptr)
Adds a 3D pooling layer to the network.
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
size_t GetNumOutputs() const
IConnectableLayer * AddUnidirectionalSequenceLstmLayer(const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
static Subgraphs SelectSubgraphs(Graph &graph, const LayerSelectorFunction &selector)
Selects subgraphs from a graph based on the selector function and the algorithm.
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const char *name=nullptr)
IConnectableLayer * AddReshapeLayer(const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr)
void ExecuteStrategy(IStrategy &strategy) const
This layer represents a L2 normalization operation.
This layer represents a cast operation.
IConnectableLayer * AddMaximumLayer(const char *name=nullptr)
bool AsBool() const
Value getters.
IConnectableLayer * AddShapeLayer(const char *name=nullptr)
BackendsMap CreateSupportedBackends(TensorHandleFactoryRegistry &handleFactoryRegistry, BackendSettings &backendSettings)
IConnectableLayer * AddCastLayer(const char *name=nullptr)
OptimizeForConnection< ConvertFp32ToFp16Layer, ConvertFp16ToFp32Layer, OptimizeInverseConversionsImpl > OptimizeInverseConversionsFp32
IConnectableLayer * AddStackLayer(const StackDescriptor &stackDescriptor, const char *name=nullptr)
CPU Execution: NEON: ArmCompute.
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
const std::string & Get() const
IConnectableLayer * AddNormalizationLayer(const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr)
Adds a normalization layer to the network.
BackendIdSet m_SelectedBackends
OptimizeForExclusiveConnection< PadLayer, Pooling2dLayer, pad_fold::FoldPadIntoPooling2dImpl > FoldPadIntoPooling2d
IConnectableLayer * AddFillLayer(const FillDescriptor &fillDescriptor, const char *name=nullptr)
Iterator end()
Returns iterator pointing to the end of the list. Lowercase for range-based for loops.
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D convolution layer to the network.
const Graph & GetGraph() const
OptimizationResult AttemptBackendAssignment(BackendSettings &backendSettings, Graph &graph, Layer *layer, BackendId backend, DataType dataTypeIn, DataType dataTypeOut, const std::vector< BackendId > &availablePreferredBackends, std::string &reasonIfUnsupported, Optional< std::vector< std::string > &> errMessages)
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
void SetTensorInfo(const TensorInfo &tensorInfo) override
A MeanDescriptor for the MeanLayer.
This layer represents a division operation.
Status SerializeToDot(std::ostream &stream) const
IConnectableLayer * AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr)
IConnectableLayer * AddQuantizedLstmLayer(const QuantizedLstmInputParams ¶ms, const char *name=nullptr)
Add a QuantizedLstm layer to the network.
This layer represents a strided slice operation.
This layer represents a maximum operation.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Infer missing output shapes and validate all output shapes.
OptimizeForType< Layer, ConvertFp32NetworkToFp16Impl > Fp32NetworkToFp16Converter
arm::pipe::ProfilingGuid GetGuid() const
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
IConnectableLayer * AddComparisonLayer(const ComparisonDescriptor &comparisonDescriptor, const char *name=nullptr)
IConnectableLayer * AddPrecompiledLayer(const PreCompiledDescriptor &preCompiledDescriptor, CompiledBlobPtr compiledBlobPtr, const Optional< BackendId > &backend, const char *name=nullptr)
Adds a Precompiled layer to the network.
void ReportWarning(const std::string &warningMessage, Optional< std::vector< std::string > &> warningMessages)
This layer represents a convolution 2d operation.
This layer represents a convolution 3d operation.
This layer converts data type Float32 to BFloat16.
void SetQuantizationOffset(int32_t offset)
IConnectableLayer * AddSwitchLayer(const char *name=nullptr)
Adds a switch layer to the network.
IConnectableLayer * AddDetectionPostProcessLayer(const DetectionPostProcessDescriptor &descriptor, const ConstTensor &anchors, const char *name=nullptr)
Adds a Detection PostProcess layer to the network.
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
Adds a multiplication layer to the network.
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr)
Add a stand-in layer for a type unknown to the Arm NN framework.
This layer represents a mean operation.
IOptimizedNetwork(const IOptimizedNetwork &other, const ModelOptions &modelOptions)
This layer represents a comparison operation.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
IConnectableLayer * AddBatchNormalizationLayer(const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr)
IConnectableLayer * AddReduceLayer(const ReduceDescriptor &reduceDescriptor, const char *name=nullptr)
Adds a reduce layer to the network.
IConnectableLayer * AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor &elementwiseUnaryDescriptor, const char *name=nullptr)
Add an ElementwiseUnary layer to the network.
OptimizeForType< Layer, AddBroadcastReshapeLayerImpl > AddBroadcastReshapeLayer
A PreCompiledDescriptor for the PreCompiledLayer.
IConnectableLayer * AddDequantizeLayer(const char *name=nullptr)
Adds a Dequantize layer to the network.
IConnectableLayer * AddConvolution3dLayer(const Convolution3dDescriptor &convolution3dDescriptor, const char *name=nullptr)
OptimizeForConnection< ConstantLayer, DequantizeLayer, ConvertConstDequantisationLayersToConstLayersImpl > ConvertConstDequantisationLayersToConstLayers
A Pooling2dDescriptor for the Pooling2dLayer.
This layer dequantizes the input tensor.
A NormalizationDescriptor for the NormalizationLayer.
IConnectableLayer * AddPreluLayer(const char *name=nullptr)
Adds a PReLU layer to the network.
OptimizedNetworkImpl(const OptimizedNetworkImpl &other, const ModelOptions &modelOptions)
IConnectableLayer * AddDepthToSpaceLayer(const DepthToSpaceDescriptor &depthToSpaceDescriptor, const char *name=nullptr)
IConnectableLayer * AddMaximumLayer(const char *name=nullptr)
Add a Maximum layer to the network.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
This layer represents a multiplication operation.
std::shared_ptr< ConstTensorHandle > m_Anchors
A unique pointer to store Anchor values.
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
IConnectableLayer * AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr)
A ChannelShuffleDescriptor for the ChannelShuffle operator.
IConnectableLayer * AddLstmLayer(const LstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
IConnectableLayer * AddPadLayer(const PadDescriptor &padDescriptor, const char *name=nullptr)
std::shared_ptr< ConstTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8)...
const TensorInfo & GetTensorInfo() const override
IConnectableLayer * AddLogicalBinaryLayer(const LogicalBinaryDescriptor &descriptor, const char *name=nullptr)
Adds a Logical Binary layer to the network.
EdgeStrategy CalculateEdgeStrategy(BackendsMap &backends, ITensorHandleFactory::FactoryId srcFactoryId, const Layer &layer, const Layer &connectedLayer, TensorHandleFactoryRegistry ®istry, bool importEnabled)
static void Destroy(IOptimizedNetwork *network)
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr)
Adds a concatenation layer to the network.
virtual MemorySourceFlags GetImportFlags() const
ITensorHandleFactory::FactoryId CalculateSlotOption(BackendsMap &backends, OutputSlot &outputSlot, TensorHandleFactoryRegistry ®istry, bool exportEnabled)
OptimizeForType< Layer, ConvertFp32NetworkToBf16Impl > Fp32NetworkToBf16Converter
A SoftmaxDescriptor for the SoftmaxLayer.
const char * GetLayerTypeAsCString(LayerType type)
virtual bool SupportsMapUnmap() const
void AddCompatibilityLayers(std::map< BackendId, std::unique_ptr< class IBackendInternal >> &backends, TensorHandleFactoryRegistry ®istry)
Modifies the graph in-place, removing edges connecting layers using different compute devices...
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store weight values.
OptimizeForConnection< ConstantLayer, ConvertFp32ToBf16Layer, FuseConvertFp32ToBf16IntoConstLayers > FuseConversionLayersIntoConstLayers
bool IsCpuRefUsed() const
static const FactoryId LegacyFactoryId
ITensorHandleFactory::FactoryId CalculateSlotOptionForInput(BackendsMap &backends, OutputSlot &slot, TensorHandleFactoryRegistry ®istry, bool importEnabled)
This layer represents a fill operation.
OptimizeForType< Layer, AddDebugToFileImpl > InsertDebugToFileLayer
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A FillDescriptor for the FillLayer.
This layer represents a DepthToSpace operation.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
IConnectableLayer * AddTransposeLayer(const TransposeDescriptor &transposeDescriptor, const char *name=nullptr)
Adds a transpose layer to the network.
unsigned int GetNumElements() const
virtual size_t GetNumInputs() const
std::map< BackendId, std::unique_ptr< class IBackendInternal > > BackendsMap
This layer represents a resize operation.
A PermuteDescriptor for the PermuteLayer.
IConnectableLayer * AddSliceLayer(const SliceDescriptor &sliceDescriptor, const char *name=nullptr)
IConnectableLayer * AddDepthToSpaceLayer(const DepthToSpaceDescriptor &depthToSpaceDescriptor, const char *name=nullptr)
Adds a depth to space layer to the network.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below...
bool m_ConstantWeights
Enable/disable constant weights and biases.
IConnectableLayer * AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor &desc, const char *name=nullptr)