#include #include "test_utils.hpp" #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wglobal-constructors" #endif struct test_rnn_forward : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto hs = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und, ih); auto lho = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, lho}); return p; } }; struct test_rnn_forward10 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 10; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto hs = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und, ih); auto lho = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, lho}); return p; } }; struct test_rnn_sql_1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 10; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape s_shape{migraphx::shape::int32_type, {batch_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); std::vector sl_data{5, 7}; auto sql = p.add_literal(migraphx::literal{s_shape, sl_data}); auto ih = p.add_parameter("ih", ih_shape); auto hs = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, sql, ih); auto last_hs = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, last_hs}); return p; } }; struct test_rnn_sql_2 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 10; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape s_shape{migraphx::shape::int32_type, {batch_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq_orig = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); migraphx::shape pad_s{migraphx::shape::float_type, {2, batch_size, input_size}}; std::vector pad_data(pad_s.elements(), 0.0f); auto seq_pad = p.add_literal(migraphx::literal{pad_s, pad_data}); auto seq = p.add_instruction(migraphx::op::concat{0}, seq_orig, seq_pad); std::vector sl_data(batch_size, static_cast(seq_len)); auto sql = p.add_literal(migraphx::literal{s_shape, sl_data}); auto ih = p.add_parameter("ih", ih_shape); auto hs = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, sql, ih); auto last_hs = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, last_hs}); return p; } }; struct test_rnn_reverse : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r, bias, und, ih); return p; } }; struct test_rnn_reverse2 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 2; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r, bias, und, ih); return p; } }; struct test_rnn_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r); return p; } }; struct test_rnn_4args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 5; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r, bias); return p; } }; struct test_rnn_5args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 10; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 1; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto output = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_rnn_bidirectional : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto output = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, und, ih); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_rnn_bidirectional10 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 10; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto output = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, und, ih); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_rnn_bi_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 10; std::size_t hidden_size = 4; std::size_t input_size = 3; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto output = p.add_instruction(migraphx::op::rnn{hidden_size, {migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_gru_forward : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; 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 ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto hs = p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und, ih); auto lho = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({lho, hs}); return p; } }; struct test_gru_forward_3args_und : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, und, und, und); return p; } }; struct test_var_sl_gru_forward : verify_program { 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); std::vector sl_data{3, 2, 1}; auto sql = p.add_literal(migraphx::literal{sl_shape, sl_data}); auto hs = p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, sql, ih); auto lho = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({lho, hs}); return p; } }; struct test_gru_forward_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); return p; } }; struct test_gru_forward_seq1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); return p; } }; struct test_gru_forward_default_actv : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); return p; } }; struct test_gru_two_outputs : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto hs = p.add_instruction( migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); auto last_hs = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, last_hs}); return p; } }; struct test_gru_forward_default_actv1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; 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 ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction( migraphx::op::gru{ hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und, ih); return p; } }; struct test_gru_reverse_last : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; 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 ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto output = p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r, bias, und, ih); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_gru_reverse_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r); return p; } }; struct test_gru_bidirct : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; 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 ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto hs = p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, und, ih); auto lho = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, lho}); return p; } }; struct test_var_sl_gru_bidirct : verify_program { 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 = 2; float clip = 0.0f; migraphx::program p; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); std::vector sl_data{2, 1, 3}; auto sql = p.add_literal(migraphx::literal{sl_shape, sl_data}); auto hs = p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, sql, ih); auto lho = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, lho}); return p; } }; struct test_gru_bidirct_3args_und : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, und, und, und); return p; } }; struct test_gru_bidirct_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); return p; } }; struct test_gru_bidirct_seq1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); return p; } }; struct test_gru_bidirct_default_actv : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; 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}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); return p; } }; struct test_gru_bidirct_default_actv1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; 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 ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction(migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, und, ih); return p; } }; struct test_lstm_forward_last : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape l_shape{migraphx::shape::int32_type, {batch_size}}; migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto len = p.add_literal(migraphx::literal(l_shape, {1, 2})); auto ic = p.add_parameter("ic", ic_shape); auto pph = p.add_parameter("pph", pph_shape); auto output = p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, len, ih, ic, pph); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output, len); return p; } }; struct test_lstm_forward_hs : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto ic = p.add_parameter("ic", ic_shape); auto pph = p.add_parameter("pph", pph_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und, ih, ic, pph); return p; } }; struct test_lstm_forward_3args_und : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, und, und, und, und, und); return p; } }; struct test_lstm_forward_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); return p; } }; struct test_lstm_two_outputs : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto hs = p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); auto last_hs = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); p.add_return({hs, last_hs}); return p; } }; struct test_lstm_three_outputs : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto hs = p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); auto last_hs = p.add_instruction(migraphx::op::rnn_last_hs_output{}, hs); auto last_cell = p.add_instruction(migraphx::op::rnn_last_cell_output{}, hs); p.add_return({hs, last_hs, last_cell}); return p; } }; struct test_lstm_forward_seq1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); return p; } }; struct test_lstm_forward_default_actv : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::lstm{hidden_size, {}, migraphx::op::rnn_direction::forward, clip}, seq, w, r); return p; } }; struct test_lstm_forward_default_actv1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::forward, clip}, seq, w, r, bias, und, ih); return p; } }; struct test_lstm_reverse_last : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto ic = p.add_parameter("ic", ic_shape); auto pph = p.add_parameter("pph", pph_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto output = p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r, bias, und, ih, ic, pph); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_lstm_reverse_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r); return p; } }; struct test_lstm_reverse_3args_cell_output : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; 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; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto hs = p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::reverse, clip}, seq, w, r); p.add_instruction(migraphx::op::rnn_last_cell_output{}, hs); return p; } }; struct test_lstm_bidirct_last : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto ic = p.add_parameter("ic", ic_shape); auto pph = p.add_parameter("pph", pph_shape); auto und = p.add_instruction(migraphx::op::undefined{}); auto output = p.add_instruction( migraphx::op::lstm{ hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, und, ih, ic, pph); p.add_instruction(migraphx::op::rnn_last_hs_output{}, output); return p; } }; struct test_lstm_bidirct_hs : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape sl_shape{migraphx::shape::int32_type, {batch_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); std::vector sl_data{3, 2}; auto sql = p.add_literal(migraphx::literal{migraphx::literal{sl_shape, sl_data}}); p.add_instruction(migraphx::op::lstm{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, sql, ih); return p; } }; struct test_lstm_bidirct_3args_und : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction( migraphx::op::gru{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, und, und, und, und, und); return p; } }; struct test_lstm_bidirct_3args : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::lstm{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); return p; } }; struct test_lstm_bidirct_seq1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction(migraphx::op::lstm{hidden_size, {migraphx::op::sigmoid{}, migraphx::op::tanh{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); return p; } }; struct test_lstm_bidirct_default_actv : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 1; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); p.add_instruction( migraphx::op::lstm{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r); return p; } }; struct test_lstm_bidirct_default_actv1 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; migraphx::shape sl_shape{migraphx::shape::int32_type, {batch_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); std::vector sl_data(batch_size, 2); auto sql = p.add_literal(migraphx::literal{sl_shape, sl_data}); p.add_instruction(migraphx::op::lstm{hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, sql, ih); return p; } }; struct test_lstm_bidirct_default_actv2 : verify_program { migraphx::program create_program() const { std::size_t batch_size = 2; std::size_t seq_len = 3; std::size_t hidden_size = 5; std::size_t input_size = 8; std::size_t num_dirct = 2; float clip = 0.0f; migraphx::program p; migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}}; migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, input_size}}; migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, 4 * hidden_size, hidden_size}}; migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}}; migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}}; auto seq = p.add_parameter("seq", in_shape); auto w = p.add_parameter("w", w_shape); auto r = p.add_parameter("r", r_shape); auto bias = p.add_parameter("bias", b_shape); auto ih = p.add_parameter("ih", ih_shape); auto und = p.add_instruction(migraphx::op::undefined{}); p.add_instruction(migraphx::op::lstm{hidden_size, {migraphx::op::tanh{}, migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::bidirectional, clip}, seq, w, r, bias, und, ih); return p; } }; int main(int argc, const char* argv[]) { test::run(argc, argv); }