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

Method apply

src/simplify_algebra.cpp:1367–1466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1365 }
1366
1367 void apply(module& m, const match::matcher_result& r) const
1368 {
1369 auto ins = r.result;
1370 auto splits = get_splits(ins);
1371 if(splits.empty())
1372 return;
1373 auto split_groups = get_split_groups(m, ins, splits);
1374 if(split_groups_are_dependent(m, ins, split_groups))
1375 {
1376 return;
1377 }
1378
1379 for(const auto& group : split_groups)
1380 {
1381 auto start = group.front();
1382 auto split_front = splits.front();
1383 auto op = start->get_operator();
1384 if(not is_fusable(start, split_front))
1385 {
1386 continue;
1387 }
1388
1389 // Make sure there are no duplicates
1390 assert(std::none_of(
1391 std::next(group.begin()), group.end(), [&](auto i) { return i == start; }));
1392
1393 auto split_idx = 0;
1394 instruction_ref c = m.end();
1395 if(start->inputs().size() == 1)
1396 {
1397 c = m.insert_instruction(std::next(ins), op, {ins}, start->module_inputs());
1398 }
1399 else if(start->inputs().size() == 2)
1400 {
1401 assert(not std::none_of(start->inputs().begin(), start->inputs().end(), [](auto i) {
1402 return i->name() == "slice";
1403 }) and "one argument must be a split");
1404
1405 auto slice_op = any_cast<op::slice>(splits.front()->get_operator());
1406 assert(not slice_op.axes.empty());
1407 if(slice_op.axes.size() > 1)
1408 return;
1409 auto concat_axis = slice_op.axes.front();
1410 if(not concat_const_foldable(group.begin(), group.end(), concat_axis))
1411 return;
1412
1413 split_idx = get_binary_op_split_idx(group, splits);
1414 assert(split_idx < 2);
1415 size_t data_idx;
1416 if(split_idx < 0 and op.attributes().contains("commutative"))
1417 {
1418 split_idx = 0;
1419 data_idx = 1;
1420 align_commutative_op_args(m, group, splits, split_idx);
1421 }
1422 else if(split_idx < 0)
1423 {
1424 return;

Callers

nothing calls this directly

Calls 15

get_splitsFunction · 0.85
concat_const_foldableFunction · 0.85
move_instructions_backFunction · 0.85
frontMethod · 0.80
insert_instructionMethod · 0.80
can_evalMethod · 0.80
resizeMethod · 0.80
replace_instructionMethod · 0.80
make_opFunction · 0.70
none_ofFunction · 0.50
transformFunction · 0.50
any_ofFunction · 0.50

Tested by

no test coverage detected