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
...@@ -9,10 +9,11 @@ struct test_add : verify_program<test_add> ...@@ -9,10 +9,11 @@ struct test_add : verify_program<test_add>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}}; migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", s); auto x = mm->add_parameter("x", s);
auto y = p.add_parameter("y", s); auto y = mm->add_parameter("y", s);
p.add_instruction(migraphx::op::add{}, x, y); mm->add_instruction(migraphx::op::add{}, x, y);
return p; return p;
} }
}; };
...@@ -10,11 +10,12 @@ struct test_add_broadcast : verify_program<test_add_broadcast> ...@@ -10,11 +10,12 @@ struct test_add_broadcast : verify_program<test_add_broadcast>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}}; migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 2, 3}}); auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 2, 3}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {2, 2}}); auto y = mm->add_parameter("y", {migraphx::shape::float_type, {2, 2}});
auto by = p.add_instruction(migraphx::op::broadcast{0, x->get_shape().lens()}, y); auto by = mm->add_instruction(migraphx::op::broadcast{0, x->get_shape().lens()}, y);
p.add_instruction(migraphx::op::add{}, x, by); mm->add_instruction(migraphx::op::add{}, x, by);
return p; return p;
} }
}; };
...@@ -10,11 +10,12 @@ struct test_add_broadcast2 : verify_program<test_add_broadcast2> ...@@ -10,11 +10,12 @@ struct test_add_broadcast2 : verify_program<test_add_broadcast2>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}}; migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 3, 4}}); auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 3, 4}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {3}}); auto y = mm->add_parameter("y", {migraphx::shape::float_type, {3}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y); auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
p.add_instruction(migraphx::op::add{}, x, by); mm->add_instruction(migraphx::op::add{}, x, by);
return p; return p;
} }
}; };
...@@ -10,11 +10,12 @@ struct test_add_broadcast3 : verify_program<test_add_broadcast3> ...@@ -10,11 +10,12 @@ struct test_add_broadcast3 : verify_program<test_add_broadcast3>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}}; migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 4, 5}}); auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 4, 5}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {4}}); auto y = mm->add_parameter("y", {migraphx::shape::float_type, {4}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y); auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
p.add_instruction(migraphx::op::add{}, x, by); mm->add_instruction(migraphx::op::add{}, x, by);
return p; return p;
} }
}; };
...@@ -10,11 +10,12 @@ struct test_add_broadcast4 : verify_program<test_add_broadcast4> ...@@ -10,11 +10,12 @@ struct test_add_broadcast4 : verify_program<test_add_broadcast4>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}}; migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 3, 5}}); auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 3, 5}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {3}}); auto y = mm->add_parameter("y", {migraphx::shape::float_type, {3}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y); auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
p.add_instruction(migraphx::op::add{}, x, by); mm->add_instruction(migraphx::op::add{}, x, by);
return p; return p;
} }
}; };
...@@ -10,11 +10,12 @@ struct test_add_broadcast5 : verify_program<test_add_broadcast5> ...@@ -10,11 +10,12 @@ struct test_add_broadcast5 : verify_program<test_add_broadcast5>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {3}}; migraphx::shape s{migraphx::shape::float_type, {3}};
auto x = p.add_parameter("x", {migraphx::shape::float_type, {2, 4, 8}}); auto x = mm->add_parameter("x", {migraphx::shape::float_type, {2, 4, 8}});
auto y = p.add_parameter("y", {migraphx::shape::float_type, {4}}); auto y = mm->add_parameter("y", {migraphx::shape::float_type, {4}});
auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y); auto by = mm->add_instruction(migraphx::op::broadcast{1, x->get_shape().lens()}, y);
p.add_instruction(migraphx::op::add{}, x, by); mm->add_instruction(migraphx::op::add{}, x, by);
return p; return p;
} }
}; };
...@@ -9,21 +9,22 @@ struct test_add_gelu : verify_program<test_add_gelu> ...@@ -9,21 +9,22 @@ struct test_add_gelu : verify_program<test_add_gelu>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
std::vector<size_t> input_lens{1, 1, 5}; std::vector<size_t> input_lens{1, 1, 5};
auto x = p.add_parameter("x", {migraphx::shape::float_type, input_lens}); auto x = mm->add_parameter("x", {migraphx::shape::float_type, input_lens});
auto y = p.add_parameter("y", {migraphx::shape::float_type, input_lens}); auto y = mm->add_parameter("y", {migraphx::shape::float_type, input_lens});
auto half = p.add_literal(0.5f); auto half = mm->add_literal(0.5f);
auto one = p.add_literal(1.0f); auto one = mm->add_literal(1.0f);
auto sqrt2 = p.add_literal(static_cast<float>(M_SQRT2)); auto sqrt2 = mm->add_literal(static_cast<float>(M_SQRT2));
auto add = p.add_instruction(migraphx::op::add{}, x, y); auto add = mm->add_instruction(migraphx::op::add{}, x, y);
auto half_mbcast = p.add_instruction(migraphx::op::multibroadcast{input_lens}, half); auto half_mbcast = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, half);
auto mul_half = p.add_instruction(migraphx::op::mul{}, add, half_mbcast); auto mul_half = mm->add_instruction(migraphx::op::mul{}, add, half_mbcast);
auto sqrt2_mbcast = p.add_instruction(migraphx::op::multibroadcast{input_lens}, sqrt2); auto sqrt2_mbcast = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, sqrt2);
auto div = p.add_instruction(migraphx::op::div{}, add, sqrt2_mbcast); auto div = mm->add_instruction(migraphx::op::div{}, add, sqrt2_mbcast);
auto erf = p.add_instruction(migraphx::op::erf{}, div); auto erf = mm->add_instruction(migraphx::op::erf{}, div);
auto one_mbcast = p.add_instruction(migraphx::op::multibroadcast{input_lens}, one); auto one_mbcast = mm->add_instruction(migraphx::op::multibroadcast{input_lens}, one);
auto add_one = p.add_instruction(migraphx::op::add{}, erf, one_mbcast); auto add_one = mm->add_instruction(migraphx::op::add{}, erf, one_mbcast);
p.add_instruction(migraphx::op::mul{}, mul_half, add_one); mm->add_instruction(migraphx::op::mul{}, mul_half, add_one);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_add_half : verify_program<test_add_half> ...@@ -9,10 +9,11 @@ struct test_add_half : verify_program<test_add_half>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::half_type, {3}}; migraphx::shape s{migraphx::shape::half_type, {3}};
auto x = p.add_parameter("x", s); auto x = mm->add_parameter("x", s);
auto y = p.add_parameter("y", s); auto y = mm->add_parameter("y", s);
p.add_instruction(migraphx::op::add{}, x, y); mm->add_instruction(migraphx::op::add{}, x, y);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_add_relu : verify_program<test_add_relu> ...@@ -9,10 +9,11 @@ struct test_add_relu : verify_program<test_add_relu>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}); auto* mm = p.get_main_module();
auto y = p.add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}); auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = p.add_instruction(migraphx::op::add{}, x, y); auto y = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::relu{}, add); auto add = mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::op::relu{}, add);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_add_sigmoid : verify_program<test_add_sigmoid> ...@@ -9,10 +9,11 @@ struct test_add_sigmoid : verify_program<test_add_sigmoid>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}); auto* mm = p.get_main_module();
auto y = p.add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}); auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = p.add_instruction(migraphx::op::add{}, x, y); auto y = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::sigmoid{}, add); auto add = mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::op::sigmoid{}, add);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_add_tanh : verify_program<test_add_tanh> ...@@ -9,10 +9,11 @@ struct test_add_tanh : verify_program<test_add_tanh>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}); auto* mm = p.get_main_module();
auto y = p.add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}); auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto add = p.add_instruction(migraphx::op::add{}, x, y); auto y = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
p.add_instruction(migraphx::op::tanh{}, add); auto add = mm->add_instruction(migraphx::op::add{}, x, y);
mm->add_instruction(migraphx::op::tanh{}, add);
return p; return p;
} }
}; };
...@@ -10,9 +10,10 @@ struct test_arg_ops : verify_program<test_arg_ops<T, Axis>> ...@@ -10,9 +10,10 @@ struct test_arg_ops : verify_program<test_arg_ops<T, Axis>>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 1025}}; migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 1025}};
auto param = p.add_parameter("data", s); auto param = mm->add_parameter("data", s);
p.add_instruction(T{Axis}, param); mm->add_instruction(T{Axis}, param);
return p; return p;
} }
......
...@@ -9,9 +9,10 @@ struct test_asin : verify_program<test_asin> ...@@ -9,9 +9,10 @@ struct test_asin : verify_program<test_asin>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {16}}; migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s); auto x = mm->add_parameter("x", s);
p.add_instruction(migraphx::op::asin{}, x); mm->add_instruction(migraphx::op::asin{}, x);
return p; return p;
} }
}; };
...@@ -9,9 +9,10 @@ struct test_asinh : verify_program<test_asinh> ...@@ -9,9 +9,10 @@ struct test_asinh : verify_program<test_asinh>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {16}}; migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s); auto x = mm->add_parameter("x", s);
p.add_instruction(migraphx::op::asinh{}, x); mm->add_instruction(migraphx::op::asinh{}, x);
return p; return p;
} }
}; };
...@@ -9,9 +9,10 @@ struct test_atan : verify_program<test_atan> ...@@ -9,9 +9,10 @@ struct test_atan : verify_program<test_atan>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {16}}; migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s); auto x = mm->add_parameter("x", s);
p.add_instruction(migraphx::op::atan{}, x); mm->add_instruction(migraphx::op::atan{}, x);
return p; return p;
} }
}; };
...@@ -9,14 +9,15 @@ struct test_atanh : verify_program<test_atanh> ...@@ -9,14 +9,15 @@ struct test_atanh : verify_program<test_atanh>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, {16}}; migraphx::shape s{migraphx::shape::double_type, {16}};
auto x = p.add_parameter("x", s); auto x = mm->add_parameter("x", s);
auto min_val = p.add_literal(-0.95); auto min_val = mm->add_literal(-0.95);
auto max_val = p.add_literal(0.95); auto max_val = mm->add_literal(0.95);
min_val = p.add_instruction(migraphx::op::multibroadcast{{16}}, min_val); min_val = mm->add_instruction(migraphx::op::multibroadcast{{16}}, min_val);
max_val = p.add_instruction(migraphx::op::multibroadcast{{16}}, max_val); max_val = mm->add_instruction(migraphx::op::multibroadcast{{16}}, max_val);
auto cx = p.add_instruction(migraphx::op::clip{}, x, min_val, max_val); auto cx = mm->add_instruction(migraphx::op::clip{}, x, min_val, max_val);
p.add_instruction(migraphx::op::atanh{}, cx); mm->add_instruction(migraphx::op::atanh{}, cx);
return p; return p;
} }
}; };
...@@ -9,9 +9,11 @@ struct test_avg_pooling_1d : verify_program<test_avg_pooling_1d> ...@@ -9,9 +9,11 @@ struct test_avg_pooling_1d : verify_program<test_avg_pooling_1d>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto input = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 5}}); auto* mm = p.get_main_module();
auto op = migraphx::op::pooling{"average", {0}, {1}, {3}}; auto input =
p.add_instruction(op, input); mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 5}});
auto op = migraphx::op::pooling{"average", {0}, {1}, {3}};
mm->add_instruction(op, input);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_avg_pooling_3d : verify_program<test_avg_pooling_3d> ...@@ -9,10 +9,11 @@ struct test_avg_pooling_3d : verify_program<test_avg_pooling_3d>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
auto input = auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 5, 5, 5}}); mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 5, 5, 5}});
auto op = migraphx::op::pooling{"average", {1, 1, 1}, {3, 3, 3}, {3, 3, 3}}; auto op = migraphx::op::pooling{"average", {1, 1, 1}, {3, 3, 3}, {3, 3, 3}};
p.add_instruction(op, input); mm->add_instruction(op, input);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_avg_pooling_3d_opt : verify_program<test_avg_pooling_3d_opt> ...@@ -9,10 +9,11 @@ struct test_avg_pooling_3d_opt : verify_program<test_avg_pooling_3d_opt>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
auto input = auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 2, 3, 3, 3}}); mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 2, 3, 3, 3}});
auto op = migraphx::op::pooling{"average", {0, 0, 0}, {1, 1, 1}, {3, 3, 3}}; auto op = migraphx::op::pooling{"average", {0, 0, 0}, {1, 1, 1}, {3, 3, 3}};
p.add_instruction(op, input); mm->add_instruction(op, input);
return p; return p;
} }
}; };
...@@ -9,10 +9,11 @@ struct test_avg_pooling_ceil_3d : verify_program<test_avg_pooling_ceil_3d> ...@@ -9,10 +9,11 @@ struct test_avg_pooling_ceil_3d : verify_program<test_avg_pooling_ceil_3d>
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module();
auto input = auto input =
p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 5, 5, 5}}); mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 5, 5, 5}});
auto op = migraphx::op::pooling{"average", {1, 1, 1}, {3, 3, 3}, {3, 3, 3}, true}; auto op = migraphx::op::pooling{"average", {1, 1, 1}, {3, 3, 3}, {3, 3, 3}, true};
p.add_instruction(op, input); mm->add_instruction(op, input);
return p; 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