Unverified Commit 2466dd6f authored by Shucai Xiao's avatar Shucai Xiao Committed by GitHub
Browse files

Refactor program to module (#684)



* code backup

* clang format

* change corresponding tool files

* clang format
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
parent de10423f
......@@ -16,29 +16,30 @@ struct test_rnn_reverse : verify_program<test_rnn_reverse>
float clip = 0.0f;
migraphx::program p;
auto* mm = p.get_main_module();
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 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);
auto und = mm->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);
mm->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;
}
......
......@@ -16,29 +16,30 @@ struct test_rnn_reverse2 : verify_program<test_rnn_reverse2>
float clip = 0.0f;
migraphx::program p;
auto* mm = p.get_main_module();
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 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);
auto und = mm->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);
mm->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;
}
......
......@@ -16,6 +16,7 @@ struct test_rnn_sql_1 : verify_program<test_rnn_sql_1>
float clip = 0.0f;
migraphx::program p;
auto* mm = p.get_main_module();
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}};
......@@ -23,26 +24,27 @@ struct test_rnn_sql_1 : verify_program<test_rnn_sql_1>
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);
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);
std::vector<int> sl_data{5, 7};
auto sql = p.add_literal(migraphx::literal{s_shape, sl_data});
auto ih = p.add_parameter("ih", ih_shape);
auto sql = mm->add_literal(migraphx::literal{s_shape, sl_data});
auto ih = mm->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});
auto hs =
mm->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 = mm->add_instruction(migraphx::op::rnn_last_hs_output{}, hs);
mm->add_return({hs, last_hs});
return p;
}
......
......@@ -16,6 +16,7 @@ struct test_rnn_sql_2 : verify_program<test_rnn_sql_2>
float clip = 0.0f;
migraphx::program p;
auto* mm = p.get_main_module();
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}};
......@@ -23,30 +24,31 @@ struct test_rnn_sql_2 : verify_program<test_rnn_sql_2>
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);
auto seq_orig = 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);
migraphx::shape pad_s{migraphx::shape::float_type, {2, batch_size, input_size}};
std::vector<float> 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);
auto seq_pad = mm->add_literal(migraphx::literal{pad_s, pad_data});
auto seq = mm->add_instruction(migraphx::op::concat{0}, seq_orig, seq_pad);
std::vector<int> sl_data(batch_size, static_cast<int>(seq_len));
auto sql = p.add_literal(migraphx::literal{s_shape, sl_data});
auto ih = p.add_parameter("ih", ih_shape);
auto sql = mm->add_literal(migraphx::literal{s_shape, sl_data});
auto ih = mm->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});
auto hs =
mm->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 = mm->add_instruction(migraphx::op::rnn_last_hs_output{}, hs);
mm->add_return({hs, last_hs});
return p;
}
......
......@@ -9,10 +9,11 @@ struct test_round : verify_program<test_round>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 6}};
auto param = p.add_parameter("x", s);
p.add_instruction(migraphx::op::round{}, param);
auto param = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::round{}, param);
return p;
};
};
......@@ -9,15 +9,16 @@ struct test_rsqrt : verify_program<test_rsqrt>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<size_t> input_lens{1, 3, 16, 16};
migraphx::shape s{migraphx::shape::float_type, input_lens};
auto x = p.add_parameter("x", s);
auto min_val = p.add_literal(1.0f);
auto max_val = p.add_literal(std::numeric_limits<float>::max());
min_val = p.add_instruction(migraphx::op::multibroadcast{input_lens}, min_val);
max_val = p.add_instruction(migraphx::op::multibroadcast{input_lens}, max_val);
auto l0 = p.add_instruction(migraphx::op::clip{}, x, min_val, max_val);
p.add_instruction(migraphx::op::rsqrt{}, l0);
auto x = mm->add_parameter("x", s);
auto min_val = mm->add_literal(1.0f);
auto max_val = mm->add_literal(std::numeric_limits<float>::max());
min_val = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, min_val);
max_val = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, max_val);
auto l0 = mm->add_instruction(migraphx::op::clip{}, x, min_val, max_val);
mm->add_instruction(migraphx::op::rsqrt{}, l0);
return p;
};
};
......@@ -9,11 +9,12 @@ struct test_scale : verify_program<test_scale>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", migraphx::shape::float_type);
auto scale = p.add_instruction(migraphx::op::scalar{s.lens()}, y);
p.add_instruction(migraphx::op::mul{}, x, scale);
auto x = mm->add_parameter("x", s);
auto y = mm->add_parameter("y", migraphx::shape::float_type);
auto scale = mm->add_instruction(migraphx::op::scalar{s.lens()}, y);
mm->add_instruction(migraphx::op::mul{}, x, scale);
return p;
}
};
......@@ -9,8 +9,9 @@ struct test_sigmoid : verify_program<test_sigmoid>
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::sigmoid{}, x);
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
mm->add_instruction(migraphx::op::sigmoid{}, x);
return p;
}
};
......@@ -9,9 +9,10 @@ struct test_sign : verify_program<test_sign>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {2, 3, 4, 6}};
auto param = p.add_parameter("x", s);
p.add_instruction(migraphx::op::sign{}, param);
auto param = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::sign{}, param);
return p;
}
};
......@@ -9,9 +9,10 @@ struct test_sin : verify_program<test_sin>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {10}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::sin{}, x);
auto x = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::sin{}, x);
return p;
}
};
......@@ -9,9 +9,10 @@ struct test_sinh : verify_program<test_sinh>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::sinh{}, x);
auto x = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::sinh{}, x);
return p;
}
};
......@@ -9,11 +9,12 @@ struct test_slice : verify_program<test_slice>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int32_type, {2, 2, 4}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", {migraphx::shape::int32_type, {2, 2, 2}});
auto slice0 = p.add_instruction(migraphx::op::slice{{2}, {0}, {2}}, x);
p.add_instruction(migraphx::op::add{}, y, slice0);
auto x = mm->add_parameter("x", s);
auto y = mm->add_parameter("y", {migraphx::shape::int32_type, {2, 2, 2}});
auto slice0 = mm->add_instruction(migraphx::op::slice{{2}, {0}, {2}}, x);
mm->add_instruction(migraphx::op::add{}, y, slice0);
return p;
}
......
......@@ -9,9 +9,10 @@ struct test_slice_sin : verify_program<test_slice_sin>
migraphx::program create_program() const
{
migraphx::program p;
auto l = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {2, 2}});
auto t = p.add_instruction(migraphx::op::slice{{1}, {1}, {2}}, l);
p.add_instruction(migraphx::op::sin{}, t);
auto* mm = p.get_main_module();
auto l = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {2, 2}});
auto t = mm->add_instruction(migraphx::op::slice{{1}, {1}, {2}}, l);
mm->add_instruction(migraphx::op::sin{}, t);
return p;
}
......
......@@ -10,9 +10,10 @@ struct test_softmax : verify_program<test_softmax<Axis, T>>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{T, {512, 4, 1067, 6}};
auto param = p.add_parameter("0", s);
p.add_instruction(migraphx::op::softmax{Axis}, param);
auto param = mm->add_parameter("0", s);
mm->add_instruction(migraphx::op::softmax{Axis}, param);
return p;
}
......
......@@ -9,8 +9,9 @@ struct test_softmax1 : verify_program<test_softmax1>
migraphx::program create_program() const
{
migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {5, 3, 3, 4}});
p.add_instruction(migraphx::op::softmax{0}, x);
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {5, 3, 3, 4}});
mm->add_instruction(migraphx::op::softmax{0}, x);
return p;
}
};
......@@ -9,9 +9,10 @@ struct test_softmax2 : verify_program<test_softmax2>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto x =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1000, 1, 1}});
p.add_instruction(migraphx::op::softmax{}, x);
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1000, 1, 1}});
mm->add_instruction(migraphx::op::softmax{}, x);
return p;
}
};
......@@ -9,10 +9,11 @@ struct test_sqrt : verify_program<test_sqrt>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 6}};
auto param = p.add_parameter("x", s);
auto param_abs = p.add_instruction(migraphx::op::abs{}, param);
p.add_instruction(migraphx::op::sqrt{}, param_abs);
auto param = mm->add_parameter("x", s);
auto param_abs = mm->add_instruction(migraphx::op::abs{}, param);
mm->add_instruction(migraphx::op::sqrt{}, param_abs);
return p;
}
};
......@@ -9,12 +9,13 @@ struct test_sub : verify_program<test_sub>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
auto z = p.add_parameter("z", s);
auto diff = p.add_instruction(migraphx::op::sub{}, x, y);
p.add_instruction(migraphx::op::sub{}, diff, z);
auto x = mm->add_parameter("x", s);
auto y = mm->add_parameter("y", s);
auto z = mm->add_parameter("z", s);
auto diff = mm->add_instruction(migraphx::op::sub{}, x, y);
mm->add_instruction(migraphx::op::sub{}, diff, z);
return p;
}
};
......@@ -9,14 +9,15 @@ struct test_sub2 : verify_program<test_sub2>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3}};
migraphx::shape b{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s);
auto y = p.add_parameter("y", s);
auto z = p.add_parameter("z", b);
auto zb = p.add_instruction(migraphx::op::broadcast{1, s.lens()}, z);
auto diff = p.add_instruction(migraphx::op::sub{}, x, y);
p.add_instruction(migraphx::op::sub{}, diff, zb);
auto x = mm->add_parameter("x", s);
auto y = mm->add_parameter("y", s);
auto z = mm->add_parameter("z", b);
auto zb = mm->add_instruction(migraphx::op::broadcast{1, s.lens()}, z);
auto diff = mm->add_instruction(migraphx::op::sub{}, x, y);
mm->add_instruction(migraphx::op::sub{}, diff, zb);
return p;
}
};
......@@ -9,9 +9,10 @@ struct test_tan : verify_program<test_tan>
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {16}};
auto x = p.add_parameter("x", s);
p.add_instruction(migraphx::op::tan{}, x);
auto x = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::tan{}, x);
return p;
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment