| 34 | struct test_rnn_sql_2 : verify_program<test_rnn_sql_2> |
| 35 | { |
| 36 | migraphx::program create_program() const |
| 37 | { |
| 38 | std::size_t batch_size = 2; |
| 39 | std::size_t seq_len = 10; |
| 40 | std::size_t hidden_size = 4; |
| 41 | std::size_t input_size = 3; |
| 42 | std::size_t num_dirct = 1; |
| 43 | float clip = 0.0f; |
| 44 | |
| 45 | migraphx::program p; |
| 46 | auto* mm = p.get_main_module(); |
| 47 | migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; |
| 48 | migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; |
| 49 | migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; |
| 50 | migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; |
| 51 | migraphx::shape s_shape{migraphx::shape::int32_type, {batch_size}}; |
| 52 | migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; |
| 53 | |
| 54 | auto seq_orig = mm->add_parameter("seq", in_shape); |
| 55 | auto w = mm->add_parameter("w", w_shape); |
| 56 | auto r = mm->add_parameter("r", r_shape); |
| 57 | auto bias = mm->add_parameter("bias", b_shape); |
| 58 | migraphx::shape pad_s{migraphx::shape::float_type, {2, batch_size, input_size}}; |
| 59 | std::vector<float> pad_data(pad_s.elements(), 0.0f); |
| 60 | auto seq_pad = mm->add_literal(migraphx::literal{pad_s, pad_data}); |
| 61 | auto seq = |
| 62 | mm->add_instruction(migraphx::make_op("concat", {{"axis", 0}}), seq_orig, seq_pad); |
| 63 | std::vector<int> sl_data(batch_size, static_cast<int>(seq_len)); |
| 64 | auto sql = mm->add_literal(migraphx::literal{s_shape, sl_data}); |
| 65 | auto ih = mm->add_parameter("ih", ih_shape); |
| 66 | |
| 67 | auto hs = mm->add_instruction( |
| 68 | migraphx::make_op( |
| 69 | "rnn", |
| 70 | {{"hidden_size", hidden_size}, |
| 71 | {"actv_func", |
| 72 | migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh")})}, |
| 73 | {"direction", migraphx::to_value(migraphx::op::rnn_direction::forward)}, |
| 74 | {"clip", clip}}), |
| 75 | seq, |
| 76 | w, |
| 77 | r, |
| 78 | bias, |
| 79 | sql, |
| 80 | ih); |
| 81 | auto last_hs = mm->add_instruction(migraphx::make_op("rnn_last_hs_output"), hs); |
| 82 | mm->add_return({hs, last_hs}); |
| 83 | |
| 84 | return p; |
| 85 | } |
| 86 | std::string section() const { return "rnn"; } |
| 87 | }; |
nothing calls this directly
no test coverage detected