test_var_sl_gru_forward.cpp 2.39 KB
Newer Older
1
2
3
4

#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
5
6
7
8
#include <migraphx/serialize.hpp>

#include <migraphx/make_op.hpp>

Paul's avatar
Paul committed
9
#include <migraphx/op/common.hpp>
10
11
12
13
14
15
16
17
18
19
20
21
22

struct test_var_sl_gru_forward : verify_program<test_var_sl_gru_forward>
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 3;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
23
        auto* mm = p.get_main_module();
24
25
26
27
28
29
30
31
32
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape sl_shape{migraphx::shape::int32_type, {batch_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

33
34
35
36
37
        auto seq  = mm->add_parameter("seq", in_shape);
        auto w    = mm->add_parameter("w", w_shape);
        auto r    = mm->add_parameter("r", r_shape);
        auto bias = mm->add_parameter("bias", b_shape);
        auto ih   = mm->add_parameter("ih", ih_shape);
38
        std::vector<int> sl_data{3, 2, 1};
39
        auto sql = mm->add_literal(migraphx::literal{sl_shape, sl_data});
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        auto hs = mm->add_instruction(
            migraphx::make_op(
                "gru",
                {{"hidden_size", hidden_size},
                 {"actv_func",
                  migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("sigmoid"),
                                                                      migraphx::make_op("tanh")})},
                 {"direction", migraphx::to_value(migraphx::op::rnn_direction::forward)},
                 {"clip", clip}}),
            seq,
            w,
            r,
            bias,
            sql,
            ih);
        auto lho = mm->add_instruction(migraphx::make_op("rnn_last_hs_output"), hs);
57
        mm->add_return({lho, hs});
58
59
60
61
62

        return p;
    }
    std::string section() const { return "rnn"; }
};