IVGCVSW-6292 Allow profiling details to be switched off during profiling

 * Add switch for network details during profiling

Signed-off-by: Keith Davis <keith.davis@arm.com>
Change-Id: I8bd49fd58f0e0255598106e9ab36806ee78391d6
diff --git a/include/armnn/IProfiler.hpp b/include/armnn/IProfiler.hpp
index 5ce4201..5fbb670 100644
--- a/include/armnn/IProfiler.hpp
+++ b/include/armnn/IProfiler.hpp
@@ -39,6 +39,10 @@
     /// @param [out] outStream The stream where to write the profiling results to.
     void Print(std::ostream& outStream) const;
 
+    /// Print out details of each layer within the network that possesses a descriptor.
+    /// Also outputs tensor info.
+    void EnableNetworkDetailsToStdOut();
+
     ~IProfiler();
     IProfiler();
 
diff --git a/include/armnn/IRuntime.hpp b/include/armnn/IRuntime.hpp
index 1bae943..8c269de 100644
--- a/include/armnn/IRuntime.hpp
+++ b/include/armnn/IRuntime.hpp
@@ -39,36 +39,40 @@
           m_ExportEnabled(exportEnabled),
           m_AsyncEnabled(asyncEnabled),
           m_ProfilingEnabled(profilingEnabled),
+          m_OutputNetworkDetails(false),
           m_InputSource(m_ImportEnabled ? MemorySource::Malloc : MemorySource::Undefined),
           m_OutputSource(m_ExportEnabled ? MemorySource::Malloc : MemorySource::Undefined)
     {}
 
     ARMNN_DEPRECATED_MSG("Please use INetworkProperties constructor without numThreads argument")
     INetworkProperties(bool asyncEnabled,
-                       MemorySource m_InputSource,
-                       MemorySource m_OutputSource,
+                       MemorySource inputSource,
+                       MemorySource outputSource,
                        size_t numThreads,
                        bool profilingEnabled = false)
-        : m_ImportEnabled(m_InputSource != MemorySource::Undefined),
-          m_ExportEnabled(m_OutputSource != MemorySource::Undefined),
+        : m_ImportEnabled(inputSource != MemorySource::Undefined),
+          m_ExportEnabled(outputSource != MemorySource::Undefined),
           m_AsyncEnabled(asyncEnabled),
           m_ProfilingEnabled(profilingEnabled),
-          m_InputSource(m_InputSource),
-          m_OutputSource(m_OutputSource)
+          m_OutputNetworkDetails(false),
+          m_InputSource(inputSource),
+          m_OutputSource(outputSource)
     {
         armnn::IgnoreUnused(numThreads);
     }
 
     INetworkProperties(bool asyncEnabled,
-                       MemorySource m_InputSource,
-                       MemorySource m_OutputSource,
-                       bool profilingEnabled = false)
-        : m_ImportEnabled(m_InputSource != MemorySource::Undefined),
-          m_ExportEnabled(m_OutputSource != MemorySource::Undefined),
+                       MemorySource inputSource,
+                       MemorySource outputSource,
+                       bool profilingEnabled = false,
+                       bool outputDetails = false)
+        : m_ImportEnabled(inputSource != MemorySource::Undefined),
+          m_ExportEnabled(outputSource != MemorySource::Undefined),
           m_AsyncEnabled(asyncEnabled),
           m_ProfilingEnabled(profilingEnabled),
-          m_InputSource(m_InputSource),
-          m_OutputSource(m_OutputSource)
+          m_OutputNetworkDetails(outputDetails),
+          m_InputSource(inputSource),
+          m_OutputSource(outputSource)
     {}
 
     /// Deprecated and will be removed in future release.
@@ -80,6 +84,8 @@
 
     const bool m_ProfilingEnabled;
 
+    const bool m_OutputNetworkDetails;
+
     const MemorySource m_InputSource;
     const MemorySource m_OutputSource;
 
diff --git a/src/armnn/LoadedNetwork.cpp b/src/armnn/LoadedNetwork.cpp
index c8dbcaa..70b5f4e 100644
--- a/src/armnn/LoadedNetwork.cpp
+++ b/src/armnn/LoadedNetwork.cpp
@@ -127,6 +127,8 @@
 
     m_Profiler->EnableProfiling(networkProperties.m_ProfilingEnabled);
 
+    if (networkProperties.m_OutputNetworkDetails) m_Profiler->EnableNetworkDetailsToStdOut();
+
     Graph& order = m_OptimizedNetwork->pOptimizedNetworkImpl->GetGraph().TopologicalSort();
     //First create tensor handlers, backends and workload factories.
     //Handlers are created before workloads are.
diff --git a/src/armnn/Profiling.cpp b/src/armnn/Profiling.cpp
index 509e9de..b9afc86 100644
--- a/src/armnn/Profiling.cpp
+++ b/src/armnn/Profiling.cpp
@@ -196,6 +196,11 @@
     m_ProfilingEnabled = enableProfiling;
 }
 
+void ProfilerImpl::EnableNetworkDetailsToStdOut()
+{
+    m_EnableDetailsToStdOut = true;
+}
+
 Event* ProfilerImpl::BeginEvent(armnn::IProfiler* profiler,
                                 const BackendId& backendId,
                                 const std::string& label,
@@ -378,7 +383,7 @@
     printer.PrintHeader();
     printer.PrintArmNNHeader();
 
-    if (m_ProfilingDetails.get()->DetailsExist())
+    if (m_ProfilingDetails.get()->DetailsExist() && m_EnableDetailsToStdOut)
     {
         JsonChildObject detailsObject{ "layer_details" };
         ConfigureDetailsObject(detailsObject, m_ProfilingDetails.get()->GetProfilingDetails());
@@ -539,6 +544,11 @@
     pProfilerImpl->EnableProfiling(enableProfiling);
 }
 
+void IProfiler::EnableNetworkDetailsToStdOut()
+{
+    pProfilerImpl->EnableNetworkDetailsToStdOut();
+}
+
 bool IProfiler::IsProfilingEnabled()
 {
     return pProfilerImpl->IsProfilingEnabled();
diff --git a/src/armnn/Profiling.hpp b/src/armnn/Profiling.hpp
index a336a0e..372b489 100644
--- a/src/armnn/Profiling.hpp
+++ b/src/armnn/Profiling.hpp
@@ -59,6 +59,9 @@
     // Checks if profiling is enabled.
     bool IsProfilingEnabled();
 
+    // Enables outputting the layer descriptors and infos to stdout
+    void EnableNetworkDetailsToStdOut();
+
     // Increments the event tag, allowing grouping of events in a user-defined manner (e.g. per inference).
     void UpdateEventTag();
 
@@ -99,6 +102,7 @@
     std::vector<EventPtr> m_EventSequence;
     DescPtr m_ProfilingDetails = std::make_unique<ProfilingDetails>();
     bool m_ProfilingEnabled;
+    bool m_EnableDetailsToStdOut;
 };
 
 // Singleton profiler manager.
diff --git a/src/backends/reference/workloads/RefConvolution2dWorkload.cpp b/src/backends/reference/workloads/RefConvolution2dWorkload.cpp
index b0b88b1..20c5c08 100644
--- a/src/backends/reference/workloads/RefConvolution2dWorkload.cpp
+++ b/src/backends/reference/workloads/RefConvolution2dWorkload.cpp
@@ -26,7 +26,7 @@
     }
 
     // Report Profiling Details
-    ARMNN_REPORT_PROFILING_WORKLOAD_DESC("RefConvolution2dWorkload_Execute",
+    ARMNN_REPORT_PROFILING_WORKLOAD_DESC("RefConvolution2dWorkload_Construct",
                                          descriptor.m_Parameters,
                                          detailsInfo,
                                          this->GetGuid());
diff --git a/tests/ExecuteNetwork/ExecuteNetwork.cpp b/tests/ExecuteNetwork/ExecuteNetwork.cpp
index e757d2c..64296d3 100644
--- a/tests/ExecuteNetwork/ExecuteNetwork.cpp
+++ b/tests/ExecuteNetwork/ExecuteNetwork.cpp
@@ -324,6 +324,7 @@
         inferenceModelParams.m_MLGOTuningFilePath             = params.m_MLGOTuningFilePath;
         inferenceModelParams.m_AsyncEnabled                   = params.m_Concurrent;
         inferenceModelParams.m_ThreadPoolSize                 = params.m_ThreadPoolSize;
+        inferenceModelParams.m_OutputDetailsToStdOut          = params.m_OutputDetailsToStdOut;
 
         for(const std::string& inputName: params.m_InputNames)
         {
@@ -768,6 +769,12 @@
         return EXIT_FAILURE;
     }
 
+    if (ProgramOptions.m_ExNetParams.m_OutputDetailsToStdOut && !ProgramOptions.m_ExNetParams.m_EnableProfiling)
+    {
+        ARMNN_LOG(fatal) << "You must enable profiling if you would like to output layer details";
+        return EXIT_FAILURE;
+    }
+
     // Create runtime
     std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(ProgramOptions.m_RuntimeOptions));
 
diff --git a/tests/ExecuteNetwork/ExecuteNetworkParams.hpp b/tests/ExecuteNetwork/ExecuteNetworkParams.hpp
index fe0c446..97c605b 100644
--- a/tests/ExecuteNetwork/ExecuteNetworkParams.hpp
+++ b/tests/ExecuteNetwork/ExecuteNetworkParams.hpp
@@ -43,6 +43,7 @@
     std::string                   m_ModelFormat;
     std::string                   m_ModelPath;
     unsigned int                  m_NumberOfThreads;
+    bool                          m_OutputDetailsToStdOut;
     std::vector<std::string>      m_OutputNames;
     std::vector<std::string>      m_OutputTensorFiles;
     std::vector<std::string>      m_OutputTypes;
diff --git a/tests/ExecuteNetwork/ExecuteNetworkProgramOptions.cpp b/tests/ExecuteNetwork/ExecuteNetworkProgramOptions.cpp
index 6ac64ff..1fd4b3d 100644
--- a/tests/ExecuteNetwork/ExecuteNetworkProgramOptions.cpp
+++ b/tests/ExecuteNetwork/ExecuteNetworkProgramOptions.cpp
@@ -407,7 +407,12 @@
 
                 ("u,counter-capture-period",
                  "If profiling is enabled in 'file-only' mode this is the capture period that will be used in the test",
-                 cxxopts::value<uint32_t>(m_RuntimeOptions.m_ProfilingOptions.m_CapturePeriod)->default_value("150"));
+                 cxxopts::value<uint32_t>(m_RuntimeOptions.m_ProfilingOptions.m_CapturePeriod)->default_value("150"))
+
+                ("output-network-details",
+                 "Outputs layer tensor infos and descriptors to std out. Defaults to off.",
+                 cxxopts::value<bool>(m_ExNetParams.m_OutputDetailsToStdOut)->default_value("false")
+                                                                            ->implicit_value("true"));
     }
     catch (const std::exception& e)
     {
diff --git a/tests/InferenceModel.hpp b/tests/InferenceModel.hpp
index 4d2b167..1db287f 100644
--- a/tests/InferenceModel.hpp
+++ b/tests/InferenceModel.hpp
@@ -100,6 +100,7 @@
     bool                            m_InferOutputShape;
     bool                            m_EnableFastMath;
     bool                            m_SaveCachedNetwork;
+    bool                            m_OutputDetailsToStdOut;
     std::string                     m_CachedNetworkFilePath;
     unsigned int                    m_NumberOfThreads;
     std::string                     m_MLGOTuningFilePath;
@@ -119,6 +120,7 @@
         , m_InferOutputShape(false)
         , m_EnableFastMath(false)
         , m_SaveCachedNetwork(false)
+        , m_OutputDetailsToStdOut(false)
         , m_CachedNetworkFilePath("")
         , m_NumberOfThreads(0)
         , m_MLGOTuningFilePath("")
@@ -489,7 +491,8 @@
             armnn::INetworkProperties networkProperties(params.m_AsyncEnabled,
                                                         armnn::MemorySource::Undefined,
                                                         armnn::MemorySource::Undefined,
-                                                        enableProfiling);
+                                                        enableProfiling,
+                                                        params.m_OutputDetailsToStdOut);
             std::string errorMessage;
             ret = m_Runtime->LoadNetwork(m_NetworkIdentifier, std::move(optNet), errorMessage, networkProperties);