MCPcopy Create free account
hub / github.com/ARM-software/armnn / OptimizeNetwork

Method OptimizeNetwork

tests/ExecuteNetwork/ArmNNExecutor.cpp:581–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579}
580
581armnn::IOptimizedNetworkPtr ArmNNExecutor::OptimizeNetwork(armnn::INetwork* network)
582{
583 armnn::IOptimizedNetworkPtr optNet{nullptr, [](armnn::IOptimizedNetwork*){}};
584
585 armnn::OptimizerOptionsOpaque options;
586 options.SetReduceFp32ToFp16(m_Params.m_EnableFp16TurboMode);
587 options.SetDebugEnabled(m_Params.m_PrintIntermediate);
588 options.SetDebugToFileEnabled(m_Params.m_PrintIntermediateOutputsToFile);
589 options.SetShapeInferenceMethod(m_Params.m_InferOutputShape ?
590 armnn::ShapeInferenceMethod::InferAndValidate :
591 armnn::ShapeInferenceMethod::ValidateOnly);
592 options.SetProfilingEnabled(m_Params.m_EnableProfiling);
593 options.SetAllowExpandedDims(m_Params.m_AllowExpandedDims);
594
595 armnn::BackendOptions gpuAcc("GpuAcc",
596 {
597 { "FastMathEnabled", m_Params.m_EnableFastMath },
598 { "SaveCachedNetwork", m_Params.m_SaveCachedNetwork },
599 { "CachedNetworkFilePath", m_Params.m_CachedNetworkFilePath },
600 { "MLGOTuningFilePath", m_Params.m_MLGOTuningFilePath }
601 });
602
603 armnn::BackendOptions cpuAcc("CpuAcc",
604 {
605 { "FastMathEnabled", m_Params.m_EnableFastMath },
606 { "NumberOfThreads", m_Params.m_NumberOfThreads }
607 });
608 options.AddModelOption(gpuAcc);
609 options.AddModelOption(cpuAcc);
610 // The shapeInferenceMethod and allowExpandedDims values have to be added to the model options
611 // because these are what are passed to the OptimizeSubgraphViews method and are used to create
612 // the new optimized INetwork that method uses
613 armnn::BackendOptions allowExDimOpt("AllowExpandedDims",
614 {
615 { "AllowExpandedDims", m_Params.m_AllowExpandedDims }
616 });
617 options.AddModelOption(allowExDimOpt);
618 armnn::BackendOptions shapeInferOpt("ShapeInferenceMethod",
619 {
620 { "InferAndValidate", m_Params.m_InferOutputShape }
621 });
622 options.AddModelOption(shapeInferOpt);
623
624 const auto optimization_start_time = armnn::GetTimeNow();
625 optNet = armnn::Optimize(*network, m_Params.m_ComputeDevices, m_Runtime->GetDeviceSpec(), options);
626
627 ARMNN_LOG(info) << "Optimization time: " << std::setprecision(2)
628 << std::fixed << armnn::GetTimeDuration(optimization_start_time).count() << " ms\n";
629
630 if (!optNet)
631 {
632 LogAndThrow("Optimize returned nullptr");
633 }
634
635 // If v,visualize-optimized-model is enabled then construct a file name for the dot file.
636 if (m_Params.m_EnableLayerDetails)
637 {
638 fs::path filename = m_Params.m_ModelPath;

Callers

nothing calls this directly

Calls 14

GetTimeNowFunction · 0.85
OptimizeFunction · 0.85
GetTimeDurationFunction · 0.85
LogAndThrowFunction · 0.85
SetReduceFp32ToFp16Method · 0.80
SetDebugEnabledMethod · 0.80
SetDebugToFileEnabledMethod · 0.80
SetProfilingEnabledMethod · 0.80
AddModelOptionMethod · 0.80
SetAllowExpandedDimsMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected