Unverified Commit bf6a3507 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Fix bug in eliminate concat: dont use sorted allocations to assign offsets (#503)



* Fix bug in eliminate concat: dont use sorted allocations to assign offsets

* Formatting
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
parent 3bbd808e
...@@ -58,12 +58,14 @@ void eliminate_concat::apply(program& p) const ...@@ -58,12 +58,14 @@ void eliminate_concat::apply(program& p) const
// Need to sort the allocations, so that we know where to // Need to sort the allocations, so that we know where to
// insert the "super"-allocation // insert the "super"-allocation
std::sort( auto sorted_allocations = allocations;
allocations.begin(), allocations.end(), [&](instruction_ref x, instruction_ref y) { std::sort(sorted_allocations.begin(),
return std::distance(p.begin(), x) < std::distance(p.begin(), y); sorted_allocations.end(),
}); [&](instruction_ref x, instruction_ref y) {
return std::distance(p.begin(), x) < std::distance(p.begin(), y);
});
// Move "super" allocation to the front // Move "super" allocation to the front
auto first = allocations.front(); auto first = sorted_allocations.front();
auto super = p.move_instruction(last, first); auto super = p.move_instruction(last, first);
// Replace each allocation with a load // Replace each allocation with a load
std::size_t offset = 0; std::size_t offset = 0;
......
...@@ -132,6 +132,37 @@ TEST_CASE(simple) ...@@ -132,6 +132,37 @@ TEST_CASE(simple)
EXPECT(p1 == p2); EXPECT(p1 == p2);
} }
TEST_CASE(reversed)
{
auto create_test_program = [] {
migraphx::program p;
auto a1 = p.add_instruction(allocate{create_shape(1)});
auto p1 = p.add_instruction(simple_op{}, a1);
auto a2 = p.add_instruction(allocate{create_shape(1)});
auto p2 = p.add_instruction(simple_op{}, a2);
std::size_t axis = 0;
auto a3 = p.add_instruction(allocate{create_shape(2)});
p.add_instruction(concat(axis), p2, p1, a3);
return p;
};
auto create_control_program = [] {
migraphx::program p;
auto a1 = p.add_instruction(allocate{create_shape(2)});
auto l1 = p.add_instruction(load{create_shape(1), 4}, a1);
auto p1 = p.add_instruction(simple_op{}, l1);
auto l2 = p.add_instruction(load{create_shape(1), 0}, a1);
auto p2 = p.add_instruction(simple_op{}, l2);
p.add_instruction(identity{}, a1, p2, p1);
return p;
};
auto p1 = create_test_program();
auto p2 = create_control_program();
run_pass(p1);
EXPECT(p1 == p2);
}
TEST_CASE(nested) TEST_CASE(nested)
{ {
auto concat_test_program = [](auto& p) { auto concat_test_program = [](auto& p) {
......
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