31 #include <client/include/IProfilingService.hpp>
33 #include <common/include/ProfilingGuid.hpp>
35 #include <fmt/format.h>
63 bool importEnabled,
ModelOptions modelOptions,
bool exportEnabled,
66 importEnabled, modelOptions,
67 exportEnabled, debugToFile))
73 bool importEnabled,
ModelOptions modelOptions,
bool exportEnabled,
74 bool debugToFile,
bool allowExpandedDims)
76 shapeInferenceMethod, importEnabled,
77 modelOptions, exportEnabled,
78 debugToFile, allowExpandedDims))
85 p_OptimizerOptionsImpl->m_ImportEnabled = OptimizerStruct.
m_ImportEnabled;
87 p_OptimizerOptionsImpl->m_ModelOptions = OptimizerStruct.
m_ModelOptions;
89 p_OptimizerOptionsImpl->m_DebugToFile = OptimizerStruct.
m_DebugToFile;
90 p_OptimizerOptionsImpl->m_Debug = OptimizerStruct.
m_Debug;
92 p_OptimizerOptionsImpl->m_ExportEnabled = OptimizerStruct.
m_ExportEnabled;
114 p_OptimizerOptionsImpl->m_ImportEnabled = ImportState;
119 p_OptimizerOptionsImpl->m_ExportEnabled = ExportState;
124 p_OptimizerOptionsImpl->m_ProfilingEnabled = ProfilingState;
129 p_OptimizerOptionsImpl->m_Debug = DebugState;
134 p_OptimizerOptionsImpl->m_DebugToFile = DebugFileState;
139 p_OptimizerOptionsImpl->m_ReduceFp32ToFp16 = ReduceFp32ToFp16State;
144 p_OptimizerOptionsImpl->m_shapeInferenceMethod = ShapeInferenceMethodType;
149 p_OptimizerOptionsImpl->m_AllowExpandedDims = ExpandedDimsAllowed;
154 p_OptimizerOptionsImpl->m_ModelOptions.push_back(NewModelOption);
159 return p_OptimizerOptionsImpl->m_ProfilingEnabled;
164 return p_OptimizerOptionsImpl->m_ImportEnabled;
169 return p_OptimizerOptionsImpl->m_ExportEnabled;
174 return p_OptimizerOptionsImpl->m_ReduceFp32ToFp16;
179 return p_OptimizerOptionsImpl->m_ReduceFp32ToBf16;
184 return p_OptimizerOptionsImpl->m_Debug;
189 return p_OptimizerOptionsImpl->m_DebugToFile;
194 return p_OptimizerOptionsImpl->m_AllowExpandedDims;
199 return p_OptimizerOptionsImpl->m_ModelOptions;
204 return p_OptimizerOptionsImpl->m_shapeInferenceMethod;
209 std::stringstream stream;
210 stream <<
"OptimizerOptions: \n";
211 stream <<
"\tReduceFp32ToFp16: " << p_OptimizerOptionsImpl->m_ReduceFp32ToFp16 <<
"\n";
212 stream <<
"\tReduceFp32ToBf16: " << p_OptimizerOptionsImpl->m_ReduceFp32ToBf16 <<
"\n";
213 stream <<
"\tDebug: " << p_OptimizerOptionsImpl->m_Debug <<
"\n";
214 stream <<
"\tDebug to file: " << p_OptimizerOptionsImpl->m_DebugToFile <<
"\n";
215 stream <<
"\tShapeInferenceMethod: " <<
217 "ValidateOnly" :
"InferAndValidate") <<
"\n";
218 stream <<
"\tImportEnabled: " << p_OptimizerOptionsImpl->m_ImportEnabled <<
"\n";
219 stream <<
"\tExportEnabled: " << p_OptimizerOptionsImpl->m_ExportEnabled <<
"\n";
220 stream <<
"\tProfilingEnabled: " << p_OptimizerOptionsImpl->m_ProfilingEnabled <<
"\n";
221 stream <<
"\tAllowExpandedDims: " << p_OptimizerOptionsImpl->m_AllowExpandedDims <<
"\n";
223 stream <<
"\tModelOptions: \n";
224 for (
auto optionsGroup : p_OptimizerOptionsImpl->m_ModelOptions)
226 for (
size_t i=0; i < optionsGroup.GetOptionCount(); i++)
229 stream <<
"\t\tBackend: " << optionsGroup.GetBackendId() <<
"\n"
230 <<
"\t\t\tOption: " << option.
GetName() <<
"\n"
262 return pNetworkImpl->AddComparisonLayer(comparisonDescriptor, name);
269 return pNetworkImpl->AddConcatLayer(concatDescriptor, name);
276 return pNetworkImpl->AddConvolution2dLayer(convolution2dDescriptor, name);
282 return pNetworkImpl->AddConvolution3dLayer(convolution3dDescriptor, name);
289 return pNetworkImpl->AddDepthToSpaceLayer(depthToSpaceDescriptor, name);
297 return pNetworkImpl->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, name);
312 return pNetworkImpl->AddDetectionPostProcessLayer(descriptor, anchors, name);
318 return pNetworkImpl->AddElementwiseBinaryLayer(elementwiseBinaryDescriptor, name);
324 return pNetworkImpl->AddElementwiseUnaryLayer(elementwiseUnaryDescriptor, name);
330 return pNetworkImpl->AddFillLayer(fillDescriptor, name);
336 return pNetworkImpl->AddFullyConnectedLayer(fullyConnectedDescriptor, name);
342 return pNetworkImpl->AddFusedLayer(fusedDescriptor, name);
348 return pNetworkImpl->AddPermuteLayer(permuteDescriptor, name);
354 return pNetworkImpl->AddBatchToSpaceNdLayer(batchToSpaceNdDescriptor, name);
360 return pNetworkImpl->AddPooling2dLayer(pooling2dDescriptor, name);
366 return pNetworkImpl->AddPooling3dLayer(pooling3dDescriptor, name);
374 return pNetworkImpl->AddPrecompiledLayer(preCompiledDescriptor, std::move(compiledBlobPtr), backend, name);
380 return pNetworkImpl->AddActivationLayer(activationDescriptor, name);
386 return pNetworkImpl->AddNormalizationLayer(normalizationDescriptor, name);
391 return pNetworkImpl->AddSliceLayer(sliceDescriptor, name);
396 return pNetworkImpl->AddSoftmaxLayer(softmaxDescriptor, name);
402 return pNetworkImpl->AddSplitterLayer(splitterDescriptor, name);
431 return pNetworkImpl->AddBatchNormalizationLayer(desc, mean, variance, beta, gamma, name);
442 return pNetworkImpl->AddResizeLayer(resizeDescriptor, name);
448 return pNetworkImpl->AddReduceLayer(reduceDescriptor, name);
454 return pNetworkImpl->AddInstanceNormalizationLayer(desc, name);
460 return pNetworkImpl->AddL2NormalizationLayer(desc, name);
466 return pNetworkImpl->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
478 return pNetworkImpl->AddReshapeLayer(reshapeDescriptor, name);
484 return pNetworkImpl->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
490 return pNetworkImpl->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
506 return pNetworkImpl->AddLstmLayer(descriptor, params, name);
532 return pNetworkImpl->AddMeanLayer(meanDescriptor, name);
549 return pNetworkImpl->AddStridedSliceLayer(stridedSliceDescriptor, name);
585 return pNetworkImpl->AddTransposeConvolution2dLayer(descriptor, weights, biases, name);
591 return pNetworkImpl->AddTransposeLayer(transposeDescriptor, name);
614 return pNetworkImpl->AddQuantizedLstmLayer(params, name);
621 return pNetworkImpl->AddQLstmLayer(descriptor, params, name);
627 return pNetworkImpl->AddLogicalBinaryLayer(descriptor, name);
635 return pNetworkImpl->AddUnidirectionalSequenceLstmLayer(descriptor, params, name);
641 return pNetworkImpl->AddChannelShuffleLayer(descriptor, name);
647 return pNetworkImpl->AddBatchMatMulLayer(descriptor, name);
664 return pNetworkImpl->AddBroadcastToLayer(descriptor, name);
670 return pNetworkImpl->AddScatterNdLayer(descriptor, name);
680 return new INetwork(networkOptions);
694 : pOptimizedNetworkImpl(new
OptimizedNetworkImpl(*other.pOptimizedNetworkImpl.get(), modelOptions)) {}
700 : pOptimizedNetworkImpl(
std::move(impl)) {}
750 return m_Graph->SerializeToDot(stream);
755 return m_Graph->GetNumInputs();
760 return m_Graph->GetNumOutputs();
764 Optional<std::vector<std::string>&> errorMessages)
766 std::stringstream fullErrorMessage;
767 fullErrorMessage <<
"ERROR: " << errorMessage;
771 errorMessages.value().push_back(fullErrorMessage.str());
776 Optional<std::vector<std::string>&> warningMessages)
778 std::stringstream fullWarningMessage;
779 fullWarningMessage <<
"WARNING: " << warningMessage;
783 warningMessages.value().push_back(fullWarningMessage.str());
791 Optional<std::vector<std::string>&> errMessages)
793 std::stringstream failureMsg;
804 bool noErrors =
true;
806 for (
unsigned int i = 0; i < numOutputs; i++) {
809 auto quantizationDataType =
info.GetDataType();
810 auto quantizationScales =
info.GetQuantizationScales();
812 switch(quantizationDataType) {
818 &&
info.HasPerAxisQuantization()) {
820 "Asymmetric Quantization Datatype.");
824 (
info.GetQuantizationScale() != (1.0f / 256.0f) ||
825 info.GetQuantizationOffset() != 0) &&
827 std::stringstream ss;
828 ss <<
"Quantization parameters for Softmax layer (Scale: " <<
829 info.GetQuantizationScale() <<
" and Offset: " <<
info.GetQuantizationOffset() <<
830 ") are incorrect and have been updated to Scale: 0.00390625 and Offset: 0";
832 info.SetQuantizationScale((1.0f / 256.0f));
833 info.SetQuantizationOffset(0);
851 const std::vector<BackendId>& availablePreferredBackends,
852 std::string& reasonIfUnsupported,
853 Optional<std::vector<std::string>&> messages)
858 auto ReturnError = [&](
const Layer* layer)
866 std::string currentReasonIfUnsupported;
872 reasonIfUnsupported += currentReasonIfUnsupported;
873 if (!isLayerSupported &&
HasCapability(
"AllOrNothing", backend))
876 if (
GetCapability(
"AllOrNothing", backend).value().GetValue().AsBool())
880 std::stringstream fullWarningMessage;
881 fullWarningMessage <<
"Backend: " << backend
882 <<
" has \"AllOrNothing\" enabled. A layer of type "
884 <<
"This backend will not be considered to execute this subgraph.";
885 reasonIfUnsupported.append(fullWarningMessage.str());
895 std::string checkStr =
"This CPU architecture does not support F16 data type, you need v8.2 or above";
896 if (!isLayerSupported || currentReasonIfUnsupported.find(checkStr) != std::string::npos)
904 auto ConstantLayerFromFp16ToFp32 = [](
Layer& layer)
908 ConstantLayer* constantLayer = PolymorphicDowncast<ConstantLayer*>(&layer);
914 std::vector<float> newValues(
info.GetNumElements());
918 info.GetNumElements(),
931 bool checkType =
false;
935 auto connectedOutputSlot = inputSlot.GetConnectedOutputSlot();
938 if (connectedOutputSlot->GetNumConnections() == 1)
941 ConstantLayerFromFp16ToFp32(connectedOutputSlot->GetOwningLayer());
947 std::vector<ConvertFp16ToFp32Layer*> convertFp16ToFp32Layers;
950 convertFp16ToFp32Layers =
955 std::vector<ConvertFp32ToFp16Layer*> convertFp32ToFp16Layers;
958 convertFp32ToFp16Layers =
963 auto AssignFirstSupportedBackend = [&](
Layer* layer,
BackendId preferredBackend)
965 bool supportedBackendFound =
false;
966 std::string reasonIfUnsupported;
972 reasonIfUnsupported))
974 supportedBackendFound =
true;
978 for (
const auto& backend : availablePreferredBackends)
981 if (backend == preferredBackend)
989 reasonIfUnsupported))
991 supportedBackendFound =
true;
997 return supportedBackendFound;
1002 if (!AssignFirstSupportedBackend(convertLayer, backend))
1004 return ReturnError(convertLayer);
1010 if (!AssignFirstSupportedBackend(convertLayer, backend))
1012 return ReturnError(convertLayer);
1020 std::stringstream warningMsg;
1022 <<
" is not supported on requested backend " << layer->
GetBackendId().
Get()
1025 <<
" (reason: " << reasonIfUnsupported
1026 <<
"), falling back to the next backend.";
1043 return {dataTypeIn, dataTypeOut};
1047 const std::vector<BackendId>& availablePreferredBackends)
1049 bool hasFp16 =
false;
1051 auto firstBackend = availablePreferredBackends[0];
1052 auto backendObjPtr = backends.find(firstBackend)->second.get();
1055 auto backendCapabilities = backendObjPtr->GetCapabilities();
1061 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1062 <<
", has FP16 support.";
1066 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1067 <<
", does not have FP16 support. "
1068 <<
"The FP16 turbo mode option will be disable. It will run using FP32.";
1072 for (
size_t i = 1; i < availablePreferredBackends.size(); ++i)
1074 auto backend = availablePreferredBackends[i];
1075 backendObjPtr = backends.find(backend)->second.get();
1076 backendCapabilities = backendObjPtr->GetCapabilities();
1079 ARMNN_LOG(
debug) <<
"Next preferred backend: " << backend <<
", does not have FP16 support. "
1080 <<
"It will run using FP32 when falling back to this backend.";
1084 ARMNN_LOG(
debug) <<
"Next preferred backend: " << backend <<
", has FP16 support.";
1095 Optional<std::vector<std::string>&> errMessages,
1098 std::vector<BackendId>& availablePreferredBackends,
1101 auto ReturnError = [&](
const Layer* layer)
1106 auto layer = PolymorphicDowncast<Layer*>(it);
1115 std::string reasonIfUnsupported;
1125 if (layer->GetBackendHint().has_value() &&
1130 layer->GetBackendHint().value(),
1133 availablePreferredBackends,
1134 reasonIfUnsupported,
1135 errMessages).
IsOk())
1143 for (
const auto& backend : availablePreferredBackends)
1145 if (layer->GetBackendHint().has_value() &&
1146 layer->GetBackendHint().value() == backend)
1157 availablePreferredBackends,
1158 reasonIfUnsupported,
1176 if (reasonIfUnsupported.find(
"AllOrNothing") != std::string::npos)
1201 layer->SetBackendId(cpuBackendId);
1206 result = ReturnError(layer);
1216 Optional<std::vector<std::string>&> errMessages)
1221 bool restart =
false;
1223 for (
auto it = firstLayer; it != lastLayer; it = (restart ? firstLayer : ++it))
1225 if (it == firstLayer)
1228 if (availablePreferredBackends.empty())
1230 ReportError(
"No preferred backends are available", errMessages);
1245 availablePreferredBackends,
1249 for (
auto it = firstLayer; it != lastLayer; ++it)
1251 auto layer = PolymorphicDowncast<Layer*>(*it);
1259 bool isFloat16 =
false;
1260 for (
auto type : inOutDataType)
1269 if (layer->GetBackendId() ==
"Unknown" || isFloat16)
1276 availablePreferredBackends,
1281 for (
auto it = firstLayer; it != lastLayer; ++it)
1283 auto layer = PolymorphicDowncast<Layer*>(*it);
1287 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1288 layer->SetBackendId(connectedBackendId);
1299 Optional<std::vector<std::string>&> errMessages)
1305 if (availablePreferredBackends.empty())
1307 std::stringstream failureMsg;
1308 failureMsg <<
"No preferred backends are available";
1315 bool restart =
false;
1316 for (
auto it = firstLayer; it != lastLayer; ++it)
1323 availablePreferredBackends,
1327 for (
auto it = firstLayer; it != lastLayer; ++it)
1329 auto layer = PolymorphicDowncast<Layer*>(*it);
1333 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1334 layer->SetBackendId(connectedBackendId);
1344 Optional<std::vector<std::string>&> errMessages)
1362 auto backendFactory = backendRegistry.GetFactory(selectedBackend);
1363 auto backendObjPtr = backendFactory();
1365 backendObjPtr->RegisterTensorHandleFactories(handleFactoryRegistry);
1367 backends[backendObjPtr->GetId()] = std::move(backendObjPtr);
1377 Optional<std::vector<std::string>&> errMessages)
1388 auto backendObjPtr = backends.find(selectedBackend)->second.get();
1408 [&backendObjPtr](
const Layer& layer)
1415 if (subgraphs.empty())
1422 for (
auto& subgraph : subgraphs)
1426 OptimizationViews optimizationViews = backendObjPtr->OptimizeSubgraphView(*subgraph, modelOptions);
1427 if (!optimizationViews.
Validate(*subgraph))
1436 SubgraphView& replacementSubgraph = substitution.m_ReplacementSubgraph;
1437 SubgraphView& substitutableSubgraph = substitution.m_SubstitutableSubgraph;
1442 std::for_each(subgraphLayers.begin(), subgraphLayers.end(), [&selectedBackend](
IConnectableLayer* l)
1444 PolymorphicDowncast<Layer*>(l)->SetBackendId(selectedBackend);
1451 for (
auto& l : deletedSubgraph.GetIConnectableLayers())
1453 Layer* deletedLayer = PolymorphicDowncast<Layer*>(l);
1457 OutputSlot* parentOut = inputSlot.GetConnectedOutputSlot();
1472 std::stringstream warningMsg;
1473 warningMsg <<
"Some sub-graph(s) failed to optimized on " << backendObjPtr->GetId() <<
" backend.";
1478 if (!backendObjPtr->GetId().IsCpuRef())
1488 std::stringstream subgraphMsg;
1489 subgraphMsg <<
"Re-assigning backends to " << failedSubgraph.GetIConnectableLayers().size()
1490 <<
" layers inside sub-graph " << count++;
1497 if (reassignmentResult.
m_Error)
1520 if (srcFactory && dstFactory &&
1550 if (frmBackend == backends.end() ||
1551 !frmBackend->second->SupportsTensorAllocatorAPI())
1558 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1565 const Layer& connectedLayer = connection->GetOwningLayer();
1567 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1568 if (toBackend == backends.end())
1573 if (!toBackend->second.get()->SupportsTensorAllocatorAPI())
1579 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1580 for (
auto&& dst : dstPrefs)
1594 auto it = factoryScores.find(dst);
1595 if (it == factoryScores.end())
1598 factoryScores[dst] = 0;
1607 factoryScores[dst]++;
1610 if (factoryScores[dst] > topScore)
1612 topScore = factoryScores[dst];
1641 if (frmBackend == backends.end() ||
1642 !frmBackend->second->SupportsTensorAllocatorAPI())
1647 bool outputConnection =
false;
1650 const Layer& connectedLayer = connection->GetOwningLayer();
1653 outputConnection =
true;
1661 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1662 for (
auto&& pref : srcPrefs)
1667 if (outputConnection)
1670 bool fallbackConnection =
false;
1673 if (inputSlot.GetConnectedOutputSlot()->GetOwningLayer().GetBackendId() != layer.
GetBackendId())
1675 fallbackConnection =
true;
1678 if (fallbackConnection)
1682 if (!factoryCap.empty())
1692 if (!outputConnection)
1696 if (!factoryCap.empty())
1715 auto it = factoryScores.find(pref);
1716 if (it == factoryScores.end())
1719 factoryScores[pref] = 0;
1726 const Layer& connectedLayer = connection->GetOwningLayer();
1728 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1729 if (toBackend == backends.end())
1734 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1735 for (
auto&& src : srcPrefs)
1737 if (factoryScores.find(src) == factoryScores.end())
1742 for (
auto&& dst : dstPrefs)
1747 factoryScores[src]++;
1755 int minScore = std::numeric_limits<int>::max();
1756 for (
auto it : factoryScores)
1758 minScore = std::min(minScore, it.second);
1762 std::vector<ITensorHandleFactory::FactoryId> optimalFactories;
1763 for (
auto it : factoryScores)
1765 if (it.second == minScore)
1767 optimalFactories.push_back(it.first);
1772 for (
auto&& srcPref : srcPrefs)
1774 for (
auto&& comp : optimalFactories)
1776 if (comp == srcPref)
1789 const Layer& connectedLayer,
1793 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1794 if (toBackend == backends.end())
1799 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1822 for (
auto&& pref : dstPrefs)
1824 if (pref == srcFactoryId)
1834 for (
auto&& pref : dstPrefs)
1853 if (srcCapability.empty() && dstCapability.empty() && srcFallback.empty() && dstFallback.empty())
1864 for (
auto&& pref : dstPrefs)
1883 Optional<std::vector<std::string>&> errMessages)
1888 optGraph.
ForEachLayer([&backends, ®istry, &result, &errMessages, importEnabled, exportEnabled](
Layer* layer)
1892 if (backends.find(layer->
GetBackendId()) == backends.end())
1894 throw armnn::Exception(
"Backend id not found for the layer");
1907 case LayerType::Input:
1908 slotOption = CalculateSlotOptionForInput(backends, outputSlot, registry, importEnabled);
1910 case LayerType::Output:
1911 slotOption = CalculateSlotOptionForOutput(backends, outputSlot, registry);
1914 slotOption = CalculateSlotOption(backends, outputSlot, registry, exportEnabled);
1920 unsigned int connectionIdx = 0;
1923 const Layer& connectedLayer = connection->GetOwningLayer();
1925 EdgeStrategy strategy = CalculateEdgeStrategy(backends, slotOption, *layer, connectedLayer,
1926 registry, importEnabled);
1928 if (strategy == EdgeStrategy::Undefined)
1930 result.m_Error = true;
1933 errMessages.value().emplace_back(
"Could not find valid strategy required for compatibility"
1934 " between backends.");
1952 bool hasFastMath =
false;
1954 auto firstBackend = availablePreferredBackends[0];
1955 if (!modelOptions.empty())
1959 if (name ==
"FastMathEnabled")
1961 hasFastMath = value.
AsBool();
1962 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1963 <<
", has FastMath support.";
1969 ARMNN_LOG(
warning) <<
"The first available preferred backend: " << firstBackend
1970 <<
", does not have FastMath support. "
1971 <<
"Support for Turbo mode for TfLite post quantized FP16 models wil be disabled.";
1984 bool atLeastOneDequantizeEncountered =
false;
1985 for (
auto it = firstLayer; it != lastLayer; ++it)
1988 if (layer->GetType() == LayerType::Constant)
1990 auto& connectedLayer = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer();
1993 if(!(connectedLayer.GetInputSlot(0).GetTensorInfo().GetDataType() == DataType::Float16 &&
1994 connectedLayer.GetOutputSlot(0).GetTensorInfo().GetDataType() == DataType::Float32))
2000 atLeastOneDequantizeEncountered =
true;
2005 if (!atLeastOneDequantizeEncountered)
2015 const std::vector<BackendId>& backendPreferences,
2018 Optional<std::vector<std::string>&> messages)
2028 const std::vector<BackendId>& backendPreferences,
2031 Optional<std::vector<std::string>&> messages)
2037 ProfilerManager::GetInstance().RegisterProfiler(profiler.get());
2041 if (backendPreferences.empty())
2049 "Please use the FastMathEnabled backend option for CpuAcc or GpuAcc.");
2060 std::unique_ptr<Graph> graph = std::make_unique<Graph>(inGraph);
2068 optimizedOptions.push_back(importExport);
2071 &IOptimizedNetwork::Destroy);
2084 using namespace optimizations;
2109 if (availablePreferredBackends.empty())
2111 std::stringstream failureMsg;
2112 failureMsg <<
"None of the preferred backends " << backendPreferences
2129 reduceFp32ToFp16 =
true;
2163 for (
auto backend : mappedGpuBackends)
2165 if (std::count(backendPreferences.begin(), backendPreferences.end(), backend)
2166 && (backendPreferences[0] != backend) &&
2169 std::stringstream failureMsg;
2170 failureMsg << backend <<
" backend cannot be specified as fallback.";
2176 std::vector<BackendId> amendedBackendPreferences = backendPreferences;
2181 for (
auto backend : mappedGpuBackends)
2183 if (!std::count(amendedBackendPreferences.begin(), amendedBackendPreferences.end(), backend))
2185 amendedBackendPreferences.insert(amendedBackendPreferences.begin(), backend);
2190 if (reduceFp32ToFp16 && hasFp16)
2204 if (assignBackendsResult.
m_Error)
2219 if (backendOptimizationResult.
m_Error)
2244 #if !defined(ARMNN_DISABLE_FILESYSTEM)
2246 ARMNN_LOG(
info) <<
"Intermediate tensors will be written to: " << result;
2260 tensorHandleFactoryRegistry,
2282 const std::vector<BackendId>& backendPreferences,
2285 Optional<std::vector<std::string>&> messages)
2295 const std::vector<BackendId>& backendPreferences,
2298 Optional<std::vector<std::string>&> messages)
2307 bool NetworkImpl::GetShapeInferenceMethod()
2309 bool shapeInferenceMethod =
false;
2313 if (name ==
"InferAndValidate")
2315 shapeInferenceMethod |= value.
AsBool();
2318 return shapeInferenceMethod;
2321 bool NetworkImpl::GetAllowExpandedDims()
2323 bool allowExpandedDims =
false;
2325 ParseOptions(m_NetworkOptions,
"AllowExpandedDims", [&](std::string name,
const BackendOptions::Var& value)
2327 if (name ==
"AllowExpandedDims")
2329 allowExpandedDims |= value.AsBool();
2332 return allowExpandedDims;
2336 : m_NetworkOptions(networkOptions),
2337 m_Graph(
std::make_unique<
Graph>(GetShapeInferenceMethod(), GetAllowExpandedDims()))
2352 return m_Graph->AddLayer<
InputLayer>(id, name);
2363 return m_Graph->AddLayer<
CastLayer>(name);
2374 return m_Graph->AddLayer<
ComparisonLayer>(comparisonDescriptor, name);
2392 return m_Graph->AddLayer<
FillLayer>(fillDescriptor, name);
2404 return m_Graph->AddLayer<
FusedLayer>(fusedDescriptor, name);
2410 return m_Graph->AddLayer<
ConcatLayer>(concatDescriptor, name);
2453 layer->
m_Anchors = std::make_shared<ScopedTensorHandle>(anchors);
2461 return m_Graph->AddLayer<
PermuteLayer>(permuteDescriptor, name);
2467 return m_Graph->AddLayer<
Pooling2dLayer>(pooling2dDescriptor, name);
2473 return m_Graph->AddLayer<
Pooling3dLayer>(pooling3dDescriptor, name);
2479 return m_Graph->AddLayer<
ActivationLayer>(activationDescriptor, name);
2485 return m_Graph->AddLayer<
ArgMinMaxLayer>(argMinMaxDescriptor, name);
2489 normalizationDescriptor,
2497 return m_Graph->AddLayer<
SliceLayer>(sliceDescriptor, name);
2503 return m_Graph->AddLayer<
SoftmaxLayer>(softmaxDescriptor, name);
2509 return m_Graph->AddLayer<
SplitterLayer>(splitterDescriptor, name);
2546 layer->
m_Mean = std::make_shared<ScopedTensorHandle>(mean);
2547 layer->m_Variance = std::make_shared<ScopedTensorHandle>(variance);
2548 layer->m_Beta = std::make_shared<ScopedTensorHandle>(beta);
2549 layer->m_Gamma = std::make_shared<ScopedTensorHandle>(gamma);
2556 return m_Graph->AddLayer<
RankLayer>(name);
2562 return m_Graph->AddLayer<
ReduceLayer>(reduceDescriptor, name);
2567 return m_Graph->AddLayer<
ResizeLayer>(resizeDescriptor, name);
2597 layer->
m_LayerOutput = std::make_shared<ScopedTensorHandle>(input);
2605 return m_Graph->AddLayer<
ReshapeLayer>(reshapeDescriptor, name);
2629 const auto layer = m_Graph->AddLayer<
LstmLayer>(descriptor, name);
2634 layer->m_BasicParameters.m_InputToCellWeights =
2636 layer->m_BasicParameters.m_InputToOutputWeights =
2638 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2640 layer->m_BasicParameters.m_RecurrentToCellWeights =
2642 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2644 layer->m_BasicParameters.m_ForgetGateBias =
2646 layer->m_BasicParameters.m_CellBias =
2647 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2648 layer->m_BasicParameters.m_OutputGateBias =
2657 "when CIFG is disabled.");
2662 "AddLstmLayer: Recurrent To Input Weights cannot be NULL "
2663 "when CIFG is disabled.");
2668 "when CIFG is disabled.");
2670 layer->m_CifgParameters.m_InputToInputWeights =
2672 layer->m_CifgParameters.m_RecurrentToInputWeights =
2674 layer->m_CifgParameters.m_InputGateBias =
2684 "when projection is enabled.");
2686 layer->m_ProjectionParameters.m_ProjectionWeights =
2690 layer->m_ProjectionParameters.m_ProjectionBias =
2703 "when Peephole is enabled and CIFG disabled.");
2706 layer->m_PeepholeParameters.m_CellToInputWeights =
2713 "when Peephole is enabled.");
2718 "when Peephole is enabled.");
2721 layer->m_PeepholeParameters.m_CellToForgetWeights =
2723 layer->m_PeepholeParameters.m_CellToOutputWeights =
2735 "when layer normalization is enabled and CIFG disabled.");
2737 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2744 "when layer normalization is enabled.");
2749 "when layer normalization is enabled.");
2754 "when layer normalization is enabled.");
2756 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2758 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2760 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
2778 return m_Graph->AddLayer<
MeanLayer>(meanDescriptor,name);
2783 return m_Graph->AddLayer<
PadLayer>(padDescriptor,name);
2805 return m_Graph->AddLayer<
GatherLayer>(gatherDescriptor, name);
2840 layer->
m_Weight = std::make_shared<ScopedTensorHandle>(weights);
2844 layer->m_Bias = std::make_shared<ScopedTensorHandle>(biases.
value());
2853 return m_Graph->AddLayer<
TransposeLayer>(transposeDescriptor, name);
2859 return m_Graph->AddLayer<
StackLayer>(stackDescriptor, name);
2877 layer->m_QuantizedLstmParameters.m_InputToForgetWeights =
2879 layer->m_QuantizedLstmParameters.m_InputToCellWeights =
2881 layer->m_QuantizedLstmParameters.m_InputToOutputWeights =
2885 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights =
2887 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights =
2889 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights =
2891 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights =
2895 layer->m_QuantizedLstmParameters.m_InputGateBias =
2897 layer->m_QuantizedLstmParameters.m_ForgetGateBias =
2899 layer->m_QuantizedLstmParameters.m_CellBias =
2900 std::make_shared<ScopedTensorHandle>(params.
GetCellBias());
2901 layer->m_QuantizedLstmParameters.m_OutputGateBias =
2911 const auto layer = m_Graph->AddLayer<
QLstmLayer>(descriptor, name);
2916 layer->m_BasicParameters.m_InputToCellWeights =
2918 layer->m_BasicParameters.m_InputToOutputWeights =
2920 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2922 layer->m_BasicParameters.m_RecurrentToCellWeights =
2924 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2926 layer->m_BasicParameters.m_ForgetGateBias =
2928 layer->m_BasicParameters.m_CellBias =
2929 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2930 layer->m_BasicParameters.m_OutputGateBias =
2944 "AddQLstmLayer: Recurrent To Input Weights cannot be NULL");
2952 layer->m_CifgParameters.m_InputToInputWeights =
2954 layer->m_CifgParameters.m_RecurrentToInputWeights =
2956 layer->m_CifgParameters.m_InputGateBias =
2968 layer->m_ProjectionParameters.m_ProjectionWeights =
2974 layer->m_ProjectionParameters.m_ProjectionBias =
3000 layer->m_PeepholeParameters.m_CellToInputWeights =
3004 layer->m_PeepholeParameters.m_CellToForgetWeights =
3006 layer->m_PeepholeParameters.m_CellToOutputWeights =
3035 layer->m_LayerNormParameters.m_InputLayerNormWeights =
3039 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
3041 layer->m_LayerNormParameters.m_CellLayerNormWeights =
3043 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
3065 layer->m_BasicParameters.m_InputToCellWeights =
3067 layer->m_BasicParameters.m_InputToOutputWeights =
3069 layer->m_BasicParameters.m_RecurrentToForgetWeights =
3071 layer->m_BasicParameters.m_RecurrentToCellWeights =
3073 layer->m_BasicParameters.m_RecurrentToOutputWeights =
3075 layer->m_BasicParameters.m_ForgetGateBias =
3077 layer->m_BasicParameters.m_CellBias =
3078 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
3079 layer->m_BasicParameters.m_OutputGateBias =
3088 "when CIFG is disabled.");
3093 "AddUnidirectionalSequenceLstmLayer: Recurrent To Input Weights cannot be NULL "
3094 "when CIFG is disabled.");
3099 "when CIFG is disabled.");
3101 layer->m_CifgParameters.m_InputToInputWeights =
3103 layer->m_CifgParameters.m_RecurrentToInputWeights =
3105 layer->m_CifgParameters.m_InputGateBias =
3115 "when projection is enabled.");
3117 layer->m_ProjectionParameters.m_ProjectionWeights =
3121 layer->m_ProjectionParameters.m_ProjectionBias =
3134 "cannot be NULL when Peephole is enabled and CIFG disabled.");
3137 layer->m_PeepholeParameters.m_CellToInputWeights =
3144 "when Peephole is enabled.");
3149 "when Peephole is enabled.");
3152 layer->m_PeepholeParameters.m_CellToForgetWeights =
3154 layer->m_PeepholeParameters.m_CellToOutputWeights =
3166 "cannot be NULL when layer normalization is enabled and CIFG disabled.");
3168 layer->m_LayerNormParameters.m_InputLayerNormWeights =
3175 "cannot be NULL when layer normalization is enabled.");
3180 "cannot be NULL when layer normalization is enabled.");
3185 "cannot be NULL when layer normalization is enabled.");
3187 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
3189 layer->m_LayerNormParameters.m_CellLayerNormWeights =
3191 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
3209 return m_Graph->AddLayer<
TileLayer>(desc, name);
3225 layer = m_Graph->AddLayer<
PreCompiledLayer>(preCompiledDescriptor,
"pre-compiled");
3259 layer->ExecuteStrategy(strategy);
3264 : m_Graph(new
Graph(*other.m_Graph.get()))
3265 , m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
3266 , m_ModelOptions(modelOptions)
3271 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
3276 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid()), m_ModelOptions(modelOptions)
3293 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
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
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)
void ApplySme2ShapePolicy(const Graph &graph, bool reduceFp32ToFp16, ModelOptions &modelOptions)
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.