MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / trim_module

Function trim_module

src/driver/trim.cpp:66–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66void trim_module(module& m, std::size_t loc, std::size_t n)
67{
68 if(loc > m.size())
69 MIGRAPHX_THROW("Trim out of range.");
70 auto last = std::prev(m.end(), loc);
71 auto start = std::prev(last, n);
72 m.remove_instructions(last, m.end());
73 if(n == 0)
74 return;
75 if(n > m.size())
76 MIGRAPHX_THROW("Trim size out of range.");
77 std::unordered_map<instruction_ref, instruction_ref> map_ins;
78 std::unordered_set<instruction_ref> instruction_set;
79 auto instructions = range(start, m.end());
80 for(instruction_ref ins : iterator_for(instructions))
81 {
82 instruction_set.insert(ins);
83 for(auto input : ins->inputs())
84 {
85 if(contains(instruction_set, input))
86 continue;
87 auto arg = capture_arg(instruction_set, input);
88 auto placeholder = add_placeholder(m, arg);
89 assert(placeholder->get_shape() == arg->get_shape());
90 if(placeholder == arg)
91 continue;
92 instruction_set.insert(placeholder);
93 map_ins[arg] = placeholder;
94 }
95 }
96 for(auto [old_ins, new_ins] : map_ins)
97 m.replace_instruction(old_ins, new_ins);
98 run_passes(m, {dead_code_elimination{}});
99 for(auto pins : m.get_parameters())
100 {
101 if(not pins->outputs().empty())
102 continue;
103 m.remove_instruction(pins);
104 }
105}
106
107} // namespace MIGRAPHX_INLINE_NS
108} // namespace driver

Callers 1

loadMethod · 0.85

Calls 15

iterator_forFunction · 0.85
containsFunction · 0.85
capture_argFunction · 0.85
add_placeholderFunction · 0.85
run_passesFunction · 0.85
remove_instructionsMethod · 0.80
replace_instructionMethod · 0.80
get_parametersMethod · 0.80
outputsMethod · 0.80
remove_instructionMethod · 0.80
rangeFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected