Unverified Commit 478ddd97 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Fix bug in simplify_algebra when using odd number input with even stride (#486)



* Add test with odd stride

* Use same logic as convolution for stride calculation

* Formatting
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
parent 878a7d09
......@@ -287,7 +287,10 @@ struct find_add_convs
static shape compute_stride_shape(const shape& input, std::size_t n)
{
return {input.type(),
{input.lens()[0], input.lens()[1], input.lens()[2] / n, input.lens()[3] / n},
{input.lens()[0],
input.lens()[1],
std::size_t(std::max<std::ptrdiff_t>(1, (input.lens()[2] - 1) / n + 1)),
std::size_t(std::max<std::ptrdiff_t>(1, (input.lens()[3] - 1) / n + 1))},
{input.strides()[0],
input.strides()[1],
input.strides()[2] * n,
......
......@@ -339,6 +339,26 @@ TEST_CASE(simplify_add_conv_1x1_diff_strides2)
p.begin(), p.end(), [](auto&& ins) { return ins.name() == "convolution"; }) == 1);
}
TEST_CASE(simplify_add_conv_1x1_diff_strides_odd)
{
migraphx::program p;
auto x = p.add_parameter("x", {migraphx::shape::float_type, {1, 54, 83, 83}});
auto w =
p.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {54, 54, 1, 1}}));
auto y = p.add_parameter("y", {migraphx::shape::float_type, {1, 54, 165, 165}});
auto v =
p.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {54, 54, 1, 1}}));
auto conv1 = p.add_instruction(migraphx::op::convolution{}, x, w);
auto conv2 = p.add_instruction(migraphx::op::convolution{{0, 0}, {2, 2}}, y, v);
auto sum = p.add_instruction(migraphx::op::add{}, conv1, conv2);
p.add_instruction(pass_op{}, sum);
auto s = p.get_output_shapes().back();
run_pass(p);
EXPECT(s == p.get_output_shapes().back());
EXPECT(std::count_if(
p.begin(), p.end(), [](auto&& ins) { return ins.name() == "convolution"; }) == 1);
}
TEST_CASE(simplify_add_conv_no_fusion_asymetrical_strides1)
{
migraphx::program 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