-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Netron ouptut fix #3778
Merged
Merged
Netron ouptut fix #3778
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ca8c89
Fix the value outputs and bugged string output in netron
CharlieL7 b270417
formatting
CharlieL7 bbcfdb0
Merge branch 'develop' into netron_ouptut_fix
CharlieL7 98bce5a
cppcheck suppress and licensing
CharlieL7 2d62c3b
Merge branch 'netron_ouptut_fix' of github.com:ROCmSoftwarePlatform/A…
CharlieL7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. | ||
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -63,12 +63,19 @@ int get_onnx_type(shape::type_t s_type) | |
|
||
auto make_attribute(const migraphx::value& val) | ||
{ | ||
value attribute; | ||
value attribute = value(std::unordered_map<std::string, value>()); | ||
attribute["name"] = val.get_key(); | ||
auto val_string = val.to<std::string>(); | ||
val_string = val_string.substr(val_string.find(":") + 1); | ||
attribute["s"] = base64_encode(val_string); | ||
attribute["type"] = "STRING"; | ||
std::string sub_str = val.get_key() + ":"; | ||
auto find_key = val_string.find(sub_str); | ||
if(find_key != std::string::npos) | ||
{ | ||
val_string = val_string.substr(find_key + sub_str.length() + 1); | ||
} | ||
// TODO: doesn't work for some reason with Netron now | ||
// attribute["s"] = base64_encode(val_string); | ||
// attribute["type"] = "STRING"; | ||
attribute["docString"] = val_string; | ||
return attribute; | ||
} | ||
|
||
|
@@ -78,7 +85,7 @@ auto make_onnx_json_node(instruction_ref ins, | |
{ | ||
value node; | ||
// TODO add support for module inputs | ||
value input_arr; | ||
value input_arr = value({}); | ||
for(instruction_ref input_ins : ins->inputs()) | ||
{ | ||
auto name = input_ins->name(); | ||
|
@@ -96,7 +103,7 @@ auto make_onnx_json_node(instruction_ref ins, | |
input_arr.push_back(ins_uids.at(input_ins) + "->" + ins_uids.at(ins)); | ||
} | ||
} | ||
value output_arr; | ||
value output_arr = value({}); | ||
for(instruction_ref output_ins : ins->outputs()) | ||
{ | ||
if(output_ins->name() == "@return") | ||
|
@@ -108,15 +115,15 @@ auto make_onnx_json_node(instruction_ref ins, | |
output_arr.push_back(ins_uids.at(ins) + "->" + ins_uids.at(output_ins)); | ||
} | ||
} | ||
node["input"] = input_arr; | ||
node["input"] = input_arr; | ||
node["output"] = output_arr; | ||
node["name"] = ins_uids.at(ins); | ||
node["opType"] = ins->name(); | ||
value op_attribute_arr; | ||
value op_attribute_arr = value({}); | ||
auto op_value = ins->get_operator().to_value(); | ||
std::for_each(op_value.begin(), op_value.end(), [&](auto v) { | ||
const std::string& attr_key = v.get_key(); | ||
if(v.is_binary()) | ||
if(v.is_binary() or attr_key == "code_object") | ||
{ | ||
return; | ||
} | ||
|
@@ -151,17 +158,17 @@ auto make_onnx_json_literal(instruction_ref ins, | |
auto make_onnx_json_shape(const shape& s) | ||
{ | ||
value ret; | ||
value dim; | ||
auto shape_lens = s.lens(); | ||
std::transform(shape_lens.begin(), | ||
shape_lens.end(), | ||
std::back_inserter(dim), | ||
[](std::size_t len) { return len; }); | ||
value dim = value({}); | ||
for(std::size_t len : s.lens()) | ||
{ | ||
// cppcheck-suppress useStlAlgorithm | ||
dim.push_back({{"dimValue", len}}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, its supposed to be an object. |
||
ret["dim"] = dim; | ||
return ret; | ||
} | ||
|
||
// ONNX graph edges called "valuetype" | ||
// ONNX graph edges called "valueType" | ||
auto make_onnx_json_edge(instruction_ref ins, | ||
instruction_ref out_ins, | ||
std::unordered_map<instruction_ref, std::string> ins_uids) | ||
|
@@ -207,8 +214,11 @@ std::unordered_map<instruction_ref, std::string> make_ins_uids(const module& mod | |
|
||
value make_graph(const module* mod) | ||
{ | ||
value graph = { | ||
{"node", {}}, {"initializer", {}}, {"input", {}}, {"output", {}}, {"valueInfo", {}}}; | ||
value graph = {{"node", value({})}, | ||
{"initializer", value({})}, | ||
{"input", value({})}, | ||
{"output", value({})}, | ||
{"valueInfo", value({})}}; | ||
auto ins_uids = make_ins_uids(*mod); | ||
for(auto ins = mod->begin(); ins != mod->end(); ++ins) | ||
{ | ||
|
@@ -251,15 +261,17 @@ std::string make_netron_output(const program& prog) | |
{ | ||
value output; | ||
auto prog_value = prog.to_value(); | ||
output["irVersion"] = prog_value.at("version").to<std::string>(); | ||
// ONNX IR version 6 | ||
// TODO: investigate sure how this affects things | ||
output["irVersion"] = 6; | ||
output["producerName"] = "AMDMIGraphX"; | ||
output["producerVersion"] = prog_value.at("migraphx_version").to<std::string>(); | ||
for(auto& mod : prog.get_modules()) | ||
{ | ||
auto graph = make_graph(mod); | ||
output["graph"] = graph; | ||
} | ||
return to_json_string(output); | ||
return to_pretty_json_string(output, 4); | ||
} | ||
|
||
} // namespace MIGRAPHX_INLINE_NS | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually
value::object{}
would be cleaner here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, didn't realize that's how it worked.