| 379 | |
| 380 | template <class AxesMap> |
| 381 | static instruction_ref insert(module_pass_manager& mpm, |
| 382 | instruction_ref ins, |
| 383 | const std::vector<instruction_ref>& inputs, |
| 384 | const AxesMap& am) |
| 385 | { |
| 386 | auto op = any_cast<fused_reduce>(ins->get_operator()); |
| 387 | std::vector<int64_t> axes; |
| 388 | for(auto axis : op.axes) |
| 389 | { |
| 390 | auto new_axes = am.at(axis); |
| 391 | axes.insert(axes.end(), new_axes.begin(), new_axes.end()); |
| 392 | } |
| 393 | std::sort(axes.begin(), axes.end()); |
| 394 | auto dims = base_dims(inputs); |
| 395 | auto* oldm = ins->module_inputs().front(); |
| 396 | auto* sm = mpm.create_module(oldm->name() + "_reshape"); |
| 397 | sm->set_bypass(); |
| 398 | auto outs = sm->fuse(*oldm, inputs, nullptr, transform_op([&](const operation& sop) { |
| 399 | if(contains(sop.name(), "reduce")) |
| 400 | return make_op(sop.name(), {{"axes", axes}}); |
| 401 | if(sop.name() == "multibroadcast") |
| 402 | return make_op("multibroadcast", {{"out_lens", dims}}); |
| 403 | assert(sop.name() == "pointwise"); |
| 404 | return sop; |
| 405 | })); |
| 406 | sm->add_return(outs); |
| 407 | return mpm.get_module().insert_instruction(ins, fused_reduce{axes}, inputs, {sm}); |
| 408 | } |
| 409 | |
| 410 | static std::vector<std::size_t> base_dims(const std::vector<instruction_ref>& inputs) |
| 411 | { |
nothing calls this directly
no test coverage detected