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

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

Paul's avatar
Paul committed
18
TEST_CASE(standard_op)
19
{
Paul's avatar
Paul committed
20
    migraphx::program p;
21
    auto l = p.add_literal(get_2x2());
Paul's avatar
Paul committed
22
23
    auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
    auto c = p.add_instruction(migraphx::op::contiguous{}, t);
24
25
26
27
28
29
    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
30
TEST_CASE(non_standard_op)
31
{
Paul's avatar
Paul committed
32
    migraphx::program p;
33
    auto l = p.add_literal(get_2x2());
Paul's avatar
Paul committed
34
35
    auto t = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
    auto c = p.add_instruction(migraphx::op::contiguous{}, t);
36
37
38
39
40
41
    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
42
int main(int argc, const char* argv[]) { test::run(argc, argv); }