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

Method apply

src/adjust_allocation.cpp:34–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32inline namespace MIGRAPHX_INLINE_NS {
33
34void adjust_allocation::apply(module& m) const
35{
36 for(auto ins : iterator_for(m))
37 {
38 // skip instruction with no input
39 if(ins->inputs().empty())
40 continue;
41
42 // Skip target-independent operators
43 if(ins->get_operator().is_context_free())
44 continue;
45
46 auto aliases = instruction::get_output_alias(ins, true);
47 if(aliases.size() != 1)
48 continue;
49 auto alias_ins = aliases.front();
50 if(alias_ins->name() != model.name() and alias_ins->name() != "@param")
51 continue;
52 // shape allocated is different from actual shape
53 // of the instruction, reallocate and replace the previous one
54 if(alias_ins->get_shape() == ins->get_shape())
55 continue;
56 auto alloc_ins = m.insert_instruction(ins, model.allocate(ins->get_shape()));
57 m.replace_instruction(alias_ins, alloc_ins);
58 // If the memory is an output parameter then copy the memory to the parameter
59 if(alias_ins->name() == "@param")
60 {
61 auto copy = m.insert_instruction(std::next(ins), make_op(model.copy()), ins, alias_ins);
62 auto tail = range(std::next(copy), m.end());
63 for(auto i : iterator_for(tail))
64 {
65 if(contains(i->inputs(), ins))
66 instruction::replace_argument(i, ins, copy);
67 }
68 }
69 }
70}
71
72} // namespace MIGRAPHX_INLINE_NS
73} // namespace migraphx

Callers

nothing calls this directly

Calls 15

iterator_forFunction · 0.85
containsFunction · 0.85
frontMethod · 0.80
insert_instructionMethod · 0.80
replace_instructionMethod · 0.80
make_opFunction · 0.70
rangeFunction · 0.50
emptyMethod · 0.45
inputsMethod · 0.45
is_context_freeMethod · 0.45
sizeMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected