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());
789 Optional<std::vector<std::string>&> errMessages)
791 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>&> errMessages)
857 auto ReturnError = [&](
const Layer* layer)
865 std::string currentReasonIfUnsupported;
871 reasonIfUnsupported += currentReasonIfUnsupported;
875 std::string checkStr =
"This CPU architecture does not support F16 data type, you need v8.2 or above";
876 if (!isLayerSupported || currentReasonIfUnsupported.find(checkStr) != std::string::npos)
884 auto ConstantLayerFromFp16ToFp32 = [](
Layer& layer)
888 ConstantLayer* constantLayer = PolymorphicDowncast<ConstantLayer*>(&layer);
894 std::vector<float> newValues(
info.GetNumElements());
898 info.GetNumElements(),
911 bool checkType =
false;
915 auto connectedOutputSlot = inputSlot.GetConnectedOutputSlot();
918 if (connectedOutputSlot->GetNumConnections() == 1)
921 ConstantLayerFromFp16ToFp32(connectedOutputSlot->GetOwningLayer());
927 std::vector<ConvertFp16ToFp32Layer*> convertFp16ToFp32Layers;
930 convertFp16ToFp32Layers =
935 std::vector<ConvertFp32ToFp16Layer*> convertFp32ToFp16Layers;
938 convertFp32ToFp16Layers =
943 auto AssignFirstSupportedBackend = [&](
Layer* layer,
BackendId preferredBackend)
945 bool supportedBackendFound =
false;
946 std::string reasonIfUnsupported;
952 reasonIfUnsupported))
954 supportedBackendFound =
true;
958 for (
const auto& backend : availablePreferredBackends)
961 if (backend == preferredBackend)
969 reasonIfUnsupported))
971 supportedBackendFound =
true;
977 return supportedBackendFound;
982 if (!AssignFirstSupportedBackend(convertLayer, backend))
984 return ReturnError(convertLayer);
990 if (!AssignFirstSupportedBackend(convertLayer, backend))
992 return ReturnError(convertLayer);
1000 std::stringstream warningMsg;
1002 <<
" is not supported on requested backend " << layer->
GetBackendId().
Get()
1005 <<
" (reason: " << reasonIfUnsupported
1006 <<
"), falling back to the next backend.";
1023 return {dataTypeIn, dataTypeOut};
1027 const std::vector<BackendId>& availablePreferredBackends)
1029 bool hasFp16 =
false;
1031 auto firstBackend = availablePreferredBackends[0];
1032 auto backendObjPtr = backends.find(firstBackend)->second.get();
1035 auto backendCapabilities = backendObjPtr->GetCapabilities();
1041 ARMNN_LOG(
debug) <<
"The first available preferred backend: " << firstBackend
1042 <<
", has FP16 support.";
1046 ARMNN_LOG(
warning) <<
"The first available preferred backend: " << firstBackend
1047 <<
", does not have FP16 support. "
1048 <<
"The FP16 turbo mode option will be disable. It will run using FP32.";
1052 for (
size_t i = 1; i < availablePreferredBackends.size(); ++i)
1054 auto backend = availablePreferredBackends[i];
1055 backendObjPtr = backends.find(backend)->second.get();
1056 backendCapabilities = backendObjPtr->GetCapabilities();
1059 ARMNN_LOG(
warning) <<
"Next preferred backend: " << backend <<
", does not have FP16 support. "
1060 <<
"It will run using FP32 when falling back to this backend.";
1064 ARMNN_LOG(
debug) <<
"Next preferred backend: " << backend <<
", has FP16 support.";
1075 Optional<std::vector<std::string>&> errMessages,
1078 std::vector<BackendId>& availablePreferredBackends)
1080 auto ReturnError = [&](
const Layer* layer)
1085 auto layer = PolymorphicDowncast<Layer*>(it);
1094 std::string reasonIfUnsupported;
1104 if (layer->GetBackendHint().has_value() &&
1109 layer->GetBackendHint().value(),
1112 availablePreferredBackends,
1113 reasonIfUnsupported,
1114 errMessages).
IsOk())
1122 for (
const auto& backend : availablePreferredBackends)
1124 if (layer->GetBackendHint().has_value() &&
1125 layer->GetBackendHint().value() == backend)
1136 availablePreferredBackends,
1137 reasonIfUnsupported,
1168 layer->SetBackendId(cpuBackendId);
1173 result = ReturnError(layer);
1183 Optional<std::vector<std::string>&> errMessages)
1189 if (availablePreferredBackends.empty())
1191 std::stringstream failureMsg;
1192 failureMsg <<
"No preferred backends are available";
1199 for (
auto it = firstLayer; it != lastLayer; ++it)
1201 auto layer = PolymorphicDowncast<Layer*>(*it);
1209 bool isFloat16 =
false;
1210 for (
auto type : inOutDataType)
1219 if (layer->GetBackendId() ==
"Unknown" || isFloat16)
1226 availablePreferredBackends);
1230 for (
auto it = firstLayer; it != lastLayer; ++it)
1232 auto layer = PolymorphicDowncast<Layer*>(*it);
1236 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1237 layer->SetBackendId(connectedBackendId);
1248 Optional<std::vector<std::string>&> errMessages)
1254 if (availablePreferredBackends.empty())
1256 std::stringstream failureMsg;
1257 failureMsg <<
"No preferred backends are available";
1264 for (
auto it = firstLayer; it != lastLayer; ++it)
1271 availablePreferredBackends);
1274 for (
auto it = firstLayer; it != lastLayer; ++it)
1276 auto layer = PolymorphicDowncast<Layer*>(*it);
1280 BackendId connectedBackendId = layer->GetOutputSlot(0).GetConnection(0)->GetOwningLayer().GetBackendId();
1281 layer->SetBackendId(connectedBackendId);
1291 Optional<std::vector<std::string>&> errMessages)
1309 auto backendFactory = backendRegistry.GetFactory(selectedBackend);
1310 auto backendObjPtr = backendFactory();
1312 backendObjPtr->RegisterTensorHandleFactories(handleFactoryRegistry);
1314 backends[backendObjPtr->GetId()] = std::move(backendObjPtr);
1324 Optional<std::vector<std::string>&> errMessages)
1335 auto backendObjPtr = backends.find(selectedBackend)->second.get();
1351 [&backendObjPtr](
const Layer& layer)
1358 if (subgraphs.empty())
1365 for (
auto& subgraph : subgraphs)
1369 OptimizationViews optimizationViews = backendObjPtr->OptimizeSubgraphView(*subgraph, modelOptions);
1370 if (!optimizationViews.
Validate(*subgraph))
1379 SubgraphView& replacementSubgraph = substitution.m_ReplacementSubgraph;
1380 SubgraphView& substitutableSubgraph = substitution.m_SubstitutableSubgraph;
1385 std::for_each(subgraphLayers.begin(), subgraphLayers.end(), [&selectedBackend](
IConnectableLayer* l)
1387 PolymorphicDowncast<Layer*>(l)->SetBackendId(selectedBackend);
1394 for (
auto& l : deletedSubgraph.GetIConnectableLayers())
1396 Layer* deletedLayer = PolymorphicDowncast<Layer*>(l);
1400 OutputSlot* parentOut = inputSlot.GetConnectedOutputSlot();
1415 std::stringstream warningMsg;
1416 warningMsg <<
"Some sub-graph(s) failed to optimized on " << backendObjPtr->GetId() <<
" backend.";
1421 if (!backendObjPtr->GetId().IsCpuRef())
1431 std::stringstream subgraphMsg;
1432 subgraphMsg <<
"Re-assigning backends to " << failedSubgraph.GetIConnectableLayers().size()
1433 <<
" layers inside sub-graph " << count++;
1440 if (reassignmentResult.
m_Error)
1463 if (srcFactory && dstFactory &&
1493 if (frmBackend == backends.end() ||
1494 !frmBackend->second->SupportsTensorAllocatorAPI())
1501 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1508 const Layer& connectedLayer = connection->GetOwningLayer();
1510 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1511 if (toBackend == backends.end())
1516 if (!toBackend->second.get()->SupportsTensorAllocatorAPI())
1522 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1523 for (
auto&& dst : dstPrefs)
1537 auto it = factoryScores.find(dst);
1538 if (it == factoryScores.end())
1541 factoryScores[dst] = 0;
1550 factoryScores[dst]++;
1553 if (factoryScores[dst] > topScore)
1555 topScore = factoryScores[dst];
1584 if (frmBackend == backends.end() ||
1585 !frmBackend->second->SupportsTensorAllocatorAPI())
1590 bool outputConnection =
false;
1593 const Layer& connectedLayer = connection->GetOwningLayer();
1596 outputConnection =
true;
1604 std::map<ITensorHandleFactory::FactoryId, int> factoryScores;
1605 for (
auto&& pref : srcPrefs)
1610 if (outputConnection)
1613 bool fallbackConnection =
false;
1616 if (inputSlot.GetConnectedOutputSlot()->GetOwningLayer().GetBackendId() != layer.
GetBackendId())
1618 fallbackConnection =
true;
1621 if (fallbackConnection)
1625 if (!factoryCap.empty())
1635 if (!outputConnection)
1639 if (!factoryCap.empty())
1658 auto it = factoryScores.find(pref);
1659 if (it == factoryScores.end())
1662 factoryScores[pref] = 0;
1669 const Layer& connectedLayer = connection->GetOwningLayer();
1671 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1672 if (toBackend == backends.end())
1677 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1678 for (
auto&& src : srcPrefs)
1680 if (factoryScores.find(src) == factoryScores.end())
1685 for (
auto&& dst : dstPrefs)
1690 factoryScores[src]++;
1698 int minScore = std::numeric_limits<int>::max();
1699 for (
auto it : factoryScores)
1701 minScore = std::min(minScore, it.second);
1705 std::vector<ITensorHandleFactory::FactoryId> optimalFactories;
1706 for (
auto it : factoryScores)
1708 if (it.second == minScore)
1710 optimalFactories.push_back(it.first);
1715 for (
auto&& srcPref : srcPrefs)
1717 for (
auto&& comp : optimalFactories)
1719 if (comp == srcPref)
1732 const Layer& connectedLayer,
1736 auto toBackend = backends.find(connectedLayer.
GetBackendId());
1737 if (toBackend == backends.end())
1742 auto dstPrefs = toBackend->second.get()->GetHandleFactoryPreferences();
1765 for (
auto&& pref : dstPrefs)
1767 if (pref == srcFactoryId)
1777 for (
auto&& pref : dstPrefs)
1796 if (srcCapability.empty() && dstCapability.empty() && srcFallback.empty() && dstFallback.empty())
1807 for (
auto&& pref : dstPrefs)
1826 Optional<std::vector<std::string>&> errMessages)
1831 optGraph.
ForEachLayer([&backends, ®istry, &result, &errMessages, importEnabled, exportEnabled](
Layer* layer)
1835 if (backends.find(layer->
GetBackendId()) == backends.end())
1837 throw armnn::Exception(
"Backend id not found for the layer");
1850 case LayerType::Input:
1851 slotOption = CalculateSlotOptionForInput(backends, outputSlot, registry, importEnabled);
1853 case LayerType::Output:
1854 slotOption = CalculateSlotOptionForOutput(backends, outputSlot, registry);
1857 slotOption = CalculateSlotOption(backends, outputSlot, registry, exportEnabled);
1863 unsigned int connectionIdx = 0;
1866 const Layer& connectedLayer = connection->GetOwningLayer();
1868 EdgeStrategy strategy = CalculateEdgeStrategy(backends, slotOption, *layer, connectedLayer,
1869 registry, importEnabled);
1871 if (strategy == EdgeStrategy::Undefined)
1873 result.m_Error = true;
1876 errMessages.value().emplace_back(
"Could not find valid strategy required for compatibility"
1877 " between backends.");
1894 const std::vector<BackendId>& backendPreferences,
1897 Optional<std::vector<std::string>&> messages)
1907 const std::vector<BackendId>& backendPreferences,
1910 Optional<std::vector<std::string>&> messages)
1916 ProfilerManager::GetInstance().RegisterProfiler(profiler.get());
1921 std::set<BackendId> backendSet(backendPreferences.begin(), backendPreferences.end());
1923 if (backendSet.find(
"GpuFsa") != backendSet.end() &&
1924 backendSet.find(
"GpuAcc") != backendSet.end())
1927 "for the same optimized network.");
1932 if (backendPreferences.empty())
1940 "Please use the FastMathEnabled backend option for CpuAcc or GpuAcc.");
1951 std::unique_ptr<Graph> graph = std::make_unique<Graph>(inGraph);
1959 optimizedOptions.push_back(importExport);
1962 &IOptimizedNetwork::Destroy);
1975 using namespace optimizations;
2023 if (availablePreferredBackends.empty())
2025 std::stringstream failureMsg;
2026 failureMsg <<
"None of the preferred backends " << backendPreferences
2055 if (assignBackendsResult.
m_Error)
2070 if (backendOptimizationResult.
m_Error)
2095 #if !defined(ARMNN_DISABLE_FILESYSTEM)
2097 ARMNN_LOG(
info) <<
"Intermediate tensors will be written to: " << result;
2111 tensorHandleFactoryRegistry,
2133 const std::vector<BackendId>& backendPreferences,
2136 Optional<std::vector<std::string>&> messages)
2146 const std::vector<BackendId>& backendPreferences,
2149 Optional<std::vector<std::string>&> messages)
2158 bool NetworkImpl::GetShapeInferenceMethod()
2160 bool shapeInferenceMethod =
false;
2162 ParseOptions(m_NetworkOptions,
"ShapeInferenceMethod", [&](std::string name,
const BackendOptions::Var& value)
2164 if (name ==
"InferAndValidate")
2166 shapeInferenceMethod |= value.AsBool();
2169 return shapeInferenceMethod;
2172 bool NetworkImpl::GetAllowExpandedDims()
2174 bool allowExpandedDims =
false;
2176 ParseOptions(m_NetworkOptions,
"AllowExpandedDims", [&](std::string name,
const BackendOptions::Var& value)
2178 if (name ==
"AllowExpandedDims")
2180 allowExpandedDims |= value.AsBool();
2183 return allowExpandedDims;
2187 : m_NetworkOptions(networkOptions),
2188 m_Graph(
std::make_unique<
Graph>(GetShapeInferenceMethod(), GetAllowExpandedDims()))
2203 return m_Graph->AddLayer<
InputLayer>(id, name);
2214 return m_Graph->AddLayer<
CastLayer>(name);
2225 return m_Graph->AddLayer<
ComparisonLayer>(comparisonDescriptor, name);
2243 return m_Graph->AddLayer<
FillLayer>(fillDescriptor, name);
2255 return m_Graph->AddLayer<
FusedLayer>(fusedDescriptor, name);
2261 return m_Graph->AddLayer<
ConcatLayer>(concatDescriptor, name);
2304 layer->
m_Anchors = std::make_shared<ScopedTensorHandle>(anchors);
2312 return m_Graph->AddLayer<
PermuteLayer>(permuteDescriptor, name);
2318 return m_Graph->AddLayer<
Pooling2dLayer>(pooling2dDescriptor, name);
2324 return m_Graph->AddLayer<
Pooling3dLayer>(pooling3dDescriptor, name);
2330 return m_Graph->AddLayer<
ActivationLayer>(activationDescriptor, name);
2336 return m_Graph->AddLayer<
ArgMinMaxLayer>(argMinMaxDescriptor, name);
2340 normalizationDescriptor,
2348 return m_Graph->AddLayer<
SliceLayer>(sliceDescriptor, name);
2354 return m_Graph->AddLayer<
SoftmaxLayer>(softmaxDescriptor, name);
2360 return m_Graph->AddLayer<
SplitterLayer>(splitterDescriptor, name);
2397 layer->
m_Mean = std::make_shared<ScopedTensorHandle>(mean);
2398 layer->m_Variance = std::make_shared<ScopedTensorHandle>(variance);
2399 layer->m_Beta = std::make_shared<ScopedTensorHandle>(beta);
2400 layer->m_Gamma = std::make_shared<ScopedTensorHandle>(gamma);
2407 return m_Graph->AddLayer<
RankLayer>(name);
2413 return m_Graph->AddLayer<
ReduceLayer>(reduceDescriptor, name);
2418 return m_Graph->AddLayer<
ResizeLayer>(resizeDescriptor, name);
2448 layer->
m_LayerOutput = std::make_shared<ScopedTensorHandle>(input);
2456 return m_Graph->AddLayer<
ReshapeLayer>(reshapeDescriptor, name);
2480 const auto layer = m_Graph->AddLayer<
LstmLayer>(descriptor, name);
2485 layer->m_BasicParameters.m_InputToCellWeights =
2487 layer->m_BasicParameters.m_InputToOutputWeights =
2489 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2491 layer->m_BasicParameters.m_RecurrentToCellWeights =
2493 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2495 layer->m_BasicParameters.m_ForgetGateBias =
2497 layer->m_BasicParameters.m_CellBias =
2498 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2499 layer->m_BasicParameters.m_OutputGateBias =
2503 if(!descriptor.m_CifgEnabled)
2508 "when CIFG is disabled.");
2513 "AddLstmLayer: Recurrent To Input Weights cannot be NULL "
2514 "when CIFG is disabled.");
2519 "when CIFG is disabled.");
2521 layer->m_CifgParameters.m_InputToInputWeights =
2523 layer->m_CifgParameters.m_RecurrentToInputWeights =
2525 layer->m_CifgParameters.m_InputGateBias =
2530 if(descriptor.m_ProjectionEnabled)
2535 "when projection is enabled.");
2537 layer->m_ProjectionParameters.m_ProjectionWeights =
2541 layer->m_ProjectionParameters.m_ProjectionBias =
2547 if(descriptor.m_PeepholeEnabled)
2549 if(!descriptor.m_CifgEnabled)
2554 "when Peephole is enabled and CIFG disabled.");
2557 layer->m_PeepholeParameters.m_CellToInputWeights =
2564 "when Peephole is enabled.");
2569 "when Peephole is enabled.");
2572 layer->m_PeepholeParameters.m_CellToForgetWeights =
2574 layer->m_PeepholeParameters.m_CellToOutputWeights =
2579 if(descriptor.m_LayerNormEnabled)
2581 if(!descriptor.m_CifgEnabled)
2586 "when layer normalization is enabled and CIFG disabled.");
2588 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2595 "when layer normalization is enabled.");
2600 "when layer normalization is enabled.");
2605 "when layer normalization is enabled.");
2607 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2609 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2611 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
2629 return m_Graph->AddLayer<
MeanLayer>(meanDescriptor,name);
2634 return m_Graph->AddLayer<
PadLayer>(padDescriptor,name);
2656 return m_Graph->AddLayer<
GatherLayer>(gatherDescriptor, name);
2691 layer->
m_Weight = std::make_shared<ScopedTensorHandle>(weights);
2693 if (descriptor.m_BiasEnabled)
2695 layer->m_Bias = std::make_shared<ScopedTensorHandle>(biases.
value());
2704 return m_Graph->AddLayer<
TransposeLayer>(transposeDescriptor, name);
2710 return m_Graph->AddLayer<
StackLayer>(stackDescriptor, name);
2728 layer->m_QuantizedLstmParameters.m_InputToForgetWeights =
2730 layer->m_QuantizedLstmParameters.m_InputToCellWeights =
2732 layer->m_QuantizedLstmParameters.m_InputToOutputWeights =
2736 layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights =
2738 layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights =
2740 layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights =
2742 layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights =
2746 layer->m_QuantizedLstmParameters.m_InputGateBias =
2748 layer->m_QuantizedLstmParameters.m_ForgetGateBias =
2750 layer->m_QuantizedLstmParameters.m_CellBias =
2751 std::make_shared<ScopedTensorHandle>(params.
GetCellBias());
2752 layer->m_QuantizedLstmParameters.m_OutputGateBias =
2762 const auto layer = m_Graph->AddLayer<
QLstmLayer>(descriptor, name);
2767 layer->m_BasicParameters.m_InputToCellWeights =
2769 layer->m_BasicParameters.m_InputToOutputWeights =
2771 layer->m_BasicParameters.m_RecurrentToForgetWeights =
2773 layer->m_BasicParameters.m_RecurrentToCellWeights =
2775 layer->m_BasicParameters.m_RecurrentToOutputWeights =
2777 layer->m_BasicParameters.m_ForgetGateBias =
2779 layer->m_BasicParameters.m_CellBias =
2780 std::make_shared<ScopedTensorHandle>(*(params.
m_CellBias));
2781 layer->m_BasicParameters.m_OutputGateBias =
2785 if(!descriptor.m_CifgEnabled)
2795 "AddQLstmLayer: Recurrent To Input Weights cannot be NULL");
2803 layer->m_CifgParameters.m_InputToInputWeights =
2805 layer->m_CifgParameters.m_RecurrentToInputWeights =
2807 layer->m_CifgParameters.m_InputGateBias =
2812 if(descriptor.m_ProjectionEnabled)
2819 layer->m_ProjectionParameters.m_ProjectionWeights =
2825 layer->m_ProjectionParameters.m_ProjectionBias =
2832 if(descriptor.m_PeepholeEnabled)
2844 if(!descriptor.m_CifgEnabled)
2851 layer->m_PeepholeParameters.m_CellToInputWeights =
2855 layer->m_PeepholeParameters.m_CellToForgetWeights =
2857 layer->m_PeepholeParameters.m_CellToOutputWeights =
2862 if(descriptor.m_LayerNormEnabled)
2879 if(!descriptor.m_CifgEnabled)
2886 layer->m_LayerNormParameters.m_InputLayerNormWeights =
2890 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
2892 layer->m_LayerNormParameters.m_CellLayerNormWeights =
2894 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
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 =
2934 if(!descriptor.m_CifgEnabled)
2939 "when CIFG is disabled.");
2944 "AddUnidirectionalSequenceLstmLayer: Recurrent To Input Weights cannot be NULL "
2945 "when CIFG is disabled.");
2950 "when CIFG is disabled.");
2952 layer->m_CifgParameters.m_InputToInputWeights =
2954 layer->m_CifgParameters.m_RecurrentToInputWeights =
2956 layer->m_CifgParameters.m_InputGateBias =
2961 if(descriptor.m_ProjectionEnabled)
2966 "when projection is enabled.");
2968 layer->m_ProjectionParameters.m_ProjectionWeights =
2972 layer->m_ProjectionParameters.m_ProjectionBias =
2978 if(descriptor.m_PeepholeEnabled)
2980 if(!descriptor.m_CifgEnabled)
2985 "cannot be NULL when Peephole is enabled and CIFG disabled.");
2988 layer->m_PeepholeParameters.m_CellToInputWeights =
2995 "when Peephole is enabled.");
3000 "when Peephole is enabled.");
3003 layer->m_PeepholeParameters.m_CellToForgetWeights =
3005 layer->m_PeepholeParameters.m_CellToOutputWeights =
3010 if(descriptor.m_LayerNormEnabled)
3012 if(!descriptor.m_CifgEnabled)
3017 "cannot be NULL when layer normalization is enabled and CIFG disabled.");
3019 layer->m_LayerNormParameters.m_InputLayerNormWeights =
3026 "cannot be NULL when layer normalization is enabled.");
3031 "cannot be NULL when layer normalization is enabled.");
3036 "cannot be NULL when layer normalization is enabled.");
3038 layer->m_LayerNormParameters.m_ForgetLayerNormWeights =
3040 layer->m_LayerNormParameters.m_CellLayerNormWeights =
3042 layer->m_LayerNormParameters.m_OutputLayerNormWeights =
3060 return m_Graph->AddLayer<
TileLayer>(desc, name);
3076 layer = m_Graph->AddLayer<
PreCompiledLayer>(preCompiledDescriptor,
"pre-compiled");
3110 layer->ExecuteStrategy(strategy);
3115 : m_Graph(new
Graph(*other.m_Graph.get()))
3116 , m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
3117 , m_ModelOptions(modelOptions)
3122 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
3127 : m_Graph(
std::move(graph)), m_Guid(
arm::pipe::IProfilingService::GetNextGuid()), m_ModelOptions(modelOptions)
3144 layer->ExecuteStrategy(strategy);