Commit d3d8b5da authored by Umang Yadav's avatar Umang Yadav
Browse files

add conv tests supported by MLIR

parent ecdb14f8
......@@ -190,10 +190,10 @@ auto is_mlir_conv(mlir_mode mode)
// Avoid MLIR assertion: Index < Length && "Invalid index!"
if(ins->get_shape().lens().size() != 4)
return false;
if(ins->get_shape().type() == shape::int8_type)
return true;
if(ins->get_shape().type() == shape::fp8e4m3fnuz_type)
return true;
if(ins->get_shape().type() == shape::int8_type)
return true;
if(mode == mlir_mode::int8)
return false;
if(mode == mlir_mode::all)
......
......@@ -27,17 +27,19 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_conv : verify_program<test_conv>
template <migraphx::shape::type_t DType>
struct test_conv : verify_program<test_conv<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto weights =
mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto input = mm->add_parameter("x", migraphx::shape{DType, {4, 3, 3, 3}});
auto weights = mm->add_parameter("w", migraphx::shape{DType, {4, 3, 3, 3}});
mm->add_instruction(migraphx::make_op("convolution"), input, weights);
return p;
}
};
template struct test_conv<migraphx::shape::float_type>;
template struct test_conv<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,16 +27,17 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_conv2 : verify_program<test_conv2>
template <migraphx::shape::type_t DType>
struct test_conv2 : verify_program<test_conv2<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 512, 28, 28}});
mm->add_parameter("x", migraphx::shape{DType, {1, 512, 28, 28}});
auto weights =
mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {256, 512, 1, 1}});
mm->add_parameter("w", migraphx::shape{DType, {256, 512, 1, 1}});
mm->add_instruction(
migraphx::make_op("convolution",
{{"padding", {0, 0}}, {"stride", {1, 1}}, {"dilation", {1, 1}}}),
......@@ -45,3 +46,5 @@ struct test_conv2 : verify_program<test_conv2>
return p;
}
};
template struct test_conv2<migraphx::shape::float_type>;
template struct test_conv2<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,18 +27,17 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_conv_add : verify_program<test_conv_add>
template <migraphx::shape::type_t DType>
struct test_conv_add : verify_program<test_conv_add<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", {migraphx::shape::float_type, {1, 8, 4, 4}});
auto w = mm->add_literal(
migraphx::generate_literal({migraphx::shape::float_type, {2, 8, 3, 3}}, 1));
auto y = mm->add_parameter("y", {migraphx::shape::float_type, {1, 8, 4, 4}});
auto v = mm->add_literal(
migraphx::generate_literal({migraphx::shape::float_type, {2, 8, 3, 3}}, 2));
auto x = mm->add_parameter("x", {DType, {1, 8, 4, 4}});
auto w = mm->add_literal(migraphx::generate_literal({DType, {2, 8, 3, 3}}, 1));
auto y = mm->add_parameter("y", {DType, {1, 8, 4, 4}});
auto v = mm->add_literal(migraphx::generate_literal({DType, {2, 8, 3, 3}}, 2));
auto conv1 = mm->add_instruction(migraphx::make_op("convolution"), x, w);
auto conv2 = mm->add_instruction(migraphx::make_op("convolution"), y, v);
auto sum = mm->add_instruction(migraphx::make_op("add"), conv1, conv2);
......@@ -46,3 +45,6 @@ struct test_conv_add : verify_program<test_conv_add>
return p;
}
};
template struct test_conv_add<migraphx::shape::float_type>;
template struct test_conv_add<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -28,17 +28,18 @@
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_conv_add_relu : verify_program<test_conv_add_relu>
template <migraphx::shape::type_t DType>
struct test_conv_add_relu : verify_program<test_conv_add_relu<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
mm->add_parameter("x", migraphx::shape{DType, {4, 3, 3, 3}});
auto weights =
mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto bias_literal = migraphx::literal{migraphx::shape{migraphx::shape::float_type, {4}},
mm->add_parameter("w", migraphx::shape{DType, {4, 3, 3, 3}});
auto bias_literal = migraphx::literal{migraphx::shape{DType, {4}},
{2.0f, 2.0f, 2.0f, 2.0f}};
auto bias = mm->add_literal(bias_literal);
auto conv = mm->add_instruction(migraphx::make_op("convolution"), input, weights);
......@@ -50,3 +51,6 @@ struct test_conv_add_relu : verify_program<test_conv_add_relu>
return p;
}
};
template struct test_conv_add_relu<migraphx::shape::float_type>;
template struct test_conv_add_relu<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -29,26 +29,24 @@
#include <migraphx/instruction.hpp>
struct test_conv_bias_clipped_relu : verify_program<test_conv_bias_clipped_relu>
template <migraphx::shape::type_t DType>
struct test_conv_bias_clipped_relu : verify_program<test_conv_bias_clipped_relu<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto weights =
mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto l0 = migraphx::literal{migraphx::shape{migraphx::shape::float_type, {4}},
{2.0f, 2.0f, 2.0f, 2.0f}};
auto input = mm->add_parameter("x", migraphx::shape{DType, {4, 3, 3, 3}});
auto weights = mm->add_parameter("w", migraphx::shape{DType, {4, 3, 3, 3}});
auto l0 = migraphx::literal{migraphx::shape{DType, {4}}, {2.0f, 2.0f, 2.0f, 2.0f}};
auto bias = mm->add_literal(l0);
auto conv = mm->add_instruction(migraphx::make_op("convolution"), input, weights);
auto bcast_add = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", conv->get_shape().lens()}}),
bias);
auto bias_add = mm->add_instruction(migraphx::make_op("add"), conv, bcast_add);
auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f);
auto min_val = mm->add_literal(migraphx::literal(DType, {0.0f}));
auto max_val = mm->add_literal(migraphx::literal(DType, {6.0f}));
min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", conv->get_shape().lens()}}), min_val);
max_val = mm->add_instruction(
......@@ -57,3 +55,6 @@ struct test_conv_bias_clipped_relu : verify_program<test_conv_bias_clipped_relu>
return p;
}
};
template struct test_conv_bias_clipped_relu<migraphx::shape::float_type>;
template struct test_conv_bias_clipped_relu<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -29,22 +29,27 @@
#include <migraphx/instruction.hpp>
#include <migraphx/common.hpp>
struct test_conv_bn_add : verify_program<test_conv_bn_add>
template <migraphx::shape::type_t DType>
struct test_conv_bn_add : verify_program<test_conv_bn_add<DType>>
{
static migraphx::instruction_ref add_bn(migraphx::module& m, migraphx::instruction_ref x)
{
auto bn_lens = x->get_shape().lens();
auto c_len = bn_lens.at(1);
migraphx::shape vars{migraphx::shape::float_type, {c_len}};
migraphx::shape vars{DType, {c_len}};
auto scale = m.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1 + c_len)));
auto bias = m.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2 + c_len)));
auto mean = m.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3 + c_len)));
auto variance = m.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4 + c_len)));
auto rt = m.add_literal(migraphx::literal{migraphx::shape::float_type, {0.5}});
auto eps = m.add_literal(migraphx::literal{migraphx::shape::float_type, {1e-5f}});
auto rt = m.add_literal(migraphx::literal{DType, {0.5}});
auto eps = m.add_literal(migraphx::literal{DType, {1e-5f}});
if constexpr((DType) == migraphx::shape::fp8e4m3fnuz_type)
{
// use 5e-2f for the fp8
eps = m.add_literal(migraphx::literal{DType, {5e-2f}});
}
auto usq_scale =
m.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), scale);
auto usq_bias = m.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), bias);
......@@ -66,12 +71,12 @@ struct test_conv_bn_add : verify_program<test_conv_bn_add>
auto* mm = p.get_main_module();
std::size_t ichannels = 64;
std::size_t ochannels = 256;
auto x = mm->add_parameter("x", {migraphx::shape::float_type, {1, ichannels, 56, 56}});
auto w = mm->add_literal(migraphx::generate_literal(
{migraphx::shape::float_type, {ochannels, ichannels, 1, 1}}, 1));
auto y = mm->add_parameter("y", {migraphx::shape::float_type, {1, ichannels, 56, 56}});
auto v = mm->add_literal(migraphx::generate_literal(
{migraphx::shape::float_type, {ochannels, ichannels, 1, 1}}, 2));
auto x = mm->add_parameter("x", {DType, {1, ichannels, 56, 56}});
auto w =
mm->add_literal(migraphx::generate_literal({DType, {ochannels, ichannels, 1, 1}}, 1));
auto y = mm->add_parameter("y", {DType, {1, ichannels, 56, 56}});
auto v =
mm->add_literal(migraphx::generate_literal({DType, {ochannels, ichannels, 1, 1}}, 2));
auto relu1 = mm->add_instruction(migraphx::make_op("relu"), x);
auto conv1 = mm->add_instruction(migraphx::make_op("convolution"), relu1, w);
auto bn1 = add_bn(*mm, conv1);
......@@ -83,3 +88,6 @@ struct test_conv_bn_add : verify_program<test_conv_bn_add>
return p;
}
};
template struct test_conv_bn_add<migraphx::shape::float_type>;
template struct test_conv_bn_add<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -55,7 +55,11 @@ struct test_conv_bn_relu_pooling : verify_program<test_conv_bn_relu_pooling<DTyp
auto rt = mm->add_literal(migraphx::literal{DType, {0.5}});
auto eps = mm->add_literal(migraphx::literal{DType, {1e-5f}});
if constexpr((DType) == migraphx::shape::fp8e4m3fnuz_type)
{
// use 5e-2f for the fp8
eps = mm->add_literal(migraphx::literal{DType, {5e-2f}});
}
auto usq_scale =
mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), scale);
auto usq_bias =
......
......@@ -46,7 +46,11 @@ struct test_conv_bn_relu_pooling2 : verify_program<test_conv_bn_relu_pooling2<DT
auto rt = m.add_literal(migraphx::literal{DType, {0.5}});
auto eps = m.add_literal(migraphx::literal{DType, {1e-5f}});
if constexpr((DType) == migraphx::shape::fp8e4m3fnuz_type)
{
// use 5e-2f for the fp8
eps = m.add_literal(migraphx::literal{DType, {5e-2f}});
}
auto usq_scale =
m.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), scale);
auto usq_bias = m.add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), bias);
......
......@@ -27,16 +27,17 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_conv_group_add : verify_program<test_conv_group_add>
template <migraphx::shape::type_t DType>
struct test_conv_group_add : verify_program<test_conv_group_add<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {1, 68, 28, 28}};
migraphx::shape s{DType, {1, 68, 28, 28}};
auto x = mm->add_parameter("x", s);
auto w = mm->add_parameter("w", {migraphx::shape::float_type, {68, 17, 1, 1}});
auto b = mm->add_parameter("b", {migraphx::shape::float_type, {68}});
auto w = mm->add_parameter("w", {DType, {68, 17, 1, 1}});
auto b = mm->add_parameter("b", {DType, {68}});
auto conv = mm->add_instruction(migraphx::make_op("convolution", {{"group", 4}}), x, w);
auto bb = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", {1, 68, 28, 28}}}), b);
......@@ -44,3 +45,5 @@ struct test_conv_group_add : verify_program<test_conv_group_add>
return p;
}
};
template struct test_conv_group_add<migraphx::shape::float_type>;
// template struct test_conv_group_add<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -28,16 +28,17 @@
#include <migraphx/make_op.hpp>
#include <migraphx/op/common.hpp>
struct test_conv_pooling : verify_program<test_conv_pooling>
template <migraphx::shape::type_t DType>
struct test_conv_pooling : verify_program<test_conv_pooling<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 32, 32}});
mm->add_parameter("x", migraphx::shape{DType, {4, 3, 32, 32}});
auto weights =
mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
mm->add_parameter("w", migraphx::shape{DType, {4, 3, 3, 3}});
auto conv = mm->add_instruction(migraphx::make_op("convolution"), input, weights);
auto pooling = mm->add_instruction(
migraphx::make_op("pooling", {{"mode", migraphx::op::pooling_mode::max}}), conv);
......@@ -45,3 +46,6 @@ struct test_conv_pooling : verify_program<test_conv_pooling>
return p;
}
};
template struct test_conv_pooling<migraphx::shape::float_type>;
template struct test_conv_pooling<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,18 +27,19 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_conv_relu : verify_program<test_conv_relu>
template <migraphx::shape::type_t DType>
struct test_conv_relu : verify_program<test_conv_relu<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto weights =
mm->add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
auto input = mm->add_parameter("x", migraphx::shape{DType, {4, 3, 3, 3}});
auto weights = mm->add_parameter("w", migraphx::shape{DType, {4, 3, 3, 3}});
auto conv = mm->add_instruction(migraphx::make_op("convolution"), input, weights);
mm->add_instruction(migraphx::make_op("relu"), conv);
return p;
}
};
template struct test_conv_relu<migraphx::shape::float_type>;
template struct test_conv_relu<migraphx::shape::fp8e4m3fnuz_type>;
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