You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/07/19 06:51:23 UTC

[GitHub] [tvm] zxybazh opened a new pull request, #12127: [MetaSchedule] Enhance Conv2d Winograd Schedule Rules

zxybazh opened a new pull request, #12127:
URL: https://github.com/apache/tvm/pull/12127

   This PR introduces some new trials to expand the search space for Winograd Conv2d Workload by writing block level schedule rules. Tests will also be included.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] vinx13 commented on a diff in pull request #12127: [MetaSchedule] Enhance Conv2d NCHW Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
vinx13 commented on code in PR #12127:
URL: https://github.com/apache/tvm/pull/12127#discussion_r935907425


##########
src/meta_schedule/schedule_rule/winograd.cc:
##########
@@ -74,6 +80,32 @@ inline LoopRV ScheduleDataPack(Schedule sch, BlockRV block) {
   return t1[1];
 }
 
+inline LoopRV ScheduleDataPackNCHW(Schedule sch, BlockRV block) {
+  Array<LoopRV> loops = sch->GetLoops(block);
+  ICHECK_EQ(loops.size(), 6);
+
+  if (const int64_t* i = tir::GetLoopIntExtent(sch->GetSRef(loops[0]))) {
+    if (*i <= 16) {
+      sch->Unroll(loops[0]);
+    }
+  }
+  if (const int64_t* i = tir::GetLoopIntExtent(sch->GetSRef(loops[1]))) {
+    if (*i <= 16) {
+      sch->Unroll(loops[1]);
+    }
+  }
+  sch->Unroll(loops[4]);
+  sch->Unroll(loops[5]);
+
+  Array<ExprRV> factors = sch->SamplePerfectTile(loops[3], /*n=*/2, /*max_innermost_factor=*/64);
+  Array<LoopRV> split =
+      sch->Split(loops[3], /*factors=*/{factors[0], factors[1]}, /*preserve_unit_loops=*/true);

Review Comment:
   ```suggestion
         sch->Split(loops[3], /*factors=*/factors, /*preserve_unit_loops=*/true);
   ```



##########
src/meta_schedule/schedule_rule/winograd.cc:
##########
@@ -92,6 +124,50 @@ TVM_REGISTER_GLOBAL("meta_schedule.winograd_data_pack.llvm")
       return {sch};
     });
 
+TVM_REGISTER_GLOBAL("meta_schedule.winograd_output.nchw.cuda")
+    .set_body_typed([](Schedule sch, BlockRV output) -> Array<Schedule> {
+      // get loops
+      Array<LoopRV> loops = sch->GetLoops(output);
+      ICHECK_EQ(loops.size(), 4);
+
+      BlockRV OL{nullptr};
+      if (sch->GetConsumers(output).size() > 0) {
+        OL = GetOnlyConsumer(sch, output);
+        sch->SetScope(OL, /*buffer_index=*/0, /*storage_scope=*/"local");
+      }
+
+      // tile
+      BlockRV inverse = GetOnlyProducer(sch, output);
+      Optional<PrimExpr> tile_size =
+          tir::GetAnn<PrimExpr>(sch->GetSRef(output), "winograd_tile_size");
+      ICHECK(tile_size.defined()) << "Winograd tile size is not defined in block annotation!";
+      Array<LoopRV> split0 = sch->Split(loops[2], {NullOpt, tile_size.value()});
+      Array<LoopRV> split1 = sch->Split(loops[3], {NullOpt, tile_size.value()});
+      sch->Reorder({split0[0], split1[0], split0[1], split1[1]});
+
+      // compute_at
+      sch->ComputeAt(inverse, /*loop_rv=*/split1[0],
+                     /*preserve_unit_loops=*/true);
+      if (OL.defined()) {
+        while (sch->GetConsumers(OL).size() > 0) {
+          BlockRV next_OL = GetOnlyConsumer(sch, OL);

Review Comment:
   Will consumers be handled automatically by auto_inline rule? If so, this and `SetScope` are not necessary



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh commented on pull request #12127: [MetaSchedule] Enhance Conv2d NCHW Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
zxybazh commented on PR #12127:
URL: https://github.com/apache/tvm/pull/12127#issuecomment-1203291630

   Hi Wuwei, I have removed bgemm block schedule and use MultiLevelTiling instead. It reproduced same performance in conv2d test, I’m running e2e tests as well. With other issues also addressed, would you please take another look? Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh commented on pull request #12127: [MetaSchedule] Enhance Conv2d Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
zxybazh commented on PR #12127:
URL: https://github.com/apache/tvm/pull/12127#issuecomment-1201990665

   @tvm-bot rerun


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh commented on a diff in pull request #12127: [MetaSchedule] Enhance Conv2d NCHW Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
zxybazh commented on code in PR #12127:
URL: https://github.com/apache/tvm/pull/12127#discussion_r936034797


##########
src/meta_schedule/schedule_rule/winograd.cc:
##########
@@ -74,6 +80,32 @@ inline LoopRV ScheduleDataPack(Schedule sch, BlockRV block) {
   return t1[1];
 }
 
+inline LoopRV ScheduleDataPackNCHW(Schedule sch, BlockRV block) {
+  Array<LoopRV> loops = sch->GetLoops(block);
+  ICHECK_EQ(loops.size(), 6);
+
+  if (const int64_t* i = tir::GetLoopIntExtent(sch->GetSRef(loops[0]))) {
+    if (*i <= 16) {
+      sch->Unroll(loops[0]);
+    }
+  }
+  if (const int64_t* i = tir::GetLoopIntExtent(sch->GetSRef(loops[1]))) {
+    if (*i <= 16) {
+      sch->Unroll(loops[1]);
+    }
+  }
+  sch->Unroll(loops[4]);
+  sch->Unroll(loops[5]);
+
+  Array<ExprRV> factors = sch->SamplePerfectTile(loops[3], /*n=*/2, /*max_innermost_factor=*/64);
+  Array<LoopRV> split =
+      sch->Split(loops[3], /*factors=*/{factors[0], factors[1]}, /*preserve_unit_loops=*/true);

Review Comment:
   Hi, it seems `factors` are type of `Array<PrimExpr>` while the argument here requires `factors` to be `Array<Optional<PrimExpr>>` so IIUC we may keep it this way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh commented on a diff in pull request #12127: [MetaSchedule] Enhance Conv2d NCHW Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
zxybazh commented on code in PR #12127:
URL: https://github.com/apache/tvm/pull/12127#discussion_r937024824


##########
tests/python/unittest/test_meta_schedule_space_cuda.py:
##########
@@ -1239,6 +1239,90 @@ def cbr_0(data: T.Buffer[(1, 224, 224, 3), "float32"], kernel: T.Buffer[(7, 7, 3
     )
 
 
+def test_cuda_tbg():

Review Comment:
   This test case was moved to the right position before the PR, it got moved after the conv2d winograd testcase because of rebase. You can see there’s no change in the `files changed` tab page.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] vinx13 commented on a diff in pull request #12127: [MetaSchedule] Enhance Conv2d NCHW Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
vinx13 commented on code in PR #12127:
URL: https://github.com/apache/tvm/pull/12127#discussion_r936956096


##########
tests/python/unittest/test_meta_schedule_space_cuda.py:
##########
@@ -1239,6 +1239,90 @@ def cbr_0(data: T.Buffer[(1, 224, 224, 3), "float32"], kernel: T.Buffer[(7, 7, 3
     )
 
 
+def test_cuda_tbg():

Review Comment:
   this test case is not related



##########
tests/python/unittest/test_meta_schedule_space_cuda.py:
##########
@@ -1378,6 +1456,9 @@ def winograd_nchw_conv2d(data: T.Buffer[(1, 64, 224, 224), "float32"], kernel: T
         space_generator=ms.space_generator.PostOrderApply(),
         sch_rules="default",
     ).generate_design_space()
+    sch = actual[0]
+    print(sch.mod.script())
+    print(sch.trace)

Review Comment:
   remove it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] zxybazh merged pull request #12127: [MetaSchedule] Enhance Conv2d NCHW Winograd Schedule Rules

Posted by GitBox <gi...@apache.org>.
zxybazh merged PR #12127:
URL: https://github.com/apache/tvm/pull/12127


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org