MLECO-755: ArmNN: Add file format external profiling option
authorIsabella Gottardi <isabella.gottardi@arm.com>
Wed, 11 Mar 2020 18:04:20 +0000 (18:04 +0000)
committerIsabella Gottardi <isabella.gottardi@arm.com>
Thu, 19 Mar 2020 18:25:33 +0000 (18:25 +0000)
* Added new m_FileFormat variable in ExternalProfilingOptions
* Added new profiling option to ExecuteNetwork
* Added check for file format in ProfilingConnectionFactory
* Added test in profiling tests

Change-Id: I0e9cb8ecac919dc0ed03dcf77324a65621f07ae7
Signed-off-by: Isabella Gottardi <isabella.gottardi@arm.com>
include/armnn/IRuntime.hpp
src/profiling/ProfilingConnectionFactory.cpp
src/profiling/test/ProfilingTests.cpp
tests/ExecuteNetwork/ExecuteNetwork.cpp

index 712355bb3aa920b6b63765af80db39c5329ec03c..8391ed3b15c156582aec5d69cc8eddff20afb628 100644 (file)
@@ -65,6 +65,7 @@ public:
                 , m_IncomingCaptureFile("")
                 , m_FileOnly(false)
                 , m_CapturePeriod(LOWEST_CAPTURE_PERIOD)
+                , m_FileFormat("binary")
             {}
 
             bool        m_EnableProfiling;
@@ -72,6 +73,7 @@ public:
             std::string m_IncomingCaptureFile;
             bool        m_FileOnly;
             uint32_t    m_CapturePeriod;
+            std::string m_FileFormat;
         };
         ExternalProfilingOptions m_ProfilingOptions;
 
index 4af81a024e63a1db63fc6e182829c05d30b94a5b..1d264def578cce322ede2a0d86fe787b11b9c434 100644 (file)
@@ -18,6 +18,12 @@ namespace profiling
 std::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection(
     const Runtime::CreationOptions::ExternalProfilingOptions& options) const
 {
+    // Before proceed to create the IProfilingConnection, check if the file format is supported
+    if (!(options.m_FileFormat == "binary"))
+    {
+        throw armnn::UnimplementedException("Unsupported profiling file format, only binary is supported");
+    }
+
     // We can create 3 different types of IProfilingConnection.
     // 1: If no relevant options are specified then a SocketProfilingConnection is returned.
     // 2: If both incoming and outgoing capture files are specified then a SocketProfilingConnection decorated by a
index 29c5299bd313c5bb9cf0a75a43747554233ca438..a631cb23560dcc82ed7641775c619cc63ada3501 100644 (file)
@@ -3448,4 +3448,41 @@ BOOST_AUTO_TEST_CASE(CheckRegisterCounters)
     BOOST_TEST(93 == readValue);
 }
 
+BOOST_AUTO_TEST_CASE(CheckFileFormat) {
+    // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
+    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
+
+    // Create profiling options.
+    armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+    options.m_EnableProfiling = true;
+    // Check the default value set to binary
+    BOOST_CHECK(options.m_FileFormat == "binary");
+
+    // Change file format to an unsupported value
+    options.m_FileFormat = "json";
+    // Enable the profiling service
+    armnn::profiling::ProfilingService profilingService;
+    profilingService.ResetExternalProfilingOptions(options, true);
+    // Start the command handler and the send thread
+    profilingService.Update();
+    BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::NotConnected);
+
+    // Redirect the output to a local stream so that we can parse the warning message
+    std::stringstream ss;
+    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
+
+    // When Update is called and the current state is ProfilingState::NotConnected
+    // an exception will be raised from GetProfilingConnection and displayed as warning in the output local stream
+    profilingService.Update();
+
+    streamRedirector.CancelRedirect();
+
+    // Check that the expected error has occurred and logged to the standard output
+    if (!boost::contains(ss.str(), "Unsupported profiling file format, only binary is supported"))
+    {
+        std::cout << ss.str();
+        BOOST_FAIL("Expected string not found.");
+    }
+}
+
 BOOST_AUTO_TEST_SUITE_END()
index 3c0301010d1575e84843fe5ed7698f63901ed8c2..3a63fffeaeafa32e681133536944382f0e11749d 100644 (file)
@@ -33,6 +33,7 @@ int main(int argc, const char* argv[])
     std::string outgoingCaptureFile;
     std::string incomingCaptureFile;
     uint32_t counterCapturePeriod;
+    std::string fileFormat;
 
     double thresholdTime = 0.0;
 
@@ -114,6 +115,8 @@ int main(int argc, const char* argv[])
              "If enabled then the 'file-only' test mode of external profiling will be enabled")
             ("counter-capture-period,u", po::value<uint32_t>(&counterCapturePeriod)->default_value(150u),
              "If profiling is enabled in 'file-only' mode this is the capture period that will be used in the test")
+            ("file-format,ff", po::value(&fileFormat),
+             "If profiling is enabled specifies the output file format")
             ("parse-unsupported", po::bool_switch()->default_value(false),
                 "Add unsupported operators as stand-in layers (where supported by parser)");
     }
@@ -187,13 +190,14 @@ int main(int argc, const char* argv[])
 
         // Create runtime
         armnn::IRuntime::CreationOptions options;
-        options.m_EnableGpuProfiling = enableProfiling;
-        options.m_DynamicBackendsPath = dynamicBackendsPath;
-        options.m_ProfilingOptions.m_EnableProfiling = enableExternalProfiling;
+        options.m_EnableGpuProfiling                     = enableProfiling;
+        options.m_DynamicBackendsPath                    = dynamicBackendsPath;
+        options.m_ProfilingOptions.m_EnableProfiling     = enableExternalProfiling;
         options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile;
         options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
-        options.m_ProfilingOptions.m_FileOnly = fileOnlyExternalProfiling;
-        options.m_ProfilingOptions.m_CapturePeriod = counterCapturePeriod;
+        options.m_ProfilingOptions.m_FileOnly            = fileOnlyExternalProfiling;
+        options.m_ProfilingOptions.m_CapturePeriod       = counterCapturePeriod;
+        options.m_ProfilingOptions.m_FileFormat          = fileFormat;
         std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options));
 
         const std::string executableName("ExecuteNetwork");
@@ -271,6 +275,7 @@ int main(int argc, const char* argv[])
         options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
         options.m_ProfilingOptions.m_FileOnly            = fileOnlyExternalProfiling;
         options.m_ProfilingOptions.m_CapturePeriod       = counterCapturePeriod;
+        options.m_ProfilingOptions.m_FileFormat          = fileFormat;
         std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options));
 
         return RunTest(modelFormat, inputTensorShapes, computeDevices, dynamicBackendsPath, modelPath, inputNames,