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

Method apply

src/simplify_reshapes.cpp:181–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179 }
180
181 void apply(module& m, const match::matcher_result& mr) const
182 {
183 auto ins = mr.result;
184
185 std::vector<operation> ops;
186 auto x = ins;
187 while(contains(shape_transform_ops(), x->get_operator().name()) or
188 x->get_operator().name() == "contiguous")
189 {
190 ops.push_back(x->get_operator());
191 x = x->inputs().front();
192 }
193 if(x->get_shape().scalar())
194 {
195 m.replace_instruction(
196 ins, make_op("multibroadcast", {{"out_lens", ins->get_shape().lens()}}), x);
197 }
198 else if(x->get_shape().elements() == 1 and ins->get_shape().elements() == 1)
199 {
200 // TODO: Use squeeze or unsqueeze
201 m.replace_instruction(ins, make_op("reshape", {{"dims", ins->get_shape().lens()}}), x);
202 }
203 else
204 {
205 std::reverse(ops.begin(), ops.end());
206 auto opt_ops = optimize_shape_transforms(x->get_shape().lens(), ops);
207 if(ops == opt_ops)
208 return;
209 auto y = insert_ops(m, ins, opt_ops, x);
210 m.replace_instruction(ins, y);
211 }
212 }
213};
214
215struct find_op_shape_transform_op

Callers

nothing calls this directly

Calls 15

containsFunction · 0.85
insert_opsFunction · 0.85
frontMethod · 0.80
scalarMethod · 0.80
replace_instructionMethod · 0.80
lensMethod · 0.80
make_opFunction · 0.70
reverseFunction · 0.50
nameMethod · 0.45
push_backMethod · 0.45
inputsMethod · 0.45

Tested by

no test coverage detected