aboutsummaryrefslogtreecommitdiff
path: root/Utils.cpp
diff options
context:
space:
mode:
authorsurmeh01 <surabhi.mehta@arm.com>2018-03-29 16:33:54 +0100
committersurmeh01 <surabhi.mehta@arm.com>2018-03-29 16:33:54 +0100
commit7666005c72227a3ea5c410ca2861c9b6620887d8 (patch)
tree084296e0ba923f7885b8efb242335a4547b2cdb0 /Utils.cpp
parent5307bc10ac488261e84ac76b2dede6039ea3fe96 (diff)
downloadandroid-nn-driver-7666005c72227a3ea5c410ca2861c9b6620887d8.tar.gz
Release 18.03
Diffstat (limited to 'Utils.cpp')
-rw-r--r--Utils.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/Utils.cpp b/Utils.cpp
index 33c1cd3c..01c2719b 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -15,6 +15,7 @@
#include <cassert>
#include <cinttypes>
#include <fstream>
+#include <iomanip>
using namespace android;
using namespace android::hidl::memory::V1_0;
@@ -270,4 +271,42 @@ void DumpTensor(const std::string& dumpDir,
}
}
+void ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork,
+ const std::string& dumpDir,
+ const Model& 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());
+ }
+}
} // namespace armnn_driver