| 34 | inline namespace MIGRAPHX_INLINE_NS { |
| 35 | |
| 36 | void eliminate_allocation::apply(module& m) const |
| 37 | { |
| 38 | assert(alignment > 0); |
| 39 | |
| 40 | std::size_t n = 0; |
| 41 | std::vector<std::pair<instruction_ref, std::size_t>> allocs; |
| 42 | for(auto ins : iterator_for(m)) |
| 43 | { |
| 44 | if(ins->name() != allocation_op) |
| 45 | continue; |
| 46 | allocs.emplace_back(ins, n); |
| 47 | std::size_t size = ins->get_shape().bytes(); |
| 48 | std::size_t padding = (alignment - (size % alignment)) % alignment; |
| 49 | n += size + padding; |
| 50 | } |
| 51 | if(n > 0) |
| 52 | { |
| 53 | auto mem = m.add_parameter("memory", shape{shape::int8_type, {n}}); |
| 54 | for(auto&& pp : allocs) |
| 55 | { |
| 56 | auto ins = pp.first; |
| 57 | auto s = ins->get_shape(); |
| 58 | auto offset = pp.second; |
| 59 | m.replace_instruction( |
| 60 | ins, make_op("load", {{"shape", to_value(s)}, {"offset", offset}}), mem); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | } // namespace MIGRAPHX_INLINE_NS |
| 66 | } // namespace migraphx |
nothing calls this directly
no test coverage detected