| 745 | } |
| 746 | |
| 747 | static void mod_from_val(module_ref mod, |
| 748 | const value& v, |
| 749 | std::unordered_map<std::string, instruction_ref>& instructions, |
| 750 | const std::unordered_map<std::string, module_ref>& map_mods) |
| 751 | { |
| 752 | const auto& module_val = v.at(mod->name()); |
| 753 | for(const value& node : module_val.at("nodes")) |
| 754 | { |
| 755 | instruction_ref output; |
| 756 | auto name = node.at("name").to<std::string>(); |
| 757 | auto fields = node.at("operator"); |
| 758 | auto normalized = node.at("normalized").to<bool>(); |
| 759 | |
| 760 | if(name == "@param") |
| 761 | { |
| 762 | output = mod->insert_parameter(mod->end(), |
| 763 | fields["parameter"].to<std::string>(), |
| 764 | migraphx::from_value<shape>(node.at("shape"))); |
| 765 | } |
| 766 | else if(name == "@literal") |
| 767 | { |
| 768 | output = |
| 769 | mod->insert_literal(mod->end(), migraphx::from_value<literal>(node.at("literal"))); |
| 770 | } |
| 771 | else |
| 772 | { |
| 773 | auto op = make_op(name, fields); |
| 774 | std::vector<instruction_ref> inputs; |
| 775 | std::transform(node.at("inputs").begin(), |
| 776 | node.at("inputs").end(), |
| 777 | std::back_inserter(inputs), |
| 778 | [&](const value& i) { |
| 779 | auto i_name = i.to<std::string>(); |
| 780 | assert(contains(instructions, i_name)); |
| 781 | return instructions.at(i_name); |
| 782 | }); |
| 783 | |
| 784 | std::vector<module_ref> module_inputs; |
| 785 | if(node.contains("module_inputs")) |
| 786 | { |
| 787 | std::transform(node.at("module_inputs").begin(), |
| 788 | node.at("module_inputs").end(), |
| 789 | std::back_inserter(module_inputs), |
| 790 | [&](const value& i) { return map_mods.at(i.to<std::string>()); }); |
| 791 | |
| 792 | for(const auto& smod : module_inputs) |
| 793 | { |
| 794 | mod_from_val(smod, v, instructions, map_mods); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | if(name == "@return") |
| 799 | { |
| 800 | output = mod->add_return(inputs); |
| 801 | } |
| 802 | else if(module_inputs.empty()) |
| 803 | { |
| 804 | output = mod->insert_instruction(mod->end(), op, inputs); |
no test coverage detected