| 79 | } |
| 80 | |
| 81 | void insert_copy(module& m, const allocation_model& model) |
| 82 | { |
| 83 | auto returns = m.get_returns(); |
| 84 | std::unordered_set<instruction_ref> returns_set(returns.begin(), returns.end()); |
| 85 | for(auto ins : returns_set) |
| 86 | { |
| 87 | if(ins->get_shape().any_of_dynamic()) |
| 88 | continue; |
| 89 | auto aliases = instruction::get_output_alias(ins); |
| 90 | if(std::any_of(aliases.begin(), aliases.end(), [&](instruction_ref alias) { |
| 91 | return alias->get_shape() == ins->get_shape(); |
| 92 | })) |
| 93 | continue; |
| 94 | auto insert_ins = std::next(ins); |
| 95 | auto alloc = m.insert_instruction( |
| 96 | insert_ins, |
| 97 | make_op("allocate", migraphx::value{{"shape", to_value(ins->get_shape())}})); |
| 98 | auto copy = m.insert_instruction(insert_ins, make_op(model.copy()), ins, alloc); |
| 99 | m.replace_instruction(ins, copy); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void insert_submod_allocations(instruction_ref ins, module& mod, const allocation_model& model) |
| 104 | { |
no test coverage detected