| 63 | |
| 64 | template <class F> |
| 65 | static migraphx::instruction_ref add_mlir(migraphx::program& p, |
| 66 | const std::string& name, |
| 67 | std::vector<migraphx::instruction_ref> inputs, |
| 68 | std::vector<std::string> arg_names, |
| 69 | const F& f) |
| 70 | { |
| 71 | assert(inputs.size() == arg_names.size() and "One interior parameter name given per input."); |
| 72 | auto* mm = p.get_main_module(); |
| 73 | auto* pm = p.create_module(name); |
| 74 | pm->set_bypass(); |
| 75 | std::vector<migraphx::instruction_ref> params; |
| 76 | for(size_t i = 0, e = inputs.size(); i < e; ++i) |
| 77 | { |
| 78 | params.push_back(pm->add_parameter(arg_names[i], inputs[i]->get_shape().as_standard())); |
| 79 | } |
| 80 | auto values = f(pm, params); |
| 81 | auto root = std::get<0>(values); |
| 82 | auto r = std::get<1>(values); |
| 83 | auto_add_return(pm, r); |
| 84 | return mm->add_instruction( |
| 85 | migraphx::make_op("gpu::mlir_op", {{"op", migraphx::to_value(root)}}), inputs, {pm}); |
| 86 | } |
| 87 | |
| 88 | template <class F> |
| 89 | static migraphx::instruction_ref add_mlir(migraphx::program& p, |
no test coverage detected