#include #include #include #include #include #include #include #include #include namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { void eliminate_allocation::apply(module& m) const { assert(alignment > 0); std::size_t n = 0; std::vector> allocs; for(auto ins : iterator_for(m)) { if(ins->name() != allocation_op) continue; allocs.emplace_back(ins, n); std::size_t size = ins->get_shape().bytes(); std::size_t padding = (alignment - (size % alignment)) % alignment; n += size + padding; } if(n > 0) { auto mem = m.add_parameter("memory", shape{shape::int8_type, {n}}); for(auto&& pp : allocs) { auto ins = pp.first; auto s = ins->get_shape(); auto offset = pp.second; m.replace_instruction( ins, make_op("load", {{"shape", to_value(s)}, {"offset", offset}}), mem); } } } } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx