Skip to content

Commit ef4c44b

Browse files
[CPU][DEBUG_CAPS] Add option for serializing exec graph to dot (#35357)
### Details: - *item1* - *...* ### Tickets: - *ticket-id* ### AI Assistance: - *AI assistance used: no / yes* - *If yes, summarize how AI was used and what human validation was performed (build/tests/manual checks).* <!-- Message of single commit: -->
1 parent 6dd34c1 commit ef4c44b

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/plugins/intel_cpu/docs/debug_capabilities/exec_graph_serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Possible serialization options:
99
Serialize to console output.
1010
* \<path\>_index.xml\
1111
Serialize graph into .xml and .bin files. Can be opened using, for example, *netron* app.
12-
* **TBD**: \<path\>.dot\
12+
* \<path\>_index.dot\
1313
Serialize graph into .dot file. Can be inspected using, for example, *graphviz* tools.

src/plugins/intel_cpu/src/graph_dumper.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@
3434
#include "openvino/op/result.hpp"
3535
#include "openvino/pass/manager.hpp"
3636
#include "openvino/pass/serialize.hpp"
37+
#include "openvino/pass/visualize_tree.hpp"
3738
#include "openvino/runtime/exec_model_info.hpp"
3839
#include "openvino/util/common_util.hpp"
3940
#include "utils/debug_capabilities.h"
41+
#include "utils/general_utils.h"
4042
#include "utils/platform.h"
4143

4244
namespace ov::intel_cpu {
4345

4446
void serializeToCout(const Graph& graph);
4547
void serializeToXML(const Graph& graph, const std::filesystem::path& path);
48+
void serializeToDot(const Graph& graph, const std::filesystem::path& path);
4649

4750
namespace {
4851

@@ -236,16 +239,37 @@ void serialize(const Graph& graph) {
236239

237240
if (pathStr == "cout") {
238241
serializeToCout(graph);
239-
} else if (std::filesystem::path p{pathStr}; p.extension() == ".xml") {
240-
static int g_idx = 0;
241-
const auto xmlPath =
242-
p.parent_path() / (p.stem().string() + "_" + std::to_string(g_idx++) + p.extension().string());
243-
serializeToXML(graph, xmlPath);
242+
return;
243+
}
244+
245+
std::filesystem::path p{pathStr};
246+
const auto ext = p.extension();
247+
248+
if (none_of(ext, ".xml", ".dot")) {
249+
OPENVINO_THROW("Unknown serialize format. Should be either 'cout', '*.xml' or '*.dot'. Got ", pathStr);
250+
}
251+
252+
static int g_idx = 0;
253+
const auto indexedFileName = p.stem().string() + "_" + std::to_string(g_idx++) + ext.string();
254+
const auto indexedPath = p.parent_path() / indexedFileName;
255+
256+
if (ext == ".xml") {
257+
serializeToXML(graph, indexedPath);
244258
} else {
245-
OPENVINO_THROW("Unknown serialize format. Should be either 'cout' or '*.xml'. Got ", pathStr);
259+
serializeToDot(graph, indexedPath);
246260
}
247261
}
248262

263+
void serializeToDot(const Graph& graph, const std::filesystem::path& path) {
264+
if (path.empty()) {
265+
return;
266+
}
267+
268+
ov::pass::Manager manager;
269+
manager.register_pass<ov::pass::VisualizeTree>(path.string(), nullptr, true);
270+
manager.run_passes(graph.dump());
271+
}
272+
249273
void serializeToXML(const Graph& graph, const std::filesystem::path& path) {
250274
if (path.empty()) {
251275
return;

0 commit comments

Comments
 (0)