Commit 03b861f1 authored by Khalique's avatar Khalique
Browse files

initial testing of generating graph file

parent af00eea8
......@@ -108,6 +108,7 @@ struct program
void debug_print() const;
void debug_print(instruction_ref ins) const;
void debug_print(const std::vector<instruction_ref>& inss) const;
void print_graph(std::ostream& os) const;
void dry_run(parameter_map params) const;
......
......@@ -7,6 +7,7 @@ int main(int argc, char const* argv[])
{
std::string file = argv[1];
auto prog = migraphx::parse_onnx(file);
std::cout << prog << std::endl;
//std::cout << prog << std::endl;
prog.print_graph(std::cout);
}
}
......@@ -54,8 +54,42 @@ static void print_instruction(std::ostream& os,
os << " -> " << ins->get_shape();
}
static std::string enclose_name(const std::string& name)
{
return '"' + name + '"';
}
static void print_graph_node(std::ostream& os,
instruction_ref ins,
const std::unordered_map<instruction_ref, std::string>& names)
{
os << "\t";
if(!ins->inputs().empty())
{
char delim = '{';
for(auto&& arg : ins->inputs())
{
os << delim << enclose_name(names.at(arg));
delim = ' ';
}
os << '}';
os << " -> ";
}
os << enclose_name(names.at(ins)) << ";";
// if(ins->name() == "@literal")
// {
// if(ins->get_literal().get_shape().elements() > 10)
// os << "{ ... }";
// else
// os << "{" << ins->get_literal() << "}";
// }
}
template <class F>
static void print_program(std::ostream& os, const program& p, F annonate)
static void print_program(std::ostream& os, const program& p, F annonate,
std::function<void(std::ostream&,instruction_ref,const std::unordered_map<instruction_ref, std::string>&)>print_func=print_instruction)
{
std::unordered_map<instruction_ref, std::string> names;
int count = 0;
......@@ -76,7 +110,7 @@ static void print_program(std::ostream& os, const program& p, F annonate)
(void)arg;
}
print_instruction(os, ins, names);
print_func(os, ins, names);
annonate(ins, names);
......@@ -531,6 +565,14 @@ void program::debug_print(const std::vector<instruction_ref>& inss) const
std::cout << std::endl;
}
void program::print_graph(std::ostream& os) const
{
os << "digraph {" << std::endl;
os << "\trankdir=LR;" << std::endl;
print_program(os, *this, [](auto&&...) {}, print_graph_node);
os << "}" << std::endl;
}
void program::dry_run(std::unordered_map<std::string, argument> params) const
{
auto& ctx = this->impl->ctx;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment