MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / print_cpp

Method print_cpp

src/module.cpp:1435–1494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1433}
1434
1435std::unordered_map<instruction_ref, std::string>
1436module::print_cpp(std::ostream& os,
1437 const std::string& mname,
1438 std::unordered_map<instruction_ref, std::string> names) const
1439{
1440 // cppcheck-suppress variableScope
1441 unsigned long seed = names.size();
1442 auto last = std::prev(this->end());
1443 names = this->print(
1444 [&](auto ins, auto ins_names) {
1445 std::vector<std::string> input_vars;
1446 std::transform(ins->inputs().begin(),
1447 ins->inputs().end(),
1448 std::back_inserter(input_vars),
1449 [&](auto input) { return cpp_var_name(ins_names.at(input)); });
1450 if(ins != last)
1451 os << "auto " << cpp_var_name(ins_names.at(ins)) << " = ";
1452 if(ins->name() == "@literal")
1453 {
1454 os << mname << "->add_literal(";
1455 bool use_abs = false;
1456 ins->get_literal().visit([&](auto v) {
1457 use_abs = std::none_of(v.begin(), v.end(), [](auto x) { return x < 0; });
1458 });
1459 if(use_abs)
1460 os << "migraphx::abs(";
1461 os << "migraphx::generate_literal(";
1462 print_cpp_shape(os, ins->get_shape());
1463 os << ", " << seed << ")";
1464 if(use_abs)
1465 os << ")";
1466 os << ");" << std::endl;
1467 seed++;
1468 }
1469 else if(ins->name() == "@param")
1470 {
1471 std::string name = any_cast<builtin::param>(ins->get_operator()).parameter;
1472 os << mname << "->add_parameter(" << enclose_name(name) << ",";
1473 print_cpp_shape(os, ins->get_shape());
1474 os << ");" << std::endl;
1475 }
1476 else if(ins->name() == "@return")
1477 {
1478 os << mname << "->add_return({";
1479 os << join_strings(input_vars, ", ");
1480 os << "});" << std::endl;
1481 }
1482 else
1483 {
1484 assert(ins->name().front() != '@');
1485 os << mname << "->add_instruction(";
1486 print_make_op(os, ins->get_operator());
1487 os << ", " << join_strings(input_vars, ", ");
1488 os << ");" << std::endl;
1489 }
1490 },
1491 names);
1492

Callers 3

TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
saveMethod · 0.45

Calls 15

endMethod · 0.95
printMethod · 0.95
nameMethod · 0.95
cpp_var_nameFunction · 0.85
print_cpp_shapeFunction · 0.85
join_stringsFunction · 0.85
print_make_opFunction · 0.85
atMethod · 0.80
frontMethod · 0.80
enclose_nameFunction · 0.70
transformFunction · 0.50
none_ofFunction · 0.50

Tested by 1

TEST_CASEFunction · 0.36