"vscode:/vscode.git/clone" did not exist on "678f9334b517134ed11e91f5ada7946fe2aba400"
Commit 6d56671b authored by Paul's avatar Paul
Browse files

Formatting

parent 3b64f602
...@@ -413,18 +413,18 @@ inline auto either_arg(std::size_t i, std::size_t j) ...@@ -413,18 +413,18 @@ inline auto either_arg(std::size_t i, std::size_t j)
}; };
} }
template<class M> template <class M>
auto same_shape(M m) auto same_shape(M m)
{ {
return make_basic_fun_matcher([=](matcher_context& ctx, instruction_ref ins) { return make_basic_fun_matcher([=](matcher_context& ctx, instruction_ref ins) {
auto i = m.match(ctx, ins); auto i = m.match(ctx, ins);
if (i != ctx.not_found() and i->get_shape() == ins->get_shape()) if(i != ctx.not_found() and i->get_shape() == ins->get_shape())
return ins; return ins;
return ctx.not_found(); return ctx.not_found();
}); });
} }
template<class... Ms> template <class... Ms>
auto same_shape(Ms... ms) auto same_shape(Ms... ms)
{ {
return all_of(same_shape(ms)...); return all_of(same_shape(ms)...);
......
...@@ -129,9 +129,7 @@ struct find_nop_reshapes ...@@ -129,9 +129,7 @@ struct find_nop_reshapes
auto reshapes = reshaper_names(); auto reshapes = reshaper_names();
reshapes.insert("transpose"); reshapes.insert("transpose");
reshapes.insert("slice"); reshapes.insert("slice");
return match::name(reshapes)( return match::name(reshapes)(match::same_shape(match::arg(0)));
match::same_shape(match::arg(0))
);
} }
void apply(program& p, match::matcher_result mr) const void apply(program& p, match::matcher_result mr) const
...@@ -197,7 +195,7 @@ struct find_concat_transpose ...@@ -197,7 +195,7 @@ struct find_concat_transpose
std::vector<instruction_ref> inputs; std::vector<instruction_ref> inputs;
std::transform( std::transform(
ins->inputs().begin(), ins->inputs().end(), std::back_inserter(inputs), [&](auto i) { ins->inputs().begin(), ins->inputs().end(), std::back_inserter(inputs), [&](auto i) {
if (i->name() == "transpose" and i->inputs().front()->get_shape().standard()) if(i->name() == "transpose" and i->inputs().front()->get_shape().standard())
return i->inputs().front(); return i->inputs().front();
return p.insert_instruction(ins, op::transpose{permutation}, i); return p.insert_instruction(ins, op::transpose{permutation}, i);
}); });
...@@ -217,7 +215,12 @@ void simplify_reshapes::apply(program& p) const ...@@ -217,7 +215,12 @@ void simplify_reshapes::apply(program& p) const
// Skip possible dead instructions // Skip possible dead instructions
if(ins->outputs().empty() and ins != end) if(ins->outputs().empty() and ins != end)
continue; continue;
match::find_matches(p, ins, find_nop_reshapes{}, find_reshaper{}, find_transpose{}, find_concat_transpose{}); match::find_matches(p,
ins,
find_nop_reshapes{},
find_reshaper{},
find_transpose{},
find_concat_transpose{});
} }
} }
......
...@@ -278,14 +278,10 @@ TEST_CASE(concat_transpose1) ...@@ -278,14 +278,10 @@ TEST_CASE(concat_transpose1)
p.compile(simplify_reshapes_target{}); p.compile(simplify_reshapes_target{});
EXPECT(p.get_shape().lens() == out_shape.lens()); EXPECT(p.get_shape().lens() == out_shape.lens());
EXPECT(std::distance(p.begin(), p.end()) == n - 3); EXPECT(std::distance(p.begin(), p.end()) == n - 3);
auto new_concat = std::find_if(p.begin(), p.end(), [](auto ins) { auto new_concat =
return ins.name() == "concat"; std::find_if(p.begin(), p.end(), [](auto ins) { return ins.name() == "concat"; });
});
EXPECT(bool{new_concat != p.end()}); EXPECT(bool{new_concat != p.end()});
EXPECT(migraphx::any_cast<migraphx::op::concat>(new_concat->get_operator()).axis == 3); EXPECT(migraphx::any_cast<migraphx::op::concat>(new_concat->get_operator()).axis == 3);
} }
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment