| 32 | inline namespace MIGRAPHX_INLINE_NS { |
| 33 | |
| 34 | void 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 |
nothing calls this directly
no test coverage detected