"src/include/vscode:/vscode.git/clone" did not exist on "5950483231fea7b87a2c4b213ccfc860b731896f"
eliminate_contiguous_test.cpp 1.98 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/identity.hpp>
#include <migraphx/op/dot.hpp>
5
6
#include <migraphx/op/transpose.hpp>
#include <migraphx/op/contiguous.hpp>
7
8
9
10
11
12
#include <basic_ops.hpp>
#include <test.hpp>

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

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

44
45
46
TEST_CASE(transpose_gemm)
{
    migraphx::program p;
Shucai Xiao's avatar
Shucai Xiao committed
47
48
49
    auto l  = p.add_literal(get_2x2());
    auto t  = p.add_instruction(migraphx::op::transpose{{1, 0}}, l);
    auto c  = p.add_instruction(migraphx::op::contiguous{}, t);
50
51
52
53
54
55
56
    auto ic = p.add_instruction(migraphx::op::identity{}, c);
    p.add_instruction(migraphx::op::dot{}, ic, l);
    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
57
int main(int argc, const char* argv[]) { test::run(argc, argv); }