From d770faf2df76e3bb373a08b3e3fc65cf6c9f0790 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Thu, 14 Sep 2023 18:38:29 -0400 Subject: [PATCH 1/6] Remove contiguous from reshape parsing --- src/onnx/parse_reshape.cpp | 3 +-- src/tf/parse_reshape.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/onnx/parse_reshape.cpp b/src/onnx/parse_reshape.cpp index ee5adeeb52d..a22f1389c33 100644 --- a/src/onnx/parse_reshape.cpp +++ b/src/onnx/parse_reshape.cpp @@ -53,8 +53,7 @@ struct parse_reshape : op_parser s.visit([&](auto v) { copy(v, std::back_inserter(dims)); }); } - auto cont = info.add_instruction(make_op("contiguous"), args[0]); - return info.add_instruction(make_op("reshape", {{"dims", dims}}), cont); + return info.add_instruction(make_op("reshape", {{"dims", dims}}), args[0]); } }; diff --git a/src/tf/parse_reshape.cpp b/src/tf/parse_reshape.cpp index 6ab28e7c564..3cbe2d878c8 100644 --- a/src/tf/parse_reshape.cpp +++ b/src/tf/parse_reshape.cpp @@ -45,8 +45,7 @@ struct parse_reshape : op_parser auto s = args[1]->eval(); std::vector dims; s.visit([&](auto v) { copy(v, std::back_inserter(dims)); }); - return info.add_instruction(make_op("reshape", {{"dims", dims}}), - info.make_contiguous(args[0])); + return info.add_instruction(make_op("reshape", {{"dims", dims}}), args[0]); } }; From f23b2493fdd6f5ba64e7e400b982473d2fff2ae7 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Wed, 27 Sep 2023 15:47:08 -0400 Subject: [PATCH 2/6] Remove contiguous from depthtospace --- src/onnx/parse_depthtospace.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/onnx/parse_depthtospace.cpp b/src/onnx/parse_depthtospace.cpp index 610902ef4af..609eee04605 100644 --- a/src/onnx/parse_depthtospace.cpp +++ b/src/onnx/parse_depthtospace.cpp @@ -87,8 +87,7 @@ struct parse_depthtospace : op_parser auto temp1 = info.add_instruction(make_op("reshape", {{"dims", lens1}}), args[0]); auto temp2 = info.add_instruction(make_op("transpose", {{"permutation", perm}}), temp1); - return info.add_instruction(make_op("reshape", {{"dims", lens2}}), - info.make_contiguous(temp2)); + return info.add_instruction(make_op("reshape", {{"dims", lens2}}), temp2); } }; From 52c3e3e3a0b4a5999583da7443a32fd2990a8d53 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Wed, 27 Sep 2023 15:47:16 -0400 Subject: [PATCH 3/6] remove contiguous from spacetodepth --- src/onnx/parse_spacetodepth.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/onnx/parse_spacetodepth.cpp b/src/onnx/parse_spacetodepth.cpp index 51ca1c0053f..69a8bf58a15 100644 --- a/src/onnx/parse_spacetodepth.cpp +++ b/src/onnx/parse_spacetodepth.cpp @@ -73,8 +73,7 @@ struct parse_spacetodepth : op_parser std::vector perm = {0, 3, 5, 1, 2, 4}; auto temp1 = info.add_instruction(make_op("reshape", {{"dims", trans_lens}}), args[0]); auto temp2 = info.add_instruction(make_op("transpose", {{"permutation", perm}}), temp1); - return info.add_instruction(make_op("reshape", {{"dims", res_lens}}), - info.make_contiguous(temp2)); + return info.add_instruction(make_op("reshape", {{"dims", res_lens}}), temp2); } }; From 7b458ac10cc96ce7d09e1bc58183bcbe5e0fc9a6 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Thu, 28 Sep 2023 11:03:37 -0400 Subject: [PATCH 4/6] Update rehape_test to remove contiguous ops --- test/onnx/onnx_test.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/onnx/onnx_test.cpp b/test/onnx/onnx_test.cpp index b0e6255a976..8459fde4212 100644 --- a/test/onnx/onnx_test.cpp +++ b/test/onnx/onnx_test.cpp @@ -5366,12 +5366,9 @@ TEST_CASE(reshape_test) migraphx::literal{migraphx::shape{migraphx::shape::int64_type, {2}}, reshape_dims}); auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {4, 2, 3}}); op.dims = reshape_dims; - auto c0 = mm->add_instruction(migraphx::make_op("contiguous"), l0); - mm->add_instruction(op, c0); - auto c1 = mm->add_instruction(migraphx::make_op("contiguous"), l0); - mm->add_instruction(op, c1); + mm->add_instruction(op, l0); + mm->add_instruction(op, l0); auto prog = optimize_onnx("reshape_test.onnx"); - EXPECT(p == prog); } From db1bced38de50bef5954d1ee6120da27d40472a1 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Thu, 28 Sep 2023 11:15:55 -0400 Subject: [PATCH 5/6] Remove contiguous from spacetodepth depthtospace tests --- test/onnx/onnx_test.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/test/onnx/onnx_test.cpp b/test/onnx/onnx_test.cpp index 8459fde4212..54e48ffab2c 100644 --- a/test/onnx/onnx_test.cpp +++ b/test/onnx/onnx_test.cpp @@ -1700,8 +1700,7 @@ TEST_CASE(depthtospace_test) mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 2, 2, 5, 5}}}), l0); auto tmp2 = mm->add_instruction( migraphx::make_op("transpose", {{"permutation", {0, 3, 4, 1, 5, 2}}}), tmp1); - auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2); - mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 10, 10}}}), tmp3); + mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 10, 10}}}), tmp2); auto prog = optimize_onnx("depthtospace_test.onnx"); EXPECT(p == prog); } @@ -1715,8 +1714,7 @@ TEST_CASE(depthtospace_crd_test) mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 2, 2, 5, 5}}}), l0); auto tmp2 = mm->add_instruction( migraphx::make_op("transpose", {{"permutation", {0, 1, 4, 2, 5, 3}}}), tmp1); - auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2); - mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 10, 10}}}), tmp3); + mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 10, 10}}}), tmp2); auto prog = optimize_onnx("depthtospace_crd_test.onnx"); EXPECT(p == prog); } @@ -1730,8 +1728,7 @@ TEST_CASE(depthtospace_simple_test) mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 2, 2, 2, 3}}}), l0); auto tmp2 = mm->add_instruction( migraphx::make_op("transpose", {{"permutation", {0, 3, 4, 1, 5, 2}}}), tmp1); - auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2); - mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 4, 6}}}), tmp3); + mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 4, 6}}}), tmp2); auto prog = optimize_onnx("depthtospace_simple_test.onnx"); EXPECT(p == prog); } @@ -1745,8 +1742,7 @@ TEST_CASE(spacetodepth_test) mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 5, 2, 5, 2}}}), l0); auto tmp2 = mm->add_instruction( migraphx::make_op("transpose", {{"permutation", {0, 3, 5, 1, 2, 4}}}), tmp1); - auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2); - mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 8, 5, 5}}}), tmp3); + mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 8, 5, 5}}}), tmp2); auto prog = optimize_onnx("spacetodepth_test.onnx"); EXPECT(p == prog); } @@ -1760,8 +1756,7 @@ TEST_CASE(spacetodepth_simple_test) mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 2, 2, 3, 2}}}), l0); auto tmp2 = mm->add_instruction( migraphx::make_op("transpose", {{"permutation", {0, 3, 5, 1, 2, 4}}}), tmp1); - auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2); - mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 8, 2, 3}}}), tmp3); + mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 8, 2, 3}}}), tmp2); auto prog = optimize_onnx("spacetodepth_simple_test.onnx"); EXPECT(p == prog); } From cdb8b7be43dd2436f1e155588b1967e6dac42346 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Thu, 28 Sep 2023 11:16:14 -0400 Subject: [PATCH 6/6] Remove contiguous from nonstandard shape test --- test/onnx/onnx_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/onnx/onnx_test.cpp b/test/onnx/onnx_test.cpp index 54e48ffab2c..9b74bf9faae 100644 --- a/test/onnx/onnx_test.cpp +++ b/test/onnx/onnx_test.cpp @@ -5376,8 +5376,7 @@ TEST_CASE(reshape_non_standard_test) auto x = mm->add_parameter("x", s); auto tran_x = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1}}}), x); - auto cont_x = mm->add_instruction(migraphx::make_op("contiguous"), tran_x); - mm->add_instruction(migraphx::make_op("reshape", {{"dims", {4, 3, 2}}}), cont_x); + mm->add_instruction(migraphx::make_op("reshape", {{"dims", {4, 3, 2}}}), tran_x); auto prog = optimize_onnx("reshape_non_standard_test.onnx"); EXPECT(p == prog);