Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU][DEBUG_CAPS] Add option for serializing exec graph to dot (#35357)

Egor Duplenskii62c431236787
diff --git a/src/plugins/intel_cpu/docs/debug_capabilities/exec_graph_serialization.md b/src/plugins/intel_cpu/docs/debug_capabilities/exec_graph_serialization.md
index b597aab326d..1139bb0e937 100644
--- a/src/plugins/intel_cpu/docs/debug_capabilities/exec_graph_serialization.md
+++ b/src/plugins/intel_cpu/docs/debug_capabilities/exec_graph_serialization.md
@@ -9,5 +9,5 @@ Possible serialization options:
Serialize to console output.
* \<path\>_index.xml\
Serialize graph into .xml and .bin files. Can be opened using, for example, *netron* app.
-* **TBD**: \<path\>.dot\
+* \<path\>_index.dot\
Serialize graph into .dot file. Can be inspected using, for example, *graphviz* tools.
diff --git a/src/plugins/intel_cpu/src/graph_dumper.cpp b/src/plugins/intel_cpu/src/graph_dumper.cpp
index 8b49acf1afa..c6ef03fbd85 100644
--- a/src/plugins/intel_cpu/src/graph_dumper.cpp
+++ b/src/plugins/intel_cpu/src/graph_dumper.cpp
@@ -34,15 +34,18 @@
#include "openvino/op/result.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/serialize.hpp"
+#include "openvino/pass/visualize_tree.hpp"
#include "openvino/runtime/exec_model_info.hpp"
#include "openvino/util/common_util.hpp"
#include "utils/debug_capabilities.h"
+#include "utils/general_utils.h"
#include "utils/platform.h"
namespace ov::intel_cpu {
void serializeToCout(const Graph& graph);
void serializeToXML(const Graph& graph, const std::filesystem::path& path);
+void serializeToDot(const Graph& graph, const std::filesystem::path& path);
namespace {
@@ -236,16 +239,37 @@ void serialize(const Graph& graph) {
if (pathStr == "cout") {
serializeToCout(graph);
- } else if (std::filesystem::path p{pathStr}; p.extension() == ".xml") {
- static int g_idx = 0;
- const auto xmlPath =
- p.parent_path() / (p.stem().string() + "_" + std::to_string(g_idx++) + p.extension().string());
- serializeToXML(graph, xmlPath);
+ return;
+ }
+
+ std::filesystem::path p{pathStr};
+ const auto ext = p.extension();
+
+ if (none_of(ext, ".xml", ".dot")) {
+ OPENVINO_THROW("Unknown serialize format. Should be either 'cout', '*.xml' or '*.dot'. Got ", pathStr);
+ }
+
+ static int g_idx = 0;
+ const auto indexedFileName = p.stem().string() + "_" + std::to_string(g_idx++) + ext.string();
+ const auto indexedPath = p.parent_path() / indexedFileName;
+
+ if (ext == ".xml") {
+ serializeToXML(graph, indexedPath);
} else {
- OPENVINO_THROW("Unknown serialize format. Should be either 'cout' or '*.xml'. Got ", pathStr);
+ serializeToDot(graph, indexedPath);
}
}
+void serializeToDot(const Graph& graph, const std::filesystem::path& path) {
+ if (path.empty()) {
+ return;
+ }
+
+ ov::pass::Manager manager;
+ manager.register_pass<ov::pass::VisualizeTree>(path.string(), nullptr, true);
+ manager.run_passes(graph.dump());
+}
+
void serializeToXML(const Graph& graph, const std::filesystem::path& path) {
if (path.empty()) {
return;