#include #include #include #include #include #include #include #include #include namespace migraph { inline namespace MIGRAPH_INLINE_NS { namespace gpu { void eliminate_workspace::apply(program& p) const { if(!enabled(MIGRAPH_DISABLE_MEMORY_COLORING{})) return; std::size_t n = 0; std::vector allocs; for(auto ins : iterator_for(p)) { if(ins->outputs().size() != 1) continue; if(ins->name() != "hip::allocate") continue; auto&& a = any_cast(ins->get_operator()); if(a.tag == "workspace") { n = std::max(n, ins->get_shape().bytes()); allocs.push_back(ins); } } auto ws = p.add_parameter("workspace", shape{shape::int8_type, {n}}); for(auto&& a : allocs) { p.replace_instruction(a, ws); p.remove_instruction(a); } } } // namespace gpu } // namespace MIGRAPH_INLINE_NS } // namespace migraph