"src/vscode:/vscode.git/clone" did not exist on "19ed10f0baaa443ed4b7c7d4a96ec2e76295cd2c"
adjust_allocation.cpp 2.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <migraphx/gpu/adjust_allocation.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/op/add.hpp>
#include <migraphx/op/transpose.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/op/tanh.hpp>
#include <basic_ops.hpp>
#include <test.hpp>

struct lowering_target
{
    std::string name() const { return "gpu::lowering"; }
    std::vector<migraphx::pass> get_passes(migraphx::context& gctx) const
    {
        auto& ctx = migraphx::any_cast<migraphx::gpu::context>(gctx);
23
24
25
26
27
        return {migraphx::auto_contiguous{},
                migraphx::gpu::lowering{ctx},
                migraphx::dead_code_elimination{},
                migraphx::eliminate_contiguous{},
                migraphx::dead_code_elimination{}};
28
29
30
31
    }
    migraphx::gpu::context get_context() const { return migraphx::gpu::context{}; }
};

Shucai Xiao's avatar
Shucai Xiao committed
32
TEST_CASE(tanh_shape)
33
34
35
36
{
    auto create_program = [] {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {2, 3}};
37
        auto x   = p.add_parameter("x", s);
Shucai Xiao's avatar
Shucai Xiao committed
38
        auto tx  = p.add_instruction(migraphx::op::transpose{{1, 0}}, x);
Shucai Xiao's avatar
Shucai Xiao committed
39
        auto txh = p.add_instruction(migraphx::op::tanh{}, tx);
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        p.add_instruction(migraphx::op::add{}, txh, txh);

        return p;
    };

    auto p1 = create_program();
    auto p2 = create_program();
    EXPECT(p1 == p2);

    p1.compile(lowering_target{});
    p2.compile(lowering_target{});

    EXPECT(p1 == p2);

    for(auto ins : iterator_for(p1))
    {
56
57
        if(ins->name() == "hip::allocate")
        {
Shucai Xiao's avatar
Shucai Xiao committed
58
            migraphx::shape wrong_s{migraphx::shape::float_type, {2, 2}};
59
60
            ins->replace(wrong_s);
        }
61
62
63
64
65
66
67
68
69
    }
    EXPECT(p1 != p2);

    migraphx::run_passes(p1,
                         {migraphx::gpu::adjust_allocation{}, migraphx::dead_code_elimination{}});
    EXPECT(p1 == p2);
}

int main(int argc, const char* argv[]) { test::run(argc, argv); }