eliminate_contiguous_test.cpp 1.38 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/operators.hpp>
4
5
6
7
8
9
#include <basic_ops.hpp>
#include <test.hpp>

struct eliminate_contiguous_target
{
    std::string name() const { return "eliminate_contiguous"; }
Paul's avatar
Paul committed
10
    std::vector<migraphx::pass> get_passes(migraphx::context&) const
11
    {
Paul's avatar
Paul committed
12
        return {migraphx::eliminate_contiguous{}, migraphx::dead_code_elimination{}};
13
    }
Paul's avatar
Paul committed
14
    migraphx::context get_context() const { return {}; }
15
16
};

Paul's avatar
Paul committed
17
TEST_CASE(standard_op)
18
{
Paul's avatar
Paul committed
19
    migraphx::program p;
20
    auto l = p.add_literal(get_2x2());
Paul's avatar
Paul committed
21
22
    auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
    auto c = p.add_instruction(migraphx::op::contiguous{}, t);
23
24
25
26
27
28
    p.add_instruction(pass_standard_op{}, c);
    auto count = std::distance(p.begin(), p.end());
    p.compile(eliminate_contiguous_target{});
    EXPECT(std::distance(p.begin(), p.end()) == count);
}

Paul's avatar
Paul committed
29
TEST_CASE(non_standard_op)
30
{
Paul's avatar
Paul committed
31
    migraphx::program p;
32
    auto l = p.add_literal(get_2x2());
Paul's avatar
Paul committed
33
34
    auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
    auto c = p.add_instruction(migraphx::op::contiguous{}, t);
35
36
37
38
39
40
    p.add_instruction(pass_op{}, c);
    auto count = std::distance(p.begin(), p.end());
    p.compile(eliminate_contiguous_target{});
    EXPECT(std::distance(p.begin(), p.end()) == (count - 1));
}

Paul's avatar
Paul committed
41
int main(int argc, const char* argv[]) { test::run(argc, argv); }