Skip to content

Commit 3d926ac

Browse files
urpetkov-amdUros Petkovic
andauthored
Fixing dump model ops feature on Windows for MGX EP (microsoft#26395)
Fixing dump model ops feature for MIGraphX EP on Windows. The feature wasn't functional because of saving format rules on Windows which are opposite from Linux. Current state of the feature gives us opportunity to generate and save onnx model after subgraph optimizations before compiling it. On this way we can look how model graph looks like after optimizations and we can use the optimized model. --------- Co-authored-by: Uros Petkovic <urpektov@amd.com>
1 parent 77555db commit 3d926ac

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

onnxruntime/core/providers/migraphx/migraphx_execution_provider.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,13 @@ MIGraphXExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_v
10821082
// dump onnx file if environment var is set
10831083
if (dump_model_ops_) {
10841084
std::string model_name = graph_viewer.Name() + ".onnx";
1085-
std::ofstream ofs(model_name);
1085+
std::ofstream ofs(model_name, std::ios::binary);
1086+
if (!ofs.is_open()) {
1087+
ORT_THROW("Failed to open file to dump ONNX model: " + model_name);
1088+
}
10861089
ofs.write(onnx_string_buffer.c_str(), onnx_string_buffer.size());
10871090
ofs.close();
1091+
LOGS_DEFAULT(INFO) << "ONNX model dumped to " << model_name;
10881092
}
10891093

10901094
// This is a list of initializers that migraphx considers as constants.
@@ -1335,9 +1339,13 @@ Status MIGraphXExecutionProvider::Compile(const std::vector<FusedNodeAndGraph>&
13351339

13361340
if (dump_model_ops_) {
13371341
std::string onnx_name = fused_node.Name() + ".onnx";
1338-
std::ofstream ofs(onnx_name);
1342+
std::ofstream ofs(onnx_name, std::ios::binary);
1343+
if (!ofs.is_open()) {
1344+
ORT_THROW("Failed to open file to dump ONNX model: " + onnx_name);
1345+
}
13391346
ofs.write(onnx_string_buffer.data(), onnx_string_buffer.size());
13401347
ofs.close();
1348+
LOGS_DEFAULT(INFO) << "ONNX model dumped to " << onnx_name;
13411349
}
13421350

13431351
std::vector<std::string> input_names, output_names;

0 commit comments

Comments
 (0)