From 4d3a24bc3a4900db8a647881b0b3a7a6bf387751 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 13 Dec 2019 14:43:24 +0000 Subject: IVGCVSW-4270 Change .dot file name to start with netId * .dot file will start with the same number as the associated input and output tensor dump files Change-Id: Ic64539854c2b8c34a7034fa18a142b2dfe67df7d Signed-off-by: Jim Flynn --- 1.2/ArmnnDriverImpl.cpp | 11 ++++++----- ArmnnDriverImpl.cpp | 8 ++++---- Utils.cpp | 33 +++++++++++++++++++++++++++++++++ Utils.hpp | 38 +------------------------------------- test/UtilsTests.cpp | 34 ++++++++++++++-------------------- 5 files changed, 58 insertions(+), 66 deletions(-) diff --git a/1.2/ArmnnDriverImpl.cpp b/1.2/ArmnnDriverImpl.cpp index 0d54c7ff..951be815 100644 --- a/1.2/ArmnnDriverImpl.cpp +++ b/1.2/ArmnnDriverImpl.cpp @@ -148,11 +148,6 @@ Return ArmnnDriverImpl::prepareArmnnModel_1_2(const armnn::IRuntime return ErrorStatus::NONE; } - // Export the optimized network graph to a dot file if an output dump directory - // has been specified in the drivers' arguments. - ExportNetworkGraphToDotFile(*optNet, options.GetRequestInputsAndOutputsDumpDir(), - model); - // Load it into the runtime. armnn::NetworkId netId = 0; try @@ -170,6 +165,12 @@ Return ArmnnDriverImpl::prepareArmnnModel_1_2(const armnn::IRuntime return ErrorStatus::NONE; } + // Export the optimized network graph to a dot file if an output dump directory + // has been specified in the drivers' arguments. + ExportNetworkGraphToDotFile(*optNet, + options.GetRequestInputsAndOutputsDumpDir(), + netId); + std::unique_ptr> preparedModel( new ArmnnPreparedModel_1_2( netId, diff --git a/ArmnnDriverImpl.cpp b/ArmnnDriverImpl.cpp index d5fa9784..df04ef9c 100644 --- a/ArmnnDriverImpl.cpp +++ b/ArmnnDriverImpl.cpp @@ -129,10 +129,6 @@ Return ArmnnDriverImpl::prepareModel( return ErrorStatus::NONE; } - // Export the optimized network graph to a dot file if an output dump directory - // has been specified in the drivers' arguments. - ExportNetworkGraphToDotFile(*optNet, options.GetRequestInputsAndOutputsDumpDir(), model); - // Load it into the runtime. armnn::NetworkId netId = 0; try @@ -150,6 +146,10 @@ Return ArmnnDriverImpl::prepareModel( return ErrorStatus::NONE; } + // Export the optimized network graph to a dot file if an output dump directory + // has been specified in the drivers' arguments. + ExportNetworkGraphToDotFile(*optNet, options.GetRequestInputsAndOutputsDumpDir(), netId); + unique_ptr> preparedModel( new ArmnnPreparedModel( netId, diff --git a/Utils.cpp b/Utils.cpp index 8af12a32..20a2f70f 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -343,6 +343,39 @@ void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled, profiler->Print(fileStream); } +void ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork, + const std::string& dumpDir, + const armnn::NetworkId networkId) +{ + // The dump directory must exist in advance. + if (dumpDir.empty()) + { + return; + } + + // Set the name of the output .dot file. + const std::string fileName = boost::str(boost::format("%1%/%2%_networkgraph.dot") + % dumpDir + % std::to_string(networkId)); + + ALOGV("Exporting the optimized network graph to file: %s", fileName.c_str()); + + // Write the network graph to a dot file. + std::ofstream fileStream; + fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc); + + if (!fileStream.good()) + { + ALOGW("Could not open file %s for writing", fileName.c_str()); + return; + } + + if (optimizedNetwork.SerializeToDot(fileStream) != armnn::Status::Success) + { + ALOGW("An error occurred when writing to file %s", fileName.c_str()); + } +} + bool IsDynamicTensor(const armnn::TensorInfo& outputInfo) { // Dynamic tensors have at least one 0-sized dimension diff --git a/Utils.hpp b/Utils.hpp index 267e519e..bfda6a66 100644 --- a/Utils.hpp +++ b/Utils.hpp @@ -104,45 +104,9 @@ void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled, armnn::NetworkId networkId, const armnn::IProfiler* profiler); -template void ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork, const std::string& dumpDir, - const HalModel& model) -{ - // The dump directory must exist in advance. - if (dumpDir.empty()) - { - return; - } - - // Get the memory address of the model and convert it to a hex string (of at least a '0' character). - size_t modelAddress = uintptr_t(&model); - std::stringstream ss; - ss << std::uppercase << std::hex << std::setfill('0') << std::setw(1) << modelAddress; - std::string modelAddressHexString = ss.str(); - - // Set the name of the output .dot file. - const std::string fileName = boost::str(boost::format("%1%/networkgraph_%2%.dot") - % dumpDir - % modelAddressHexString); - - ALOGV("Exporting the optimized network graph to file: %s", fileName.c_str()); - - // Write the network graph to a dot file. - std::ofstream fileStream; - fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc); - - if (!fileStream.good()) - { - ALOGW("Could not open file %s for writing", fileName.c_str()); - return; - } - - if (optimizedNetwork.SerializeToDot(fileStream) != armnn::Status::Success) - { - ALOGW("An error occurred when writing to file %s", fileName.c_str()); - } -} + const armnn::NetworkId networkId); /// Checks if a tensor info represents a dynamic tensor bool IsDynamicTensor(const armnn::TensorInfo& outputInfo); diff --git a/test/UtilsTests.cpp b/test/UtilsTests.cpp index 6ac1ebb0..6ece4e26 100644 --- a/test/UtilsTests.cpp +++ b/test/UtilsTests.cpp @@ -31,24 +31,18 @@ public: // Setup: set the output dump directory and an empty dummy model (as only its memory address is used). // Defaulting the output dump directory to "/data" because it should exist and be writable in all deployments. ExportNetworkGraphFixture() - : ExportNetworkGraphFixture("/data") + : ExportNetworkGraphFixture("/data", 1) {} - ExportNetworkGraphFixture(const std::string& requestInputsAndOutputsDumpDir) + ExportNetworkGraphFixture(const std::string& requestInputsAndOutputsDumpDir, armnn::NetworkId networkId) : m_RequestInputsAndOutputsDumpDir(requestInputsAndOutputsDumpDir) - , m_Model({}) + , m_NetworkId(networkId) , m_FileName() , m_FileStream() { - // Get the memory address of the model and convert it to a hex string (of at least a '0' character). - size_t modelAddress = uintptr_t(&m_Model); - std::stringstream ss; - ss << std::uppercase << std::hex << std::setfill('0') << std::setw(1) << modelAddress; - std::string modelAddressHexString = ss.str(); - // Set the name of the output .dot file. - m_FileName = boost::str(boost::format("%1%/networkgraph_%2%.dot") + m_FileName = boost::str(boost::format("%1%/%2%_networkgraph.dot") % m_RequestInputsAndOutputsDumpDir - % modelAddressHexString); + % std::to_string(m_NetworkId)); } // Teardown: delete the dump file regardless of the outcome of the tests. @@ -96,7 +90,7 @@ public: } std::string m_RequestInputsAndOutputsDumpDir; - V1_0::Model m_Model; + armnn::NetworkId m_NetworkId; private: std::string m_FileName; @@ -133,7 +127,7 @@ private: BOOST_AUTO_TEST_CASE(ExportToEmptyDirectory) { // Set the fixture for this test. - ExportNetworkGraphFixture fixture(""); + ExportNetworkGraphFixture fixture("", 0); // Set a mock content for the optimized network. std::string mockSerializedContent = "This is a mock serialized content."; @@ -144,7 +138,7 @@ BOOST_AUTO_TEST_CASE(ExportToEmptyDirectory) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture.m_RequestInputsAndOutputsDumpDir, - fixture.m_Model); + 0); // Check that the output file does not exist. BOOST_TEST(!fixture.FileExists()); @@ -164,7 +158,7 @@ BOOST_AUTO_TEST_CASE(ExportNetwork) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture.m_RequestInputsAndOutputsDumpDir, - fixture.m_Model); + fixture.m_NetworkId); // Check that the output file exists and that it has the correct name. BOOST_TEST(fixture.FileExists()); @@ -187,7 +181,7 @@ BOOST_AUTO_TEST_CASE(ExportNetworkOverwriteFile) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture.m_RequestInputsAndOutputsDumpDir, - fixture.m_Model); + fixture.m_NetworkId); // Check that the output file exists and that it has the correct name. BOOST_TEST(fixture.FileExists()); @@ -202,7 +196,7 @@ BOOST_AUTO_TEST_CASE(ExportNetworkOverwriteFile) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture.m_RequestInputsAndOutputsDumpDir, - fixture.m_Model); + fixture.m_NetworkId); // Check that the output file still exists and that it has the correct name. BOOST_TEST(fixture.FileExists()); @@ -227,7 +221,7 @@ BOOST_AUTO_TEST_CASE(ExportMultipleNetworks) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture1.m_RequestInputsAndOutputsDumpDir, - fixture1.m_Model); + fixture1.m_NetworkId); // Check that the output file exists and that it has the correct name. BOOST_TEST(fixture1.FileExists()); @@ -238,7 +232,7 @@ BOOST_AUTO_TEST_CASE(ExportMultipleNetworks) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture2.m_RequestInputsAndOutputsDumpDir, - fixture2.m_Model); + fixture2.m_NetworkId); // Check that the output file exists and that it has the correct name. BOOST_TEST(fixture2.FileExists()); @@ -249,7 +243,7 @@ BOOST_AUTO_TEST_CASE(ExportMultipleNetworks) // Export the mock optimized network. armnn_driver::ExportNetworkGraphToDotFile(mockOptimizedNetwork, fixture3.m_RequestInputsAndOutputsDumpDir, - fixture3.m_Model); + fixture3.m_NetworkId); // Check that the output file exists and that it has the correct name. BOOST_TEST(fixture3.FileExists()); -- cgit v1.2.1