Unverified Commit 8d21fdc9 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Refactor to use make_op almost everywhere (#696)

* Load op when serializing

* Formatting

* Add missing clip field

* Use make_op almost everywhere

* Formatting

* More make ops for rnns

* Get rid of spaces

* Formatting

* Remove operators headers

* Formatting

* Remove unused op headers

* Increase line threshold
parent b5633c27
......@@ -2,6 +2,10 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/operators.hpp>
struct test_rnn_forward10 : verify_program<test_rnn_forward10>
......@@ -28,20 +32,24 @@ struct test_rnn_forward10 : verify_program<test_rnn_forward10>
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{});
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,
und,
ih);
auto lho = mm->add_instruction(migraphx::op::rnn_last_hs_output{}, hs);
auto und = mm->add_instruction(migraphx::make_op("undefined"));
auto hs = mm->add_instruction(
migraphx::make_op(
"rnn",
{{"hidden_size", hidden_size},
{"actv_func",
migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh"),
migraphx::make_op("tanh")})},
{"direction", migraphx::to_value(migraphx::op::rnn_direction::forward)},
{"clip", clip}}),
seq,
w,
r,
bias,
und,
ih);
auto lho = mm->add_instruction(migraphx::make_op("rnn_last_hs_output"), hs);
mm->add_return({hs, lho});
return p;
......
......@@ -2,6 +2,10 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/operators.hpp>
struct test_rnn_reverse : verify_program<test_rnn_reverse>
......@@ -28,18 +32,23 @@ struct test_rnn_reverse : verify_program<test_rnn_reverse>
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{});
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);
auto und = mm->add_instruction(migraphx::make_op("undefined"));
mm->add_instruction(
migraphx::make_op(
"rnn",
{{"hidden_size", hidden_size},
{"actv_func",
migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh"),
migraphx::make_op("tanh")})},
{"direction", migraphx::to_value(migraphx::op::rnn_direction::reverse)},
{"clip", clip}}),
seq,
w,
r,
bias,
und,
ih);
return p;
}
......
......@@ -2,6 +2,10 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/operators.hpp>
struct test_rnn_reverse2 : verify_program<test_rnn_reverse2>
......@@ -28,18 +32,23 @@ struct test_rnn_reverse2 : verify_program<test_rnn_reverse2>
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{});
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);
auto und = mm->add_instruction(migraphx::make_op("undefined"));
mm->add_instruction(
migraphx::make_op(
"rnn",
{{"hidden_size", hidden_size},
{"actv_func",
migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh"),
migraphx::make_op("tanh")})},
{"direction", migraphx::to_value(migraphx::op::rnn_direction::reverse)},
{"clip", clip}}),
seq,
w,
r,
bias,
und,
ih);
return p;
}
......
......@@ -2,6 +2,10 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/operators.hpp>
struct test_rnn_sql_1 : verify_program<test_rnn_sql_1>
......@@ -32,18 +36,22 @@ struct test_rnn_sql_1 : verify_program<test_rnn_sql_1>
auto sql = mm->add_literal(migraphx::literal{s_shape, sl_data});
auto ih = mm->add_parameter("ih", ih_shape);
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);
auto hs = mm->add_instruction(
migraphx::make_op(
"rnn",
{{"hidden_size", hidden_size},
{"actv_func",
migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh"),
migraphx::make_op("tanh")})},
{"direction", migraphx::to_value(migraphx::op::rnn_direction::forward)},
{"clip", clip}}),
seq,
w,
r,
bias,
sql,
ih);
auto last_hs = mm->add_instruction(migraphx::make_op("rnn_last_hs_output"), hs);
mm->add_return({hs, last_hs});
return p;
......
......@@ -2,6 +2,10 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/operators.hpp>
struct test_rnn_sql_2 : verify_program<test_rnn_sql_2>
......@@ -31,23 +35,28 @@ struct test_rnn_sql_2 : verify_program<test_rnn_sql_2>
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 = mm->add_literal(migraphx::literal{pad_s, pad_data});
auto seq = mm->add_instruction(migraphx::op::concat{0}, seq_orig, seq_pad);
auto seq =
mm->add_instruction(migraphx::make_op("concat", {{"axis", 0}}), seq_orig, seq_pad);
std::vector<int> sl_data(batch_size, static_cast<int>(seq_len));
auto sql = mm->add_literal(migraphx::literal{s_shape, sl_data});
auto ih = mm->add_parameter("ih", ih_shape);
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);
auto hs = mm->add_instruction(
migraphx::make_op(
"rnn",
{{"hidden_size", hidden_size},
{"actv_func",
migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh"),
migraphx::make_op("tanh")})},
{"direction", migraphx::to_value(migraphx::op::rnn_direction::forward)},
{"clip", clip}}),
seq,
w,
r,
bias,
sql,
ih);
auto last_hs = mm->add_instruction(migraphx::make_op("rnn_last_hs_output"), hs);
mm->add_return({hs, last_hs});
return p;
......
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_round : verify_program<test_round>
{
......@@ -13,7 +13,7 @@ struct test_round : verify_program<test_round>
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 6}};
auto param = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::round{}, param);
mm->add_instruction(migraphx::make_op("round"), param);
return p;
};
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_rsqrt : verify_program<test_rsqrt>
{
......@@ -15,10 +15,12 @@ struct test_rsqrt : verify_program<test_rsqrt>
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);
min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", input_lens}}), min_val);
max_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", input_lens}}), max_val);
auto l0 = mm->add_instruction(migraphx::make_op("clip"), x, min_val, max_val);
mm->add_instruction(migraphx::make_op("rsqrt"), l0);
return p;
};
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_scale : verify_program<test_scale>
{
......@@ -11,10 +11,11 @@ struct test_scale : verify_program<test_scale>
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}};
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);
auto x = mm->add_parameter("x", s);
auto y = mm->add_parameter("y", migraphx::shape::float_type);
auto scale =
mm->add_instruction(migraphx::make_op("scalar", {{"scalar_bcst_dims", s.lens()}}), y);
mm->add_instruction(migraphx::make_op("mul"), x, scale);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sigmoid : verify_program<test_sigmoid>
{
......@@ -11,7 +11,7 @@ struct test_sigmoid : verify_program<test_sigmoid>
migraphx::program p;
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);
mm->add_instruction(migraphx::make_op("sigmoid"), x);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sign : verify_program<test_sign>
{
......@@ -12,7 +12,7 @@ struct test_sign : verify_program<test_sign>
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {2, 3, 4, 6}};
auto param = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::sign{}, param);
mm->add_instruction(migraphx::make_op("sign"), param);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sin : verify_program<test_sin>
{
......@@ -12,7 +12,7 @@ struct test_sin : verify_program<test_sin>
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {10}};
auto x = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::sin{}, x);
mm->add_instruction(migraphx::make_op("sin"), x);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sinh : verify_program<test_sinh>
{
......@@ -12,7 +12,7 @@ struct test_sinh : verify_program<test_sinh>
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::sinh{}, x);
mm->add_instruction(migraphx::make_op("sinh"), x);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_slice : verify_program<test_slice>
{
......@@ -13,8 +13,9 @@ struct test_slice : verify_program<test_slice>
migraphx::shape s{migraphx::shape::int32_type, {2, 2, 4}};
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);
auto slice0 = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {2}}, {"starts", {0}}, {"ends", {2}}}), x);
mm->add_instruction(migraphx::make_op("add"), y, slice0);
return p;
}
......
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_slice_sin : verify_program<test_slice_sin>
{
......@@ -11,8 +11,9 @@ struct test_slice_sin : verify_program<test_slice_sin>
migraphx::program p;
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);
auto t = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {1}}, {"starts", {1}}, {"ends", {2}}}), l);
mm->add_instruction(migraphx::make_op("sin"), t);
return p;
}
......
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
template <int Axis, migraphx::shape::type_t T>
struct test_softmax : verify_program<test_softmax<Axis, T>>
......@@ -13,7 +13,7 @@ struct test_softmax : verify_program<test_softmax<Axis, T>>
auto* mm = p.get_main_module();
migraphx::shape s{T, {512, 4, 1067, 6}};
auto param = mm->add_parameter("0", s);
mm->add_instruction(migraphx::op::softmax{Axis}, param);
mm->add_instruction(migraphx::make_op("softmax", {{"axis", Axis}}), param);
return p;
}
......
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_softmax1 : verify_program<test_softmax1>
{
......@@ -11,7 +11,7 @@ struct test_softmax1 : verify_program<test_softmax1>
migraphx::program p;
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);
mm->add_instruction(migraphx::make_op("softmax", {{"axis", 0}}), x);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_softmax2 : verify_program<test_softmax2>
{
......@@ -12,7 +12,7 @@ struct test_softmax2 : verify_program<test_softmax2>
auto* mm = p.get_main_module();
auto x =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1000, 1, 1}});
mm->add_instruction(migraphx::op::softmax{}, x);
mm->add_instruction(migraphx::make_op("softmax"), x);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sqrt : verify_program<test_sqrt>
{
......@@ -12,8 +12,8 @@ struct test_sqrt : verify_program<test_sqrt>
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 6}};
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);
auto param_abs = mm->add_instruction(migraphx::make_op("abs"), param);
mm->add_instruction(migraphx::make_op("sqrt"), param_abs);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sub : verify_program<test_sub>
{
......@@ -14,8 +14,8 @@ struct test_sub : verify_program<test_sub>
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);
auto diff = mm->add_instruction(migraphx::make_op("sub"), x, y);
mm->add_instruction(migraphx::make_op("sub"), diff, z);
return p;
}
};
......@@ -2,7 +2,7 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
struct test_sub2 : verify_program<test_sub2>
{
......@@ -12,12 +12,13 @@ struct test_sub2 : verify_program<test_sub2>
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 = 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);
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::make_op("broadcast", {{"axis", 1}, {"dims", s.lens()}}), z);
auto diff = mm->add_instruction(migraphx::make_op("sub"), x, y);
mm->add_instruction(migraphx::make_op("sub"), diff, zb);
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