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

Method print_py

src/module.cpp:1363–1433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1361}
1362
1363std::unordered_map<instruction_ref, std::string>
1364module::print_py(std::ostream& os,
1365 const std::string& mname,
1366 std::unordered_map<instruction_ref, std::string> names) const
1367{
1368 // cppcheck-suppress variableScope
1369 unsigned long seed = names.size();
1370 auto last = std::prev(this->end());
1371 names = this->print(
1372 [&](auto ins, auto ins_names) {
1373 std::vector<std::string> input_vars;
1374 std::transform(ins->inputs().begin(),
1375 ins->inputs().end(),
1376 std::back_inserter(input_vars),
1377 [&](auto input) { return cpp_var_name(ins_names.at(input)); });
1378 if(ins != last)
1379 os << cpp_var_name(ins_names.at(ins)) << " = ";
1380 if(ins->name() == "@literal")
1381 {
1382 os << mname << ".add_literal(";
1383 if(ins->get_shape().elements() < 1024)
1384 {
1385 os << "migraphx.create_argument(";
1386 print_py_shape(os, ins->get_shape());
1387 os << ", [" << ins->get_literal() << "])";
1388 }
1389 else
1390 {
1391 const bool use_abs = false;
1392 // Disable abs for now
1393 // ins->get_literal().visit([&](auto v) {
1394 // use_abs = std::none_of(v.begin(), v.end(), [](auto x) { return x < 0; });
1395 // });
1396 if(use_abs)
1397 os << "migraphx.abs_literal(";
1398 os << "migraphx.generate_argument(";
1399 print_py_shape(os, ins->get_shape());
1400 os << ", " << seed << ")";
1401 if(use_abs)
1402 os << ")";
1403 seed++;
1404 }
1405 os << ")" << std::endl;
1406 }
1407 else if(ins->name() == "@param")
1408 {
1409 std::string name = any_cast<builtin::param>(ins->get_operator()).parameter;
1410 os << mname << ".add_parameter(" << enclose_name(name) << ", ";
1411 print_py_shape(os, ins->get_shape());
1412 os << ")" << std::endl;
1413 }
1414 else if(ins->name() == "@return")
1415 {
1416 os << mname << ".add_return([" << join_strings(input_vars, ", ") << "])"
1417 << std::endl;
1418 }
1419 else
1420 {

Callers 2

saveMethod · 0.45
MIGRAPHX_PYBIND11_MODULEFunction · 0.45

Calls 15

endMethod · 0.95
printMethod · 0.95
nameMethod · 0.95
cpp_var_nameFunction · 0.85
print_py_shapeFunction · 0.85
join_stringsFunction · 0.85
print_py_opFunction · 0.85
atMethod · 0.80
frontMethod · 0.80
enclose_nameFunction · 0.70
transformFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected