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,7 +2,8 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_add_broadcast3 : verify_program<test_add_broadcast3>
......@@ -14,8 +15,9 @@ struct test_add_broadcast3 : verify_program<test_add_broadcast3>
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 4, 5}});
auto y = mm->add_parameter("y", {migraphx::shape::float_type, {4}});
auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
mm->add_instruction(migraphx::op::add{}, x, by);
auto by = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", x->get_shape().lens()}}), y);
mm->add_instruction(migraphx::make_op("add"), x, by);
return p;
}
};
......@@ -2,7 +2,8 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_add_broadcast4 : verify_program<test_add_broadcast4>
......@@ -14,8 +15,9 @@ struct test_add_broadcast4 : verify_program<test_add_broadcast4>
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 3, 5}});
auto y = mm->add_parameter("y", {migraphx::shape::float_type, {3}});
auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
mm->add_instruction(migraphx::op::add{}, x, by);
auto by = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", x->get_shape().lens()}}), y);
mm->add_instruction(migraphx::make_op("add"), x, by);
return p;
}
};
......@@ -2,7 +2,8 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_add_broadcast5 : verify_program<test_add_broadcast5>
......@@ -14,8 +15,9 @@ struct test_add_broadcast5 : verify_program<test_add_broadcast5>
migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 4, 8}});
auto y = mm->add_parameter("y", {migraphx::shape::float_type, {4}});
auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
mm->add_instruction(migraphx::op::add{}, x, by);
auto by = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", x->get_shape().lens()}}), y);
mm->add_instruction(migraphx::make_op("add"), x, by);
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_add_gelu : verify_program<test_add_gelu>
{
......@@ -11,20 +11,23 @@ struct test_add_gelu : verify_program<test_add_gelu>
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<size_t> input_lens{1, 1, 5};
auto x = mm->add_parameter("x", {migraphx::shape::float_type, input_lens});
auto y = mm->add_parameter("y", {migraphx::shape::float_type, input_lens});
auto half = mm->add_literal(0.5f);
auto one = mm->add_literal(1.0f);
auto sqrt2 = mm->add_literal(static_cast<float>(M_SQRT2));
auto add = mm->add_instruction(migraphx::op::add{}, x, y);
auto half_mbcast = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, half);
auto mul_half = mm->add_instruction(migraphx::op::mul{}, add, half_mbcast);
auto sqrt2_mbcast = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, sqrt2);
auto div = mm->add_instruction(migraphx::op::div{}, add, sqrt2_mbcast);
auto erf = mm->add_instruction(migraphx::op::erf{}, div);
auto one_mbcast = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, one);
auto add_one = mm->add_instruction(migraphx::op::add{}, erf, one_mbcast);
mm->add_instruction(migraphx::op::mul{}, mul_half, add_one);
auto x = mm->add_parameter("x", {migraphx::shape::float_type, input_lens});
auto y = mm->add_parameter("y", {migraphx::shape::float_type, input_lens});
auto half = mm->add_literal(0.5f);
auto one = mm->add_literal(1.0f);
auto sqrt2 = mm->add_literal(static_cast<float>(M_SQRT2));
auto add = mm->add_instruction(migraphx::make_op("add"), x, y);
auto half_mbcast = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", input_lens}}), half);
auto mul_half = mm->add_instruction(migraphx::make_op("mul"), add, half_mbcast);
auto sqrt2_mbcast = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", input_lens}}), sqrt2);
auto div = mm->add_instruction(migraphx::make_op("div"), add, sqrt2_mbcast);
auto erf = mm->add_instruction(migraphx::make_op("erf"), div);
auto one_mbcast = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", input_lens}}), one);
auto add_one = mm->add_instruction(migraphx::make_op("add"), erf, one_mbcast);
mm->add_instruction(migraphx::make_op("mul"), mul_half, add_one);
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_add_half : verify_program<test_add_half>
{
......@@ -13,7 +13,7 @@ struct test_add_half : verify_program<test_add_half>
migraphx::shape s{migraphx::shape::half_type, {3}};
auto x = mm->add_parameter("x", s);
auto y = mm->add_parameter("y", s);
mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::make_op("add"), x, y);
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_add_relu : verify_program<test_add_relu>
{
......@@ -12,8 +12,8 @@ struct test_add_relu : verify_program<test_add_relu>
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto y = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::op::relu{}, add);
auto add = mm->add_instruction(migraphx::make_op("add"), x, y);
mm->add_instruction(migraphx::make_op("relu"), add);
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_add_sigmoid : verify_program<test_add_sigmoid>
{
......@@ -12,8 +12,8 @@ struct test_add_sigmoid : verify_program<test_add_sigmoid>
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto y = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::op::sigmoid{}, add);
auto add = mm->add_instruction(migraphx::make_op("add"), x, y);
mm->add_instruction(migraphx::make_op("sigmoid"), add);
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_add_tanh : verify_program<test_add_tanh>
{
......@@ -12,8 +12,8 @@ struct test_add_tanh : verify_program<test_add_tanh>
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto y = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::op::tanh{}, add);
auto add = mm->add_instruction(migraphx::make_op("add"), x, y);
mm->add_instruction(migraphx::make_op("tanh"), add);
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_asin : verify_program<test_asin>
{
......@@ -12,7 +12,7 @@ struct test_asin : verify_program<test_asin>
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::asin{}, x);
mm->add_instruction(migraphx::make_op("asin"), 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_asinh : verify_program<test_asinh>
{
......@@ -12,7 +12,7 @@ struct test_asinh : verify_program<test_asinh>
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::asinh{}, x);
mm->add_instruction(migraphx::make_op("asinh"), 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_atan : verify_program<test_atan>
{
......@@ -12,7 +12,7 @@ struct test_atan : verify_program<test_atan>
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::atan{}, x);
mm->add_instruction(migraphx::make_op("atan"), 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_atanh : verify_program<test_atanh>
{
......@@ -14,10 +14,12 @@ struct test_atanh : verify_program<test_atanh>
auto x = mm->add_parameter("x", s);
auto min_val = mm->add_literal(-0.95);
auto max_val = mm->add_literal(0.95);
min_val = mm->add_instruction(migraphx::op::multibroadcast{{16}}, min_val);
max_val = mm->add_instruction(migraphx::op::multibroadcast{{16}}, max_val);
auto cx = mm->add_instruction(migraphx::op::clip{}, x, min_val, max_val);
mm->add_instruction(migraphx::op::atanh{}, cx);
min_val = mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {16}}}),
min_val);
max_val = mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {16}}}),
max_val);
auto cx = mm->add_instruction(migraphx::make_op("clip"), x, min_val, max_val);
mm->add_instruction(migraphx::make_op("atanh"), cx);
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_batchnorm_1d : verify_program<test_batchnorm_1d>
{
......@@ -22,7 +22,8 @@ struct test_batchnorm_1d : verify_program<test_batchnorm_1d>
auto bias = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
mm->add_instruction(
migraphx::make_op("batch_norm_inference"), x, scale, bias, mean, variance);
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_batchnorm_1d_per_actv : verify_program<test_batchnorm_1d_per_actv>
......@@ -23,8 +27,12 @@ struct test_batchnorm_1d_per_actv : verify_program<test_batchnorm_1d_per_actv>
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(
migraphx::op::batch_norm_inference{
1.0e-5, 0.96f, migraphx::op::batch_norm_inference::per_activation},
migraphx::make_op(
"batch_norm_inference",
{{"epsilon", 1.0e-5},
{"momentum", 0.96f},
{"bn_mode",
migraphx::to_value(migraphx::op::batch_norm_inference::per_activation)}}),
x,
scale,
bias,
......
......@@ -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_batchnorm_2d_per_actv : verify_program<test_batchnorm_2d_per_actv>
......@@ -24,8 +28,12 @@ struct test_batchnorm_2d_per_actv : verify_program<test_batchnorm_2d_per_actv>
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(
migraphx::op::batch_norm_inference{
1.0e-6, 0.9f, migraphx::op::batch_norm_inference::per_activation},
migraphx::make_op(
"batch_norm_inference",
{{"epsilon", 1.0e-6},
{"momentum", 0.9f},
{"bn_mode",
migraphx::to_value(migraphx::op::batch_norm_inference::per_activation)}}),
x,
scale,
bias,
......
......@@ -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_batchnorm_3d : verify_program<test_batchnorm_3d>
{
......@@ -24,7 +24,8 @@ struct test_batchnorm_3d : verify_program<test_batchnorm_3d>
auto bias = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
mm->add_instruction(
migraphx::make_op("batch_norm_inference"), x, scale, bias, mean, variance);
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_batchnorm_3d_per_actv : verify_program<test_batchnorm_3d_per_actv>
......@@ -25,8 +29,12 @@ struct test_batchnorm_3d_per_actv : verify_program<test_batchnorm_3d_per_actv>
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(
migraphx::op::batch_norm_inference{
1.0e-6, 0.8f, migraphx::op::batch_norm_inference::per_activation},
migraphx::make_op(
"batch_norm_inference",
{{"epsilon", 1.0e-6},
{"momentum", 0.8f},
{"bn_mode",
migraphx::to_value(migraphx::op::batch_norm_inference::per_activation)}}),
x,
scale,
bias,
......
......@@ -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_batchnorm_inference : verify_program<test_batchnorm_inference>
{
......@@ -23,7 +23,8 @@ struct test_batchnorm_inference : verify_program<test_batchnorm_inference>
auto bias = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
mm->add_instruction(
migraphx::make_op("batch_norm_inference"), x, scale, bias, mean, variance);
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_batchnorm_inference_2 : verify_program<test_batchnorm_inference_2>
{
......@@ -23,7 +23,8 @@ struct test_batchnorm_inference_2 : verify_program<test_batchnorm_inference_2>
auto bias = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
mm->add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
mm->add_instruction(
migraphx::make_op("batch_norm_inference"), x, scale, bias, mean, variance);
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_ceil : verify_program<test_ceil>
{
......@@ -13,7 +13,7 @@ struct test_ceil : verify_program<test_ceil>
migraphx::shape s{migraphx::shape::double_type, {2, 3, 4, 6}};
auto param = mm->add_parameter("x", s);
mm->add_instruction(migraphx::op::ceil{}, param);
mm->add_instruction(migraphx::make_op("ceil"), param);
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