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

Method insert

src/fuse_reduce.cpp:381–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 14

containsFunction · 0.85
atMethod · 0.80
frontMethod · 0.80
set_bypassMethod · 0.80
insert_instructionMethod · 0.80
get_moduleMethod · 0.80
make_opFunction · 0.70
sortFunction · 0.50
endMethod · 0.45
beginMethod · 0.45
create_moduleMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected