30 #include <client/include/IProfilingService.hpp>
32 #include <common/include/ProfilingGuid.hpp>
34 #include <fmt/format.h>
62 bool importEnabled,
ModelOptions modelOptions,
bool exportEnabled,
65 importEnabled, modelOptions,
66 exportEnabled, debugToFile))
72 bool importEnabled,
ModelOptions modelOptions,
bool exportEnabled,
73 bool debugToFile,
bool allowExpandedDims)
75 shapeInferenceMethod, importEnabled,
76 modelOptions, exportEnabled,
77 debugToFile, allowExpandedDims))
84 p_OptimizerOptionsImpl->m_ImportEnabled = OptimizerStruct.
m_ImportEnabled;
86 p_OptimizerOptionsImpl->m_ModelOptions = OptimizerStruct.
m_ModelOptions;
88 p_OptimizerOptionsImpl->m_DebugToFile = OptimizerStruct.
m_DebugToFile;
89 p_OptimizerOptionsImpl->m_Debug = OptimizerStruct.
m_Debug;
91 p_OptimizerOptionsImpl->m_ExportEnabled = OptimizerStruct.
m_ExportEnabled;
113 p_OptimizerOptionsImpl->m_ImportEnabled = ImportState;
118 p_OptimizerOptionsImpl->m_ExportEnabled = ExportState;
123 p_OptimizerOptionsImpl->m_ProfilingEnabled = ProfilingState;
128 p_OptimizerOptionsImpl->m_Debug = DebugState;
133 p_OptimizerOptionsImpl->m_DebugToFile = DebugFileState;
138 p_OptimizerOptionsImpl->m_ReduceFp32ToFp16 = ReduceFp32ToFp16State;
143 p_OptimizerOptionsImpl->m_shapeInferenceMethod = ShapeInferenceMethodType;
148 p_OptimizerOptionsImpl->m_AllowExpandedDims = ExpandedDimsAllowed;
153 p_OptimizerOptionsImpl->m_ModelOptions.push_back(NewModelOption);
158 return p_OptimizerOptionsImpl->m_ProfilingEnabled;
163 return p_OptimizerOptionsImpl->m_ImportEnabled;
168 return p_OptimizerOptionsImpl->m_ExportEnabled;
173 return p_OptimizerOptionsImpl->m_ReduceFp32ToFp16;
178 return p_OptimizerOptionsImpl->m_ReduceFp32ToBf16;
183 return p_OptimizerOptionsImpl->m_Debug;
188 return p_OptimizerOptionsImpl->m_DebugToFile;
193 return p_OptimizerOptionsImpl->m_AllowExpandedDims;
198 return p_OptimizerOptionsImpl->m_ModelOptions;
203 return p_OptimizerOptionsImpl->m_shapeInferenceMethod;
208 std::stringstream stream;
209 stream <<
"OptimizerOptions: \n";
210 stream <<
"\tReduceFp32ToFp16: " << p_OptimizerOptionsImpl->m_ReduceFp32ToFp16 <<
"\n";
211 stream <<
"\tReduceFp32ToBf16: " << p_OptimizerOptionsImpl->m_ReduceFp32ToBf16 <<
"\n";
212 stream <<
"\tDebug: " << p_OptimizerOptionsImpl->m_Debug <<
"\n";
213 stream <<
"\tDebug to file: " << p_OptimizerOptionsImpl->m_DebugToFile <<
"\n";
214 stream <<
"\tShapeInferenceMethod: " <<
216 "ValidateOnly" :
"InferAndValidate") <<
"\n";
217 stream <<
"\tImportEnabled: " << p_OptimizerOptionsImpl->m_ImportEnabled <<
"\n";
218 stream <<
"\tExportEnabled: " << p_OptimizerOptionsImpl->m_ExportEnabled <<
"\n";
219 stream <<
"\tProfilingEnabled: " << p_OptimizerOptionsImpl->m_ProfilingEnabled <<
"\n";
220 stream <<
"\tAllowExpandedDims: " << p_OptimizerOptionsImpl->m_AllowExpandedDims <<
"\n";
222 stream <<
"\tModelOptions: \n";
223 for (
auto optionsGroup : p_OptimizerOptionsImpl->m_ModelOptions)
225 for (
size_t i=0; i < optionsGroup.GetOptionCount(); i++)
228 stream <<
"\t\tBackend: " << optionsGroup.GetBackendId() <<
"\n"
229 <<
"\t\t\tOption: " << option.
GetName() <<
"\n"
261 return pNetworkImpl->AddComparisonLayer(comparisonDescriptor, name);
268 return pNetworkImpl->AddConcatLayer(concatDescriptor, name);
275 return pNetworkImpl->AddConvolution2dLayer(convolution2dDescriptor, name);
281 return pNetworkImpl->AddConvolution3dLayer(convolution3dDescriptor, name);
288 return pNetworkImpl->AddDepthToSpaceLayer(depthToSpaceDescriptor, name);
296 return pNetworkImpl->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, name);
311 return pNetworkImpl->AddDetectionPostProcessLayer(descriptor, anchors, name);
317 return pNetworkImpl->AddElementwiseBinaryLayer(elementwiseBinaryDescriptor, name);
323 return pNetworkImpl->AddElementwiseUnaryLayer(elementwiseUnaryDescriptor, name);
329 return pNetworkImpl->AddFillLayer(fillDescriptor, name);
335 return pNetworkImpl->AddFullyConnectedLayer(fullyConnectedDescriptor, name);
341 return pNetworkImpl->AddFusedLayer(fusedDescriptor, name);
347 return pNetworkImpl->AddPermuteLayer(permuteDescriptor, name);
353 return pNetworkImpl->AddBatchToSpaceNdLayer(batchToSpaceNdDescriptor, name);
359 return pNetworkImpl->AddPooling2dLayer(pooling2dDescriptor, name);
365 return pNetworkImpl->AddPooling3dLayer(pooling3dDescriptor, name);
373 return pNetworkImpl->AddPrecompiledLayer(preCompiledDescriptor, std::move(compiledBlobPtr), backend, name);
379 return pNetworkImpl->AddActivationLayer(activationDescriptor, name);
385 return pNetworkImpl->AddNormalizationLayer(normalizationDescriptor, name);
390 return pNetworkImpl->AddSliceLayer(sliceDescriptor, name);
395 return pNetworkImpl->AddSoftmaxLayer(softmaxDescriptor, name);
401 return pNetworkImpl->AddSplitterLayer(splitterDescriptor, name);
430 return pNetworkImpl->AddBatchNormalizationLayer(desc, mean, variance, beta, gamma, name);
441 return pNetworkImpl->AddResizeLayer(resizeDescriptor, name);
447 return pNetworkImpl->AddReduceLayer(reduceDescriptor, name);
453 return pNetworkImpl->AddInstanceNormalizationLayer(desc, name);
459 return pNetworkImpl->AddL2NormalizationLayer(desc, name);
465 return pNetworkImpl->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
477 return pNetworkImpl->AddReshapeLayer(reshapeDescriptor, name);
483 return pNetworkImpl->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
489 return pNetworkImpl->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
505 return pNetworkImpl->AddLstmLayer(descriptor, params, name);
531 return pNetworkImpl->AddMeanLayer(meanDescriptor, name);
548 return pNetworkImpl->AddStridedSliceLayer(stridedSliceDescriptor, name);
584 return pNetworkImpl->AddTransposeConvolution2dLayer(descriptor, weights, biases, name);
590 return pNetworkImpl->AddTransposeLayer(transposeDescriptor, name);
613 return pNetworkImpl->AddQuantizedLstmLayer(params, name);
620 return pNetworkImpl->AddQLstmLayer(descriptor, params, name);
626 return pNetworkImpl->AddLogicalBinaryLayer(descriptor, name);
634 return pNetworkImpl->AddUnidirectionalSequenceLstmLayer(descriptor, params, name);
640 return pNetworkImpl->AddChannelShuffleLayer(descriptor, name);
646 return pNetworkImpl->AddBatchMatMulLayer(descriptor, name);
663 return pNetworkImpl->AddBroadcastToLayer(descriptor, name);
669 return pNetworkImpl->AddScatterNdLayer(descriptor, name);
679 return new INetwork(networkOptions);
693 : pOptimizedNetworkImpl(new
OptimizedNetworkImpl(*other.pOptimizedNetworkImpl.get(), modelOptions)) {}
699 : pOptimizedNetworkImpl(
std::move(impl)) {}
749 return m_Graph->SerializeToDot(stream);
754 return m_Graph->GetNumInputs();
759 return m_Graph->GetNumOutputs();
763 Optional<std::vector<std::string>&> errorMessages)
765 std::stringstream fullErrorMessage;
766 fullErrorMessage <<
"ERROR: " << errorMessage;
770 errorMessages.value().push_back(fullErrorMessage.str());
775 Optional<std::vector<std::string>&> warningMessages)
777 std::stringstream fullWarningMessage;
778 fullWarningMessage <<
"WARNING: " << warningMessage;
782 warningMessages.value().push_back(fullWarningMessage.str());
790 Optional<std::vector<std::string>&> errMessages)
792 std::stringstream failureMsg;
803 bool noErrors =
true;
805 for (
unsigned int i = 0; i < numOutputs; i++) {
808 auto quantizationDataType =
info.GetDataType();
809 auto quantizationScales =
info.GetQuantizationScales();
811 switch(quantizationDataType) {
817 &&
info.HasPerAxisQuantization()) {
819 "Asymmetric Quantization Datatype.");
823 (
info.GetQuantizationScale() != (1.0f / 256.0f) ||
824 info.GetQuantizationOffset() != 0) &&
826 std::stringstream ss;
827 ss <<
"Quantization parameters for Softmax layer (Scale: " <<
828 info.GetQuantizationScale() <<
" and Offset: " <<
info.GetQuantizationOffset() <<
829 ") are incorrect and have been updated to Scale: 0.00390625 and Offset: 0";
831 info.SetQuantizationScale((1.0f / 256.0f));
832 info.SetQuantizationOffset(0);
850 const std::vector<BackendId>& availablePreferredBackends,
851 std::string& reasonIfUnsupported,
852 Optional<std::vector<std::string>&> messages)
857 auto ReturnError = [&](
const Layer* layer)
865 std::string currentReasonIfUnsupported;
871 reasonIfUnsupported += currentReasonIfUnsupported;
872 if (!isLayerSupported &&
HasCapability(
"AllOrNothing", backend))
875 if (
GetCapability(
"AllOrNothing", backend).value().GetValue().AsBool())
879 std::stringstream fullWarningMessage;
880 fullWarningMessage <<
"Backend: " << backend
881 <<
" has \"AllOrNothing\" enabled. A layer of type "
883 <<
"This backend will not be considered to execute this subgraph.";
884 reasonIfUnsupported.append(fullWarningMessage.str());
894 std::string checkStr =
"This CPU architecture does not support F16 data type, you need v8.2 or above";
895 if (!isLayerSupported || currentReasonIfUnsupported.find(checkStr) != std::string::npos)
903 auto ConstantLayerFromFp16ToFp32 = [](
Layer& layer)
907 ConstantLayer* constantLayer = PolymorphicDowncast<ConstantLayer*>(&layer);
913 std::vector<float> newValues(
info.GetNumElements());
917 info.GetNumElements(),
930 bool checkType =
false;
934 auto connectedOutputSlot = inputSlot.GetConnectedOutputSlot();
937 if (connectedOutputSlot->GetNumConnections() == 1)
940 ConstantLayerFromFp16ToFp32(connectedOutputSlot->GetOwningLayer());
946 std::vector<ConvertFp16ToFp32Layer*> convertFp16ToFp32Layers;
949 convertFp16ToFp32Layers =
954 std::vector<ConvertFp32ToFp16Layer*> convertFp32ToFp16Layers;
957 convertFp32ToFp16Layers =
962 auto AssignFirstSupportedBackend = [&](
Layer* layer,
BackendId preferredBackend)
964 bool supportedBackendFound =
false;
965 std::string reasonIfUnsupported;
971 reasonIfUnsupported))
973 supportedBackendFound =
true;
977 for (
const auto& backend : availablePreferredBackends)
980 if (backend == preferredBackend)
988 reasonIfUnsupported))
990 supportedBackendFound =
true;
996 return supportedBackendFound;
1001 if (!AssignFirstSupportedBackend(convertLayer, backend))
1003 return ReturnError(convertLayer);
1009 if (!AssignFirstSupportedBackend(convertLayer, backend))
1011 return ReturnError(convertLayer);
1019 std::stringstream warningMsg;
1021 <<
" is not supported on requested backend " << layer->
GetBackendId().
Get()
1024 <<
" (reason: " << reasonIfUnsupported
1025 <<
"), falling back to the next backend.";
1042 return {dataTypeIn, dataTypeOut};
1046 const std::vector<BackendId>& availablePreferredBackends)
1048 bool hasFp16 =
false;
1050 auto firstBackend = availablePreferredBackends[0];
1051 auto backendObjPtr = backends.find(firstBackend)->second.get();
1054 auto backendCapabilities = backendObjPtr->GetCapabilities();
1060 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1061 <<
", has FP16 support.";
1065 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1066 <<
", does not have FP16 support. "
1067 <<
"The FP16 turbo mode option will be disable. It will run using FP32.";
1071 for (
size_t i = 1; i < availablePreferredBackends.size(); ++i)
1073 auto backend = availablePreferredBackends[i];
1074 backendObjPtr = backends.find(backend)->second.get();
1075 backendCapabilities = backendObjPtr->GetCapabilities();
1078 ARMNN_LOG(
debug) <<
"Next preferred backend: " << backend <<
", does not have FP16 support. "
1079 <<
"It will run using FP32 when falling back to this backend.";
1083 ARMNN_LOG(
debug) <<
"Next preferred backend: " << backend <<
", has FP16 support.";
1094 Optional<std::vector<std::string>&> errMessages,
1097 std::vector<BackendId>& availablePreferredBackends,
1100 auto ReturnError = [&](
const Layer* layer)
1105 auto layer = PolymorphicDowncast<Layer*>(it);
1114 std::string reasonIfUnsupported;
1124 if (layer->GetBackendHint().has_value() &&
1129 layer->GetBackendHint().value(),
1132 availablePreferredBackends,
1133 reasonIfUnsupported,
1134 errMessages).
IsOk())
1142 for (
const auto& backend : availablePreferredBackends)
1144 if (layer->GetBackendHint().has_value() &&
1145 layer->GetBackendHint().value() == backend)
1156 availablePreferredBackends,
1157 reasonIfUnsupported,
1175 if (reasonIfUnsupported.find(
"AllOrNothing") != std::string::npos)
1200 layer->SetBackendId(cpuBackendId);
1205 result = ReturnError(layer);
1215 Optional<std::vector<std::string>&> errMessages)
1220 bool restart =
false;
1222 for (
auto it = firstLayer; it != lastLayer; it = (restart ? firstLayer : ++it))
1224 if (it == firstLayer)
1227 if (availablePreferredBackends.empty())
1229 ReportError(
"No preferred backends are available", errMessages);
1244 availablePreferredBackends,
1248 for (
auto it = firstLayer; it != lastLayer; ++it)
1250 auto layer = PolymorphicDowncast<Layer*>(*it);
1258 bool isFloat16 =
false;
1259 for (
auto type : inOutDataType)
1268 if (layer->GetBackendId() ==
"Unknown" || isFloat16)
1275 availablePreferredBackends,
1280 for (
auto it = firstLayer; it != lastLayer; ++it)
1282 auto layer = PolymorphicDowncast<Layer*>(*it);
1286 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1287 layer->SetBackendId(connectedBackendId);
1298 Optional<std::vector<std::string>&> errMessages)
1304 if (availablePreferredBackends.empty())
1306 std::stringstream failureMsg;
1307 failureMsg <<
"No preferred backends are available";
1314 bool restart =
false;
1315 for (
auto it = firstLayer; it != lastLayer; ++it)
1322 availablePreferredBackends,
1326 for (
auto it = firstLayer; it != lastLayer; ++it)
1328 auto layer = PolymorphicDowncast<Layer*>(*it);
1332 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1333 layer->SetBackendId(connectedBackendId);
1343 Optional<std::vector<std::string>&> errMessages)
1361 auto backendFactory = backendRegistry.GetFactory(selectedBackend);
1362 auto backendObjPtr = backendFactory();
1364 backendObjPtr->RegisterTensorHandleFactories(handleFactoryRegistry);
1366 backends[backendObjPtr->GetId()] = std::move(backendObjPtr);
1376 Optional<std::vector<std::string>&> errMessages)
1387 auto backendObjPtr = backends.find(selectedBackend)->second.get();
1403 [&backendObjPtr](
const Layer& layer)
1410 if (subgraphs.empty())
1417 for (
auto& subgraph : subgraphs)
1421 OptimizationViews optimizationViews = backendObjPtr->OptimizeSubgraphView(*subgraph, modelOptions);
1422 if (!optimizationViews.
Validate(*subgraph))
1431 SubgraphView& replacementSubgraph = substitution.m_ReplacementSubgraph;
1432 SubgraphView& substitutableSubgraph = substitution.m_SubstitutableSubgraph;
1437 std::for_each(subgraphLayers.begin(), subgraphLayers.end(), [&selectedBackend](
IConnectableLayer* l)
1439 PolymorphicDowncast<Layer*>(l)->SetBackendId(selectedBackend);
1446 for (
auto& l : deletedSubgraph.GetIConnectableLayers())
1448 Layer* deletedLayer = PolymorphicDowncast<Layer*>(l);
1452 OutputSlot* parentOut = inputSlot.GetConnectedOutputSlot();
1467 std::stringstream warningMsg;
1468 warningMsg <<
"Some sub-graph(s) failed to optimized on " << backendObjPtr->GetId() <<
" backend.";
1473 if (!backendObjPtr->GetId().IsCpuRef())
1483 std::stringstream subgraphMsg;
1484 subgraphMsg <<
"Re-assigning backends to " << failedSubgraph.GetIConnectableLayers().size()
1485 <<
" layers inside sub-graph " << count++;
1492 if (reassignmentResult.
m_Error)
1515 if (srcFactory && dstFactory &&
1545 if (frmBackend == backends.end() ||
1546 !frmBackend->second->SupportsTensorAllocatorAPI())
1553 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1560 const Layer& connectedLayer = connection->GetOwningLayer();
1562 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1563 if (toBackend == backends.end())
1568 if (!toBackend->second.get()->SupportsTensorAllocatorAPI())
1574 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1575 for (
auto&& dst : dstPrefs)
1589 auto it = factoryScores.find(dst);
1590 if (it == factoryScores.end())
1593 factoryScores[dst] = 0;
1602 factoryScores[dst]++;
1605 if (factoryScores[dst] > topScore)
1607 topScore = factoryScores[dst];
1636 if (frmBackend == backends.end() ||
1637 !frmBackend->second->SupportsTensorAllocatorAPI())
1642 bool outputConnection =
false;
1645 const Layer& connectedLayer = connection->GetOwningLayer();
1648 outputConnection =
true;
1656 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1657 for (
auto&& pref : srcPrefs)
1662 if (outputConnection)
1665 bool fallbackConnection =
false;
1668 if (inputSlot.GetConnectedOutputSlot()->GetOwningLayer().GetBackendId() != layer.
GetBackendId())
1670 fallbackConnection =
true;
1673 if (fallbackConnection)
1677 if (!factoryCap.empty())
1687 if (!outputConnection)
1691 if (!factoryCap.empty())
1710 auto it = factoryScores.find(pref);
1711 if (it == factoryScores.end())
1714 factoryScores[pref] = 0;
1721 const Layer& connectedLayer = connection->GetOwningLayer();
1723 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1724 if (toBackend == backends.end())
1729 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1730 for (
auto&& src : srcPrefs)
1732 if (factoryScores.find(src) == factoryScores.end())
1737 for (
auto&& dst : dstPrefs)
1742 factoryScores[src]++;
1750 int minScore = std::numeric_limits<int>::max();
1751 for (
auto it : factoryScores)
1753 minScore = std::min(minScore, it.second);
1757 std::vector<ITensorHandleFactory::FactoryId> optimalFactories;
1758 for (
auto it : factoryScores)
1760 if (it.second == minScore)
1762 optimalFactories.push_back(it.first);
1767 for (
auto&& srcPref : srcPrefs)
1769 for (
auto&& comp : optimalFactories)
1771 if (comp == srcPref)
1784 const Layer& connectedLayer,
1788 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1789 if (toBackend == backends.end())
1794 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1817 for (
auto&& pref : dstPrefs)
1819 if (pref == srcFactoryId)
1829 for (
auto&& pref : dstPrefs)
1848 if (srcCapability.empty() && dstCapability.empty() && srcFallback.empty() && dstFallback.empty())
1859 for (
auto&& pref : dstPrefs)
1878 Optional<std::vector<std::string>&> errMessages)
1883 optGraph.
ForEachLayer([&backends, ®istry, &result, &errMessages, importEnabled, exportEnabled](
Layer* layer)
1887 if (backends.find(layer->
GetBackendId()) == backends.end())
1889 throw armnn::Exception(
"Backend id not found for the layer");
1902 case LayerType::Input:
1903 slotOption = CalculateSlotOptionForInput(backends, outputSlot, registry, importEnabled);
1905 case LayerType::Output:
1906 slotOption = CalculateSlotOptionForOutput(backends, outputSlot, registry);
1909 slotOption = CalculateSlotOption(backends, outputSlot, registry, exportEnabled);
1915 unsigned int connectionIdx = 0;
1918 const Layer& connectedLayer = connection->GetOwningLayer();
1920 EdgeStrategy strategy = CalculateEdgeStrategy(backends, slotOption, *layer, connectedLayer,
1921 registry, importEnabled);
1923 if (strategy == EdgeStrategy::Undefined)
1925 result.m_Error = true;
1928 errMessages.value().emplace_back(
"Could not find valid strategy required for compatibility"
1929 " between backends.");
1947 bool hasFastMath =
false;
1949 auto firstBackend = availablePreferredBackends[0];
1950 if (!modelOptions.empty())
1954 if (name ==
"FastMathEnabled")
1956 hasFastMath = value.
AsBool();
1957 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1958 <<
", has FastMath support.";
1964 ARMNN_LOG(
warning) <<
"The first available preferred backend: " << firstBackend
1965 <<
", does not have FastMath support. "
1966 <<
"Support for Turbo mode for TfLite post quantized FP16 models wil be disabled.";
1979 bool atLeastOneDequantizeEncountered =
false;
1980 for (
auto it = firstLayer; it != lastLayer; ++it)
1983 if (layer->GetType() == LayerType::Constant)
1985 auto& connectedLayer = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer();
1988 if(!(connectedLayer.GetInputSlot(0).GetTensorInfo().GetDataType() == DataType::Float16 &&
1989 connectedLayer.GetOutputSlot(0).GetTensorInfo().GetDataType() == DataType::Float32))
1995 atLeastOneDequantizeEncountered =
true;
2000 if (!atLeastOneDequantizeEncountered)
2010 const std::vector<BackendId>& backendPreferences,
2013 Optional<std::vector<std::string>&> messages)
2023 const std::vector<BackendId>& backendPreferences,
2026 Optional<std::vector<std::string>&> messages)
2032 ProfilerManager::GetInstance().RegisterProfiler(profiler.get());
2036 if (backendPreferences.empty())
2044 "Please use the FastMathEnabled backend option for CpuAcc or GpuAcc.");
2055 std::unique_ptr<Graph> graph = std::make_unique<Graph>(inGraph);
2063 optimizedOptions.push_back(importExport);
2066 &IOptimizedNetwork::Destroy);
2079 using namespace optimizations;
2098 if (availablePreferredBackends.empty())
2100 std::stringstream failureMsg;
2101 failureMsg <<
"None of the preferred backends " << backendPreferences
2118 reduceFp32ToFp16 =
true;
2155 for (
auto backend : mappedGpuBackends)
2157 if (std::count(backendPreferences.begin(), backendPreferences.end(), backend)
2158 && (backendPreferences[0] != backend) &&
2161 std::stringstream failureMsg;
2162 failureMsg << backend <<
" backend cannot be specified as fallback.";
2168 std::vector<BackendId> amendedBackendPreferences = backendPreferences;
2173 for (
auto backend : mappedGpuBackends)
2175 if (!std::count(amendedBackendPreferences.begin(), amendedBackendPreferences.end(), backend))
2177 amendedBackendPreferences.insert(amendedBackendPreferences.begin(), backend);
2182 if (reduceFp32ToFp16 && hasFp16)
2196 if (assignBackendsResult.
m_Error)
2211 if (backendOptimizationResult.
m_Error)
2236 #if !defined(ARMNN_DISABLE_FILESYSTEM)
2238 ARMNN_LOG(
info) <<
"Intermediate tensors will be written to: " << result;
2252 tensorHandleFactoryRegistry,
2274 const std::vector<BackendId>& backendPreferences,
2277 Optional<std::vector<std::string>&> messages)
2287 const std::vector<BackendId>& backendPreferences,
2290 Optional<std::vector<std::string>&> messages)
2299 bool NetworkImpl::GetShapeInferenceMethod()
2301 bool shapeInferenceMethod =
false;
2305 if (name ==
"InferAndValidate")
2307 shapeInferenceMethod |= value.
AsBool();
2310 return shapeInferenceMethod;
2313 bool NetworkImpl::GetAllowExpandedDims()
2315 bool allowExpandedDims =
false;
2317 ParseOptions(m_NetworkOptions,
"AllowExpandedDims", [&](std::string name,
const BackendOptions::Var& value)
2319 if (name ==
"AllowExpandedDims")
2321 allowExpandedDims |= value.AsBool();
2324 return allowExpandedDims;
2328 : m_NetworkOptions(networkOptions),
2329 m_Graph(
std::make_unique<
Graph>(GetShapeInferenceMethod(), GetAllowExpandedDims()))
2344 return m_Graph->AddLayer<
InputLayer>(id, name);
2355 return m_Graph->AddLayer<
CastLayer>(name);
2366 return m_Graph->AddLayer<
ComparisonLayer>(comparisonDescriptor, name);
2384 return m_Graph->AddLayer<
FillLayer>(fillDescriptor, name);
2396 return m_Graph->AddLayer<
FusedLayer>(fusedDescriptor, name);
2402 return m_Graph->AddLayer<
ConcatLayer>(concatDescriptor, name);
2445 layer->
m_Anchors = std::make_shared<ScopedTensorHandle>(anchors);
2453 return m_Graph->AddLayer<
PermuteLayer>(permuteDescriptor, name);
2459 return m_Graph->AddLayer<
Pooling2dLayer>(pooling2dDescriptor, name);
2465 return m_Graph->AddLayer<
Pooling3dLayer>(pooling3dDescriptor, name);
2471 return m_Graph->AddLayer<
ActivationLayer>(activationDescriptor, name);
2477 return m_Graph->AddLayer<
ArgMinMaxLayer>(argMinMaxDescriptor, name);
2481 normalizationDescriptor,
2489 return m_Graph->AddLayer<
SliceLayer>(sliceDescriptor, name);
2495 return m_Graph->AddLayer<
SoftmaxLayer>(softmaxDescriptor, name);
2501 return m_Graph->AddLayer<
SplitterLayer>(splitterDescriptor, name);
2538 layer->
m_Mean = std::make_shared<ScopedTensorHandle>(mean);
2539 layer->m_Variance = std::make_shared<ScopedTensorHandle>(variance);
2540 layer->m_Beta = std::make_shared<ScopedTensorHandle>(beta);
2541 layer->m_Gamma = std::make_shared<ScopedTensorHandle>(gamma);
2548 return m_Graph->AddLayer<
RankLayer>(name);
2554 return m_Graph->AddLayer<
ReduceLayer>(reduceDescriptor, name);
2559 return m_Graph->AddLayer<
ResizeLayer>(resizeDescriptor, name);
2589 layer->
m_LayerOutput = std::make_shared<ScopedTensorHandle>(input);
2597 return m_Graph->AddLayer<
ReshapeLayer>(reshapeDescriptor, name);
2621 const auto layer = m_Graph->AddLayer<
LstmLayer>(descriptor, name);
2626 layer->m_BasicParameters.m_InputToCellWeights =
2628 layer->m_BasicParameters.m_InputToOutputWeights =
2630 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2632 layer->m_BasicParameters.m_RecurrentToCellWeights =
2634 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2636 layer->m_BasicParameters.m_ForgetGateBias =
2638 layer->m_BasicParameters.m_CellBias =
2639 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2640 layer->m_BasicParameters.m_OutputGateBias =
2649 "when CIFG is disabled.");
2654 "AddLstmLayer: Recurrent To Input Weights cannot be NULL "
2655 "when CIFG is disabled.");
2660 "when CIFG is disabled.");
2662 layer->m_CifgParameters.m_InputToInputWeights =
2664 layer->m_CifgParameters.m_RecurrentToInputWeights =
2666 layer->m_CifgParameters.m_InputGateBias =
2676 "when projection is enabled.");
2678 layer->m_ProjectionParameters.m_ProjectionWeights =
2682 layer->m_ProjectionParameters.m_ProjectionBias =
2695 "when Peephole is enabled and CIFG disabled.");
2698 layer->m_PeepholeParameters.m_CellToInputWeights =
2705 "when Peephole is enabled.");
2710 "when Peephole is enabled.");
2713 layer->m_PeepholeParameters.m_CellToForgetWeights =
2715 layer->m_PeepholeParameters.m_CellToOutputWeights =
2727 "when layer normalization is enabled and CIFG disabled.");
2729 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2736 "when layer normalization is enabled.");
2741 "when layer normalization is enabled.");
2746 "when layer normalization is enabled.");
2748 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2750 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2752 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
2770 return m_Graph->AddLayer<
MeanLayer>(meanDescriptor,name);
2775 return m_Graph->AddLayer<
PadLayer>(padDescriptor,name);
2797 return m_Graph->AddLayer<
GatherLayer>(gatherDescriptor, name);
2832 layer->
m_Weight = std::make_shared<ScopedTensorHandle>(weights);
2836 layer->m_Bias = std::make_shared<ScopedTensorHandle>(biases.
value());
2845 return m_Graph->AddLayer<
TransposeLayer>(transposeDescriptor, name);
2851 return m_Graph->AddLayer<
StackLayer>(stackDescriptor, name);
2869 layer->m_QuantizedLstmParameters.m_InputToForgetWeights =
2871 layer->m_QuantizedLstmParameters.m_InputToCellWeights =
2873 layer->m_QuantizedLstmParameters.m_InputToOutputWeights =
2877 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights =
2879 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights =
2881 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights =
2883 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights =
2887 layer->m_QuantizedLstmParameters.m_InputGateBias =
2889 layer->m_QuantizedLstmParameters.m_ForgetGateBias =
2891 layer->m_QuantizedLstmParameters.m_CellBias =
2892 std::make_shared<ScopedTensorHandle>(params.
GetCellBias());
2893 layer->m_QuantizedLstmParameters.m_OutputGateBias =
2903 const auto layer = m_Graph->AddLayer<
QLstmLayer>(descriptor, name);
2908 layer->m_BasicParameters.m_InputToCellWeights =
2910 layer->m_BasicParameters.m_InputToOutputWeights =
2912 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2914 layer->m_BasicParameters.m_RecurrentToCellWeights =
2916 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2918 layer->m_BasicParameters.m_ForgetGateBias =
2920 layer->m_BasicParameters.m_CellBias =
2921 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2922 layer->m_BasicParameters.m_OutputGateBias =
2936 "AddQLstmLayer: Recurrent To Input Weights cannot be NULL");
2944 layer->m_CifgParameters.m_InputToInputWeights =
2946 layer->m_CifgParameters.m_RecurrentToInputWeights =
2948 layer->m_CifgParameters.m_InputGateBias =
2960 layer->m_ProjectionParameters.m_ProjectionWeights =
2966 layer->m_ProjectionParameters.m_ProjectionBias =
2992 layer->m_PeepholeParameters.m_CellToInputWeights =
2996 layer->m_PeepholeParameters.m_CellToForgetWeights =
2998 layer->m_PeepholeParameters.m_CellToOutputWeights =
3027 layer->m_LayerNormParameters.m_InputLayerNormWeights =
3031 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
3033 layer->m_LayerNormParameters.m_CellLayerNormWeights =
3035 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
3057 layer->m_BasicParameters.m_InputToCellWeights =
3059 layer->m_BasicParameters.m_InputToOutputWeights =
3061 layer->m_BasicParameters.m_RecurrentToForgetWeights =
3063 layer->m_BasicParameters.m_RecurrentToCellWeights =
3065 layer->m_BasicParameters.m_RecurrentToOutputWeights =
3067 layer->m_BasicParameters.m_ForgetGateBias =
3069 layer->m_BasicParameters.m_CellBias =
3070 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
3071 layer->m_BasicParameters.m_OutputGateBias =
3080 "when CIFG is disabled.");
3085 "AddUnidirectionalSequenceLstmLayer: Recurrent To Input Weights cannot be NULL "
3086 "when CIFG is disabled.");
3091 "when CIFG is disabled.");
3093 layer->m_CifgParameters.m_InputToInputWeights =
3095 layer->m_CifgParameters.m_RecurrentToInputWeights =
3097 layer->m_CifgParameters.m_InputGateBias =
3107 "when projection is enabled.");
3109 layer->m_ProjectionParameters.m_ProjectionWeights =
3113 layer->m_ProjectionParameters.m_ProjectionBias =
3126 "cannot be NULL when Peephole is enabled and CIFG disabled.");
3129 layer->m_PeepholeParameters.m_CellToInputWeights =
3136 "when Peephole is enabled.");
3141 "when Peephole is enabled.");
3144 layer->m_PeepholeParameters.m_CellToForgetWeights =
3146 layer->m_PeepholeParameters.m_CellToOutputWeights =
3158 "cannot be NULL when layer normalization is enabled and CIFG disabled.");
3160 layer->m_LayerNormParameters.m_InputLayerNormWeights =
3167 "cannot be NULL when layer normalization is enabled.");
3172 "cannot be NULL when layer normalization is enabled.");
3177 "cannot be NULL when layer normalization is enabled.");
3179 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
3181 layer->m_LayerNormParameters.m_CellLayerNormWeights =
3183 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
3201 return m_Graph->AddLayer<
TileLayer>(desc, name);
3217 layer = m_Graph->AddLayer<
PreCompiledLayer>(preCompiledDescriptor,
"pre-compiled");
3251 layer->ExecuteStrategy(strategy);
3256 : m_Graph(new
Graph(*other.m_Graph.get()))
3257 , m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
3258 , m_ModelOptions(modelOptions)
3263 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
3268 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid()), m_ModelOptions(modelOptions)
3285 layer->ExecuteStrategy(strategy);
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
#define ARMNN_NO_DEPRECATE_WARN_END
#define ARMNN_LOG(severity)
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
This layer represents an activation operation with the specified activation function.
This layer represents an addition operation.
This layer represents a ArgMinMax operation.
const std::string & Get() const
Very basic type safe variant.
bool AsBool() const
Value getters.
BackendIdSet GetBackendIds() const
BackendIdVector GetMappedGpuBackends()
This layer represents a batch normalization operation.
std::shared_ptr< ConstTensorHandle > m_Mean
A unique pointer to store Mean values.
This layer represents a BatchToSpaceNd operation.
This layer represents a cast operation.
This layer represents a comparison operation.
This layer represents a merge operation.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
A layer that the constant data can be bound to.
std::shared_ptr< ConstTensorHandle > m_LayerOutput
This layer converts data type Float 16 to Float 32.
This layer converts data type Float 32 to Float 16.
This layer represents a convolution 2d operation.
This layer represents a convolution 3d operation.
This layer represents a DepthToSpace operation.
This layer represents a depthwise convolution 2d operation.
This layer dequantizes the input tensor.
This layer represents a detection postprocess operator.
std::shared_ptr< ConstTensorHandle > m_Anchors
A unique pointer to store Anchor values.
This layer represents a division operation.
This layer represents a elementwiseBinary operation.
This layer represents a elementwiseUnary operation.
Base class for all ArmNN exceptions so that users can filter to just those.
virtual const char * what() const noexcept override
This layer represents a fill operation.
This layer represents a floor operation.
This layer represents a fully connected operation.
This layer represents a Gather operator.
This layer represents a GatherNd operator.
Iterator begin()
Returns iterator pointing to the beginning of the list. Lowercase for range-based for loops.
void VerifyConstantLayerSetTensorInfo() const
For each ConstantLayer in Graph, ensures TensorInfo is set on all output slots.
const std::shared_ptr< IProfiler > & GetProfiler() const
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
void SubstituteSubgraph(SubgraphView &subgraph, IConnectableLayer *substituteLayer)
Substitutes the given sub-graph with either a new layer or a new sub-graph.
Iterator end()
Returns iterator pointing to the end of the list. Lowercase for range-based for loops.
LayerList::const_iterator Iterator
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,...
void ForEachLayer(Func func) const
virtual std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Device specific knowledge to be passed to the optimizer.
Main network class which provides the interface for building up a neural network.
IConnectableLayer * AddFusedLayer(const FusedDescriptor &fusedDescriptor, const char *name=nullptr)
Adds a Fused layer to the network.
IConnectableLayer * AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor &elementwiseUnaryDescriptor, const char *name=nullptr)
Add an ElementwiseUnary layer to the network.
IConnectableLayer * AddLstmLayer(const LstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
Add a Lstm layer to the network.
IConnectableLayer * AddDivisionLayer(const char *name=nullptr)
Adds a division layer to the network.
IConnectableLayer * AddQuantizeLayer(const char *name=nullptr)
Add a quantize layer to the network.
IConnectableLayer * AddMergeLayer(const char *name=nullptr)
Adds a merge layer to the network.
IConnectableLayer * AddPermuteLayer(const PermuteDescriptor &permuteDescriptor, const char *name=nullptr)
Adds a permute layer to the network.
IConnectableLayer * AddSpaceToDepthLayer(const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr)
Adds a space to depth layer to the network.
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 * AddGatherLayer(const GatherDescriptor &descriptor, const char *name=nullptr)
Add Gather layer to the network.
IConnectableLayer * AddRankLayer(const char *name=nullptr)
Adds a rank layer to the network.
IConnectableLayer * AddSwitchLayer(const char *name=nullptr)
Adds a switch layer to the network.
IConnectableLayer * AddQLstmLayer(const QLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
Add a QLstm layer to the network.
INetwork(NetworkOptions networkOptions={})
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
Adds a softmax layer to the network.
IConnectableLayer * AddDequantizeLayer(const char *name=nullptr)
Adds a Dequantize layer to the network.
IConnectableLayer * AddBroadcastToLayer(const BroadcastToDescriptor &descriptor, const char *name=nullptr)
Add a BroadcastTo layer to the network.
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D convolution layer to the network.
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
Adds an addition layer to the network.
IConnectableLayer * AddQuantizedLstmLayer(const QuantizedLstmInputParams ¶ms, const char *name=nullptr)
Add a QuantizedLstm layer to the network.
static INetworkPtr Create(const NetworkOptions &networkOptions={})
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.
std::unique_ptr< NetworkImpl > pNetworkImpl
IConnectableLayer * AddFloorLayer(const char *name=nullptr)
Adds a floor layer to the network.
IConnectableLayer * AddConvolution3dLayer(const Convolution3dDescriptor &convolution3dDescriptor, const char *name=nullptr)
Adds a 3D convolution layer to the network.
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const char *name=nullptr)
Adds a fully connected layer to the network.
IConnectableLayer * AddMinimumLayer(const char *name=nullptr)
Add a Minimum layer to the network.
IConnectableLayer * AddStackLayer(const StackDescriptor &descriptor, const char *name=nullptr)
Adds a stack layer to the network.
static void Destroy(INetwork *network)
IConnectableLayer * AddMaximumLayer(const char *name=nullptr)
Add a Maximum layer to the network.
IConnectableLayer * AddNormalizationLayer(const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr)
Adds a normalization layer to the network.
IConnectableLayer * AddPreluLayer(const char *name=nullptr)
Adds a PReLU layer to the network.
IConnectableLayer * AddPadLayer(const PadDescriptor &padDescriptor, const char *name=nullptr)
Adds a fully pad layer to the network.
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
Adds a splitter layer to the network.
void ExecuteStrategy(IStrategy &strategy) const
IConnectableLayer * AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr)
Adds a space to batch layer to the network.
IConnectableLayer * AddCastLayer(const char *name=nullptr)
Adds a cast 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.
IConnectableLayer * AddChannelShuffleLayer(const ChannelShuffleDescriptor &descriptor, const char *name=nullptr)
Add a ChannelShuffle layer to the network.
IConnectableLayer * AddLogicalBinaryLayer(const LogicalBinaryDescriptor &descriptor, const char *name=nullptr)
Adds a Logical Binary layer to the network.
IConnectableLayer * AddLogSoftmaxLayer(const LogSoftmaxDescriptor &logSoftmaxDescriptor, const char *name=nullptr)
Adds a log softmax layer to the network.
IConnectableLayer * AddReshapeLayer(const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr)
Adds a reshape layer to the network.
IConnectableLayer * AddSliceLayer(const SliceDescriptor &sliceDescriptor, const char *name=nullptr)
Adds a slice layer to the network.
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.
IConnectableLayer * AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr)
Adds a batch to space ND layer to the network.
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)
Adds an activation layer to the network.
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Adds an input layer to the network.
IConnectableLayer * AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor &elementwiseBinaryDescriptor, const char *name=nullptr)
Add an ElementwiseBinary layer to the network.
IConnectableLayer * AddL2NormalizationLayer(const L2NormalizationDescriptor &desc, const char *name=nullptr)
Adds an L2 normalization layer to the network.
IConnectableLayer * AddTransposeLayer(const TransposeDescriptor &transposeDescriptor, const char *name=nullptr)
Adds a transpose layer to the network.
static INetwork * CreateRaw(const NetworkOptions &networkOptions={})
IConnectableLayer * AddUnidirectionalSequenceLstmLayer(const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
Add a UnidirectionalSequenceLstm layer to the network.
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
Adds a multiplication layer to the network.
IConnectableLayer * AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor &desc, const char *name=nullptr)
Adds an instance normalization 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 * AddStridedSliceLayer(const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr)
Adds a strided slice layer to the network.
IConnectableLayer * AddTileLayer(const TileDescriptor &descriptor, const char *name=nullptr)
Add a Tile layer to the network.
IConnectableLayer * AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D depthwise convolution layer to the network.
IConnectableLayer * AddComparisonLayer(const ComparisonDescriptor &comparisonDescriptor, const char *name=nullptr)
Add a Comparison layer to the network.
IConnectableLayer * AddMeanLayer(const MeanDescriptor &meanDescriptor, const char *name=nullptr)
Add a Mean layer to the network.
IConnectableLayer * AddResizeLayer(const ResizeDescriptor &resizeDescriptor, const char *name=nullptr)
Adds a resize layer to the network.
IConnectableLayer * AddArgMinMaxLayer(const ArgMinMaxDescriptor &desc, const char *name=nullptr)
Adds an ArgMinMax layer to the network.
IConnectableLayer * AddReduceLayer(const ReduceDescriptor &reduceDescriptor, const char *name=nullptr)
Adds a reduce layer to the network.
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)
Adds a 2D pooling layer to the network.
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr)
Adds a concatenation layer to the network.
IConnectableLayer * AddBatchMatMulLayer(const BatchMatMulDescriptor &descriptor, const char *name=nullptr)
Add a BatchMatMul layer to the network.
IConnectableLayer * AddPooling3dLayer(const Pooling3dDescriptor &pooling3dDescriptor, const char *name=nullptr)
Adds a 3D pooling layer to the network.
IConnectableLayer * AddPrecompiledLayer(const PreCompiledDescriptor &preCompiledDescriptor, CompiledBlobPtr compiledBlobPtr, const Optional< BackendId > &backend, const char *name=nullptr)
Adds a Precompiled layer to the network.
IConnectableLayer * AddSubtractionLayer(const char *name=nullptr)
Adds a subtraction layer to the network.
IConnectableLayer * AddDepthToSpaceLayer(const DepthToSpaceDescriptor &depthToSpaceDescriptor, const char *name=nullptr)
Adds a depth to space layer to the network.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Adds an output layer to the network.
IConnectableLayer * AddReverseV2Layer(const char *name=nullptr)
Add a ReverseV2 layer to the network.
IConnectableLayer * AddGatherNdLayer(const char *name=nullptr)
Add GatherNd layer to the network.
IConnectableLayer * AddShapeLayer(const char *name=nullptr)
Adds a shape layer to the network.
IConnectableLayer * AddFillLayer(const FillDescriptor &fillDescriptor, const char *name=nullptr)
Add an Fill layer to the network.
IConnectableLayer * AddScatterNdLayer(const ScatterNdDescriptor &descriptor, const char *name=nullptr)
Add a ScatterNd layer to the network.
Status SerializeToDot(std::ostream &stream) const
IOptimizedNetwork(const IOptimizedNetwork &other, const ModelOptions &modelOptions)
Creates a copy of the IOptimizedNetwork.
std::unique_ptr< OptimizedNetworkImpl > pOptimizedNetworkImpl
static void Destroy(IOptimizedNetwork *network)
size_t GetNumOutputs() const
void ExecuteStrategy(IStrategy &strategy) const
const std::shared_ptr< IProfiler > & GetProfiler() const
size_t GetNumInputs() const
arm::pipe::ProfilingGuid GetGuid() const
virtual std::vector< Capability > GetCapabilities(const IConnectableLayer *layer, const IConnectableLayer *connectedLayer, CapabilityClass capabilityClass)
virtual MemorySourceFlags GetExportFlags() const
static const FactoryId LegacyFactoryId
virtual MemorySourceFlags GetImportFlags() const
static const FactoryId DeferredFactoryId
Use the workload factory to create the tensor handle.
virtual bool SupportsMapUnmap() const
static bool IsLayerSupported(const BackendId &backendId, const IConnectableLayer &layer, Optional< DataType > dataType, std::string &outReasonIfUnsupported)
This layer represents an instance normalization operation.
This layer represents a L2 normalization operation.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
void SetBackendId(const BackendId &id) override
Set the backend of the IConnectableLayer.
Optional< BackendId > GetBackendHint() const
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
const std::vector< InputSlot > & GetInputSlots() const
const BackendId & GetBackendId() const
This layer represents a log softmax operation.
This layer represents a Logical Binary operation.
This layer represents a LSTM operation.
LstmBasicParameters m_BasicParameters
This layer represents a maximum operation.
This layer represents a mean operation.
This layer dequantizes the input tensor.
This layer represents a minimum operation.
This layer represents a multiplication operation.
Private implementation of INetwork.
IConnectableLayer * AddFusedLayer(const FusedDescriptor &fusedDescriptor, const char *name=nullptr)
IConnectableLayer * AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor &elementwiseUnaryDescriptor, const char *name=nullptr)
IConnectableLayer * AddLstmLayer(const LstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
IConnectableLayer * AddDivisionLayer(const char *name=nullptr)
IConnectableLayer * AddQuantizeLayer(const char *name=nullptr)
IConnectableLayer * AddMergeLayer(const char *name=nullptr)
IConnectableLayer * AddPermuteLayer(const PermuteDescriptor &permuteDescriptor, const char *name=nullptr)
IConnectableLayer * AddSpaceToDepthLayer(const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr)
IConnectableLayer * AddConstantLayer(const ConstTensor &input, const char *name=nullptr)
IConnectableLayer * AddLogicalBinaryLayer(const LogicalBinaryDescriptor &logicalBinaryDescriptor, const char *name=nullptr)
IConnectableLayer * AddConvertFp16ToFp32Layer(const char *name=nullptr)
IConnectableLayer * AddRankLayer(const char *name=nullptr)
IConnectableLayer * AddSwitchLayer(const char *name=nullptr)
IConnectableLayer * AddQLstmLayer(const QLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
IConnectableLayer * AddDequantizeLayer(const char *name=nullptr)
IConnectableLayer * AddBroadcastToLayer(const BroadcastToDescriptor &descriptor, const char *name=nullptr)
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
IConnectableLayer * AddQuantizedLstmLayer(const QuantizedLstmInputParams ¶ms, const char *name=nullptr)
IConnectableLayer * AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor &descriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr)
IConnectableLayer * AddFloorLayer(const char *name=nullptr)
IConnectableLayer * AddConvolution3dLayer(const Convolution3dDescriptor &convolution3dDescriptor, const char *name=nullptr)
IConnectableLayer * AddStackLayer(const StackDescriptor &stackDescriptor, const char *name=nullptr)
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const char *name=nullptr)
IConnectableLayer * AddMinimumLayer(const char *name=nullptr)
IConnectableLayer * AddMaximumLayer(const char *name=nullptr)
IConnectableLayer * AddChannelShuffleLayer(const ChannelShuffleDescriptor &channelShuffleDescriptor, const char *name=nullptr)
IConnectableLayer * AddNormalizationLayer(const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr)
IConnectableLayer * AddPreluLayer(const char *name=nullptr)
IConnectableLayer * AddPadLayer(const PadDescriptor &padDescriptor, const char *name=nullptr)
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
void ExecuteStrategy(IStrategy &strategy) const
IConnectableLayer * AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr)
IConnectableLayer * AddCastLayer(const char *name=nullptr)
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr)
IConnectableLayer * AddScatterNdLayer(const ScatterNdDescriptor &scatterDescriptor, const char *name=nullptr)
IConnectableLayer * AddBatchMatMulLayer(const BatchMatMulDescriptor &desc, const char *name=nullptr)
IConnectableLayer * AddLogSoftmaxLayer(const LogSoftmaxDescriptor &logSoftmaxDescriptor, const char *name=nullptr)
IConnectableLayer * AddReshapeLayer(const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr)
IConnectableLayer * AddSliceLayer(const SliceDescriptor &sliceDescriptor, const char *name=nullptr)
IConnectableLayer * AddBatchNormalizationLayer(const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr)
IConnectableLayer * AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr)
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
IConnectableLayer * AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor &elementwiseBinaryDescriptor, const char *name=nullptr)
IConnectableLayer * AddTileLayer(const TileDescriptor &tileDescriptor, const char *name=nullptr)
IConnectableLayer * AddGatherLayer(const GatherDescriptor &gatherDescriptor, const char *name=nullptr)
IConnectableLayer * AddL2NormalizationLayer(const L2NormalizationDescriptor &desc, const char *name=nullptr)
IConnectableLayer * AddTransposeLayer(const TransposeDescriptor &transposeDescriptor, const char *name=nullptr)
IConnectableLayer * AddConvertFp32ToFp16Layer(const char *name=nullptr)
IConnectableLayer * AddUnidirectionalSequenceLstmLayer(const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParams ¶ms, const char *name=nullptr)
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
IConnectableLayer * AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor &desc, const char *name=nullptr)
IConnectableLayer * AddDetectionPostProcessLayer(const DetectionPostProcessDescriptor &descriptor, const ConstTensor &anchors, const char *name=nullptr)
IConnectableLayer * AddStridedSliceLayer(const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr)
IConnectableLayer * AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
IConnectableLayer * AddComparisonLayer(const ComparisonDescriptor &comparisonDescriptor, const char *name=nullptr)
IConnectableLayer * AddMeanLayer(const MeanDescriptor &meanDescriptor, const char *name=nullptr)
IConnectableLayer * AddResizeLayer(const ResizeDescriptor &resizeDescriptor, const char *name=nullptr)
IConnectableLayer * AddArgMinMaxLayer(const ArgMinMaxDescriptor &desc, const char *name=nullptr)
IConnectableLayer * AddReduceLayer(const ReduceDescriptor &reduceDescriptor, const char *name=nullptr)
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr)
IConnectableLayer * AddPooling3dLayer(const Pooling3dDescriptor &pooling3dDescriptor, const char *name=nullptr)
IConnectableLayer * AddPrecompiledLayer(const PreCompiledDescriptor &preCompiledDescriptor, CompiledBlobPtr compiledBlobPtr, const Optional< BackendId > &backend, const char *name=nullptr)
IConnectableLayer * AddSubtractionLayer(const char *name=nullptr)
IConnectableLayer * AddDepthToSpaceLayer(const DepthToSpaceDescriptor &depthToSpaceDescriptor, const char *name=nullptr)
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
IConnectableLayer * AddReverseV2Layer(const char *name=nullptr)
IConnectableLayer * AddGatherNdLayer(const char *name=nullptr)
IConnectableLayer * AddShapeLayer(const char *name=nullptr)
IConnectableLayer * AddFillLayer(const FillDescriptor &fillDescriptor, const char *name=nullptr)
const Graph & GetGraph() const
This layer represents a normalization operation.
bool Validate(const SubgraphView &originalSubgraph) const
const Substitutions & GetSubstitutions() const
const Subgraphs & GetDeletedSubgraphs() const
const Subgraphs & GetFailedSubgraphs() const
virtual ~OptimizedNetworkImpl()
virtual Status SerializeToDot(std::ostream &stream) const
virtual size_t GetNumOutputs() const
void ExecuteStrategy(IStrategy &strategy) const
virtual size_t GetNumInputs() const
OptimizedNetworkImpl(const OptimizedNetworkImpl &other, const ModelOptions &modelOptions)
virtual Status PrintGraph()
static void Pass(Graph &graph, const Optimizations &optimizations)
~OptimizerOptionsOpaque()
void AddModelOption(armnn::BackendOptions)
void SetDebugEnabled(bool DebugState)
OptimizerOptionsOpaque & operator=(OptimizerOptionsOpaque other)
bool GetImportEnabled() const
bool GetReduceFp32ToBf16() const
bool GetProfilingEnabled() const
void SetReduceFp32ToFp16(bool ReduceFp32ToFp16State)
armnn::ShapeInferenceMethod GetShapeInferenceMethod() const
void SetAllowExpandedDims(bool ExpandedDimsAllowed)
bool GetDebugEnabled() const
bool GetReduceFp32ToFp16() const
void SetProfilingEnabled(bool ProfilingState)
bool GetDebugToFileEnabled() const
void SetDebugToFileEnabled(bool DebugFileState)
void SetExportEnabled(bool ExportState)
const std::string ToString() const
void SetImportEnabled(bool ImportState)
armnn::ModelOptions GetModelOptions() const
void SetShapeInferenceMethod(armnn::ShapeInferenceMethod ShapeInferenceMethodType)
bool GetAllowExpandedDims() const
bool GetExportEnabled() const
bool has_value() const noexcept
A layer user-provided data can be bound to (e.g. inputs, outputs).
const InputSlot * GetConnection(unsigned int index) const override
unsigned int GetNumConnections() const override
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
const std::vector< InputSlot * > & GetConnections() const
Layer & GetOwningLayer() const
void SetTensorInfo(const TensorInfo &tensorInfo) override
void Disconnect(InputSlot &slot)
const TensorInfo & GetTensorInfo() const override
int Connect(InputSlot &destination)
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
This layer represents a pad operation.
This layer represents a permutation operation.
This layer represents a pooling 2d operation.
This layer represents a pooling 3d operation.
void SetPreCompiledObject(PreCompiledObjectPtr preCompiledObject)
This layer represents a QLstm operation.
QLstmBasicParameters m_BasicParameters
This layer represents a QuantizedLstm operation.
QuantizedLstmParameters m_QuantizedLstmParameters
This layer represents a reduction operation.
This layer represents a reshape operation.
This layer represents a resize operation.
This layer represents a ReverseV2 operation.
This layer represents a ScatterNd operator.
This layer represents a softmax operation.
This layer represents a SpaceToBatchNd operation.
This layer represents a SpaceToDepth operation.
This layer represents a split operation.
This layer represents a stack operation.
This layer represents an unknown operation in the input graph.
This layer represents a strided slice operation.
The SubgraphView class represents a subgraph of a Graph.
IConnectableLayers::iterator IConnectableLayerIterator
IConnectableLayerIterator begin()
const IConnectableLayers & GetIConnectableLayers() const
std::list< IConnectableLayer * > IConnectableLayers
IConnectableLayerIterator end()
static Subgraphs SelectSubgraphs(Graph &graph, const LayerSelectorFunction &selector)
Selects subgraphs from a graph based on the selector function and the algorithm.
std::vector< SubgraphView::SubgraphViewPtr > Subgraphs
This layer represents a subtraction operation.
This layer calculates both true and false outputs for input.
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
void SetDataType(DataType type)
DataType GetDataType() const
This layer represents a 2D transpose convolution operation.
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store weight values.
This layer represents a transpose operation.
This layer represents a LSTM operation.
LstmBasicParameters m_BasicParameters
static void ConvertFloat16To32(const void *srcFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
ConvertConstants< Float16ToFloat32, IsFloat32Layer > ConvertConstantsHalfToFloat
OptimizeForConnection< PermuteLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteLayer > > PermuteAndBatchToSpaceAsDepthToSpace
OptimizeForConnection< ConvertFp16ToFp32Layer, ConvertFp32ToFp16Layer, OptimizeInverseConversionsImpl > OptimizeInverseConversionsFp16
ConvertConstants< Float32ToFloat16, IsFloat16Layer > ConvertConstantsFloatToHalf
OptimizeForExclusiveConnection< PadLayer, DepthwiseConvolution2dLayer, pad_fold::FoldPadIntoDepthwiseConvolution2dImpl > FoldPadIntoDepthwiseConvolution2d
OptimizeForExclusiveConnection< PadLayer, Pooling2dLayer, pad_fold::FoldPadIntoPooling2dImpl > FoldPadIntoPooling2d
OptimizeForConnection< Layer, ReshapeLayer, SquashEqualSiblingsImpl< ReshapeLayer > > SquashEqualReshapeSiblings
OptimizeForConnection< TransposeLayer, TransposeLayer, OptimizeInversePermutesImpl< TransposeLayer > > OptimizeInverseTransposes
OptimizeForConnection< ConstantLayer, DequantizeLayer, TurboConvertConstDequantisationLayersToConstLayersImpl > TurboConvertConstDequantisationLayersToConstLayers
OptimizeForConnection< ConstantLayer, DequantizeLayer, ConvertConstDequantisationLayersToConstLayersImpl > ConvertConstDequantisationLayersToConstLayers
OptimizeForType< Layer, AddBroadcastReshapeLayerImpl > AddBroadcastReshapeLayer
OptimizeForExclusiveConnection< DepthwiseConvolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< DepthwiseConvolution2dLayer, armnn::DataType::Float32 > > FuseBatchNormIntoDepthwiseConvolution2DFloat32
OptimizeForConnection< Layer, TransposeLayer, MoveTransposeUpImpl > MoveTransposeUp
OptimizeForConnection< Layer, PermuteLayer, SquashEqualSiblingsImpl< PermuteLayer > > SquashEqualPermuteSiblings
OptimizeForConnection< ReshapeLayer, ReshapeLayer, OptimizeConsecutiveReshapesImpl > OptimizeConsecutiveReshapes
OptimizeForType< Layer, ConvertFp32NetworkToFp16Impl > Fp32NetworkToFp16Converter
OptimizeForExclusiveConnection< Convolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< Convolution2dLayer, armnn::DataType::Float16 > > FuseBatchNormIntoConvolution2DFloat16
OptimizeForExclusiveConnection< PadLayer, Convolution2dLayer, pad_fold::FoldPadIntoConvolution2dImpl > FoldPadIntoConvolution2d
OptimizeForConnection< TransposeLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< TransposeLayer > > TransposeAndBatchToSpaceAsDepthToSpace
OptimizeForType< Layer, AddDebugToFileImpl > InsertDebugToFileLayer
OptimizeForConnection< PermuteLayer, PermuteLayer, OptimizeInversePermutesImpl< PermuteLayer > > OptimizeInversePermutes
OptimizeForExclusiveConnection< Convolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< Convolution2dLayer, armnn::DataType::Float32 > > FuseBatchNormIntoConvolution2DFloat32
OptimizeForType< Layer, AddDebugImpl > InsertDebugLayer
OptimizeForConnection< Layer, PermuteLayer, MovePermuteUpImpl > MovePermuteUp
OptimizeForExclusiveConnection< DepthwiseConvolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< DepthwiseConvolution2dLayer, armnn::DataType::Float16 > > FuseBatchNormIntoDepthwiseConvolution2DFloat16
OptimizeForConnection< Layer, TransposeLayer, SquashEqualSiblingsImpl< TransposeLayer > > SquashEqualTransposeSiblings
OptimizeForExclusiveConnection< ElementwiseBinaryLayer, ElementwiseBinaryLayer, MaxMinIntoBoundedReluImpl > MaxMinIntoBoundedRelu
OptimizeForType< BroadcastToLayer, DeleteBroadcastToImpl > BroadcastToOptimizationLayer
OptimizeForType< TransposeLayer, TransposeAsReshapeImpl > TransposeAsReshape
OptimizeForConnection< ConstantLayer, PermuteLayer, ConvertConstPermuteLayersToConstLayers > FusePermuteIntoConstLayer
OptimizeForType< PermuteLayer, PermuteAsReshapeImpl > PermuteAsReshape
OptimizeForConnection< ConvertFp32ToFp16Layer, ConvertFp16ToFp32Layer, OptimizeInverseConversionsImpl > OptimizeInverseConversionsFp32
Copyright (c) 2021 ARM Limited and Contributors.
void ReportWarning(const std::string &warningMessage, Optional< std::vector< std::string > & > warningMessages)
OptimizationResult AssignBackends(OptimizedNetworkImpl *optNetObjPtr, BackendSettings &backendSettings, SubgraphView &subgraph, Optional< std::vector< std::string > & > errMessages)
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 > & > messages)
BackendsMap CreateSupportedBackends(TensorHandleFactoryRegistry &handleFactoryRegistry, BackendSettings &backendSettings)
std::vector< DataType > GetLayerInOutDatatype(const Layer *layer)
void AssignBackendsIConnectable(OptimizedNetworkImpl *optNetObjPtr, IConnectableLayer *it, Optional< std::vector< std::string > & > errMessages, OptimizationResult &result, BackendSettings &backendSettings, std::vector< BackendId > &availablePreferredBackends, bool &restart)
void ReportError(const std::string &errorMessage, Optional< std::vector< std::string > & > errorMessages)
bool HasMatchingCapability(const BackendOptions::BackendOption &capability, const BackendCapabilities &capabilities)
Convenience function to check if a given capability matches a capability in a BackendCapabilities str...
void IgnoreUnused(Ts &&...)
bool IsTfLiteTurboModel(const Graph &optGraph)
std::vector< BackendOptions > NetworkOptions
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
std::vector< BackendOptions > ModelOptions
bool RequiresCopy(ITensorHandleFactory::FactoryId src, ITensorHandleFactory::FactoryId dst, TensorHandleFactoryRegistry ®istry)
ITensorHandleFactory::FactoryId CalculateSlotOptionForInput(BackendsMap &backends, OutputSlot &slot, TensorHandleFactoryRegistry ®istry, bool importEnabled)
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Optional< const BackendOptions::BackendOption > GetCapability(const std::string &backendCapabilityName, const BackendCapabilities &capabilities)
Returns a BackendCapability if the backend lists the capability The BackendCapability must then be in...
EdgeStrategy CalculateEdgeStrategy(BackendsMap &backends, ITensorHandleFactory::FactoryId srcFactoryId, const Layer &layer, const Layer &connectedLayer, TensorHandleFactoryRegistry ®istry, bool importEnabled)
constexpr const char * GetDataTypeName(DataType dataType)
OptimizationResult AssignBackends(OptimizedNetworkImpl *optNetObjPtr, BackendSettings &backendSettings, Graph::Iterator &firstLayer, Graph::Iterator &lastLayer, Optional< std::vector< std::string > & > errMessages)
float Dequantize(QuantizedType value, float scale, int32_t offset)
Dequantize an 8-bit data type into a floating point data type.
bool CheckScaleSetOnQuantizedType(Layer *layer, Optional< std::vector< std::string > & > errMessages)
bool CheckFastMathSupport(const std::vector< BackendId > &availablePreferredBackends, const ModelOptions &modelOptions)
std::map< BackendId, std::unique_ptr< class IBackendInternal > > BackendsMap
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptionsOpaque &options=OptimizerOptionsOpaque(), Optional< std::vector< std::string > & > messages=EmptyOptional())
Create an optimized version of the network.
bool CheckFp16Support(BackendsMap &backends, const std::vector< BackendId > &availablePreferredBackends)
Optimizer::Optimizations MakeOptimizations(Args &&... args)
ITensorHandleFactory::FactoryId CalculateSlotOptionForOutput(BackendsMap &backends, OutputSlot &slot, TensorHandleFactoryRegistry ®istry)
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
bool HasCapability(const std::string &name, const BackendCapabilities &capabilities)
Convenience function to check if a capability exists in a BackendCapabilites struct.
std::vector< ConvertFp32ToFp16Layer * > InsertConvertFp32ToFp16LayersAfter(Graph &graph, Layer &layer)
BackendRegistry & BackendRegistryInstance()
OptimizationResult ApplyBackendOptimizations(OptimizedNetworkImpl *optNetObjPtr, BackendSettings &backendSettings, BackendsMap &backends, const ModelOptions &modelOptions, Optional< std::vector< std::string > & > errMessages)
std::vector< BackendId > BackendIdVector
OptimizationResult SelectTensorHandleStrategy(Graph &optGraph, BackendsMap &backends, TensorHandleFactoryRegistry ®istry, bool importEnabled, bool exportEnabled, Optional< std::vector< std::string > & > errMessages)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
std::vector< ConvertFp16ToFp32Layer * > InsertConvertFp16ToFp32LayersBefore(Graph &graph, Layer &layer, bool expectCorrectInputType)
ITensorHandleFactory::FactoryId CalculateSlotOption(BackendsMap &backends, OutputSlot &outputSlot, TensorHandleFactoryRegistry ®istry, bool exportEnabled)
const char * GetLayerTypeAsCString(LayerType type)
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
@ ValidateOnly
Validate all output shapes.
@ CpuAcc
CPU Execution: NEON: ArmCompute.
@ CpuRef
CPU Execution: Reference C++ kernels.
@ GpuAcc
GPU Execution: OpenCL: ArmCompute.
OptimizationResult ReturnWithError(OptimizationResult res, const Layer *layer, const BackendSettings &backendSettings, Optional< std::vector< std::string > & > errMessages)
std::unique_ptr< void, CompiledBlobDeleter > CompiledBlobPtr
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
@ ExportToTarget
Destination backend can work directly with tensors on source backend.
@ DirectCompatibility
No strategy has been defined. Used internally to verify integrity of optimizations.
@ CopyToTarget
Source backends tensor data can be exported to destination backend tensor without copy.
std::string CreateDirectory(std::string sPath)
Returns full path to temporary folder.
An ActivationDescriptor for the ActivationLayer.
An ArgMinMaxDescriptor for ArgMinMaxLayer.
std::string GetName() const
Struct for the users to pass backend specific options.
BackendIdSet m_SupportedBackends
BackendIdSet m_IgnoredBackends
BackendIdSet m_SelectedBackends
bool IsBackendSupported(const BackendId &backend) const
BackendIdVector GetAvailablePreferredBackends() const
bool IsCpuRefUsed() const
BackendIdVector m_PreferredBackends
A BatchMatMulDescriptor for the BatchMatMul operator.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
A ChannelShuffleDescriptor for the ChannelShuffle operator.
A ComparisonDescriptor for the ComparisonLayer.
A Convolution2dDescriptor for the Convolution2dLayer.
A Convolution3dDescriptor for the Convolution3dLayer.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A ElementwiseBinaryDescriptor for the ElementwiseBinaryLayer.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
A FillDescriptor for the FillLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
A FusedDescriptor for the FusedLayer.
A GatherDescriptor for the GatherLayer.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
An LstmDescriptor for the LstmLayer.
bool m_PeepholeEnabled
Enable/disable peephole.
bool m_LayerNormEnabled
Enable/disable layer normalization.
bool m_ProjectionEnabled
Enable/disable the projection layer.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
A MeanDescriptor for the MeanLayer.
A NormalizationDescriptor for the NormalizationLayer.
bool IsWarningOnly() const
bool m_ExportEnabled
Enable Export.
bool m_ImportEnabled
Enable Import.
bool m_ReduceFp32ToBf16
@Note This feature has been replaced by enabling Fast Math in compute library backend options.
bool m_ProfilingEnabled
Enable profiling dump of the optimizer phase.
bool m_Debug
Add debug data for easier troubleshooting.
bool m_ReduceFp32ToFp16
Reduces all Fp32 operators in the model to Fp16 for faster processing.
ModelOptions m_ModelOptions
Enable Model Options.
ShapeInferenceMethod m_shapeInferenceMethod
Infer output size when not available.
bool m_AllowExpandedDims
When calculating tensor sizes, dimensions of size == 1 will be ignored.
bool m_DebugToFile
Pass debug data to separate output files for easier troubleshooting.
An OriginsDescriptor for the ConcatLayer.
A PadDescriptor for the PadLayer.
A PermuteDescriptor for the PermuteLayer.
A Pooling2dDescriptor for the Pooling2dLayer.
A Pooling3dDescriptor for the Pooling3dLayer.
A PreCompiledDescriptor for the PreCompiledLayer.
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
A QLstmDescriptor for the QLstmLayer.
bool m_PeepholeEnabled
Enable/disable peephole.
bool m_LayerNormEnabled
Enable/disable layer normalization.
bool m_ProjectionEnabled
Enable/disable the projection layer.
bool m_CifgEnabled
Enable/disable CIFG (coupled input & forget gate).
std::shared_ptr< ConstTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
A ReduceDescriptor for the REDUCE operators.
A ReshapeDescriptor for the ReshapeLayer.
A ResizeDescriptor for the ResizeLayer.
A ScatterNdDescriptor for the ScatterNdLayer.
A SliceDescriptor for the SliceLayer.
A SoftmaxDescriptor for the SoftmaxLayer.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A StackDescriptor for the StackLayer.
A StandInDescriptor for the StandIn layer.
A StridedSliceDescriptor for the StridedSliceLayer.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
bool m_BiasEnabled
Enable/disable bias.
A TransposeDescriptor for the TransposeLayer.
A ViewsDescriptor for the SplitterLayer.