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 2020/04/09 06:16:07 UTC

[GitHub] [incubator-tvm] comaniac opened a new pull request #5288: [BYOC] Refine DNNL Codegen

comaniac opened a new pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288
 
 
   With multiple output and merge compiler region support, we can now refine the DNNL codegen to support ops with multiple outputs such as `batch_norm`. This PR:
   
   - Support operators with multiple outputs.
   - Fix the issue that the second fuse run in VM will go into external functions and decompose `batch_norm`.
   - Turn on DNNL `batch_norm`.
   - Fix `TupleGeItem` in DNNL codegen.
   - Skip MobileNet test because of the constant node issue for now.
   
   cc @zhiics, @masahi.
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on issue #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#issuecomment-611916545
 
 
   Thanks @comaniac @zhiics 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406501323
 
 

 ##########
 File path: tests/python/relay/test_pass_partition_graph.py
 ##########
 @@ -862,7 +863,7 @@ def expected():
     test_extern_ccompiler_default_ops()
     test_extern_ccompiler()
     test_extern_dnnl()
-    test_extern_dnnl_mobilenet()
+    #test_extern_dnnl_mobilenet()
 
 Review comment:
   What change in this PR makes running mobilenet test difficult?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] comaniac commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406504773
 
 

 ##########
 File path: src/relay/backend/vm/compiler.cc
 ##########
 @@ -924,19 +924,20 @@ IRModule VMCompiler::OptimizeModule(const IRModule& mod, const TargetsMap& targe
   pass_seqs.push_back(transform::LambdaLift());
   pass_seqs.push_back(transform::InlinePrimitives());
 
+  // Manifest the allocations.
+  pass_seqs.push_back(transform::ManifestAlloc(this->target_host_));
+  // Compute away possibly introduced constant computation.
+  pass_seqs.push_back(transform::FoldConstant());
+  // Fuse the shape functions.
+  pass_seqs.push_back(transform::FuseOps());
+
 
 Review comment:
   zhiics previously made a PR to outline all partition function to avoid being touched by some passes such as `fuse_ops`, but you can see that before this PR the second run of `fuse_ops` pass is invoked after the inline pass, resulting in the decomposition of `batch_norm`. After this change, we inline the partition functions back after finishing all other passes so that `batch_norm` could be preserved safely to external codegen.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406501685
 
 

 ##########
 File path: src/relay/backend/vm/compiler.cc
 ##########
 @@ -924,19 +924,20 @@ IRModule VMCompiler::OptimizeModule(const IRModule& mod, const TargetsMap& targe
   pass_seqs.push_back(transform::LambdaLift());
   pass_seqs.push_back(transform::InlinePrimitives());
 
+  // Manifest the allocations.
+  pass_seqs.push_back(transform::ManifestAlloc(this->target_host_));
+  // Compute away possibly introduced constant computation.
+  pass_seqs.push_back(transform::FoldConstant());
+  // Fuse the shape functions.
+  pass_seqs.push_back(transform::FuseOps());
+
 
 Review comment:
   Why is this change for?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406501323
 
 

 ##########
 File path: tests/python/relay/test_pass_partition_graph.py
 ##########
 @@ -862,7 +863,7 @@ def expected():
     test_extern_ccompiler_default_ops()
     test_extern_ccompiler()
     test_extern_dnnl()
-    test_extern_dnnl_mobilenet()
+    #test_extern_dnnl_mobilenet()
 
 Review comment:
   What change in this PR makes running mobilenet test difficult? I have no problem running this test even with my PR.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406501685
 
 

 ##########
 File path: src/relay/backend/vm/compiler.cc
 ##########
 @@ -924,19 +924,20 @@ IRModule VMCompiler::OptimizeModule(const IRModule& mod, const TargetsMap& targe
   pass_seqs.push_back(transform::LambdaLift());
   pass_seqs.push_back(transform::InlinePrimitives());
 
+  // Manifest the allocations.
+  pass_seqs.push_back(transform::ManifestAlloc(this->target_host_));
+  // Compute away possibly introduced constant computation.
+  pass_seqs.push_back(transform::FoldConstant());
+  // Fuse the shape functions.
+  pass_seqs.push_back(transform::FuseOps());
+
 
 Review comment:
   What is this change for?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] comaniac commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406503687
 
 

 ##########
 File path: tests/python/relay/test_pass_partition_graph.py
 ##########
 @@ -862,7 +863,7 @@ def expected():
     test_extern_ccompiler_default_ops()
     test_extern_ccompiler()
     test_extern_dnnl()
-    test_extern_dnnl_mobilenet()
+    #test_extern_dnnl_mobilenet()
 
 Review comment:
   Ah I missed one line in this separated PR. We added `mod["main"] = relay.build_module.bind_params_by_name(mod["main"], params)` to this case and it results in the large contant tensor issue that we didn't handle it in this PR.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi merged pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi merged pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406523632
 
 

 ##########
 File path: src/relay/backend/vm/compiler.cc
 ##########
 @@ -924,19 +924,20 @@ IRModule VMCompiler::OptimizeModule(const IRModule& mod, const TargetsMap& targe
   pass_seqs.push_back(transform::LambdaLift());
   pass_seqs.push_back(transform::InlinePrimitives());
 
+  // Manifest the allocations.
+  pass_seqs.push_back(transform::ManifestAlloc(this->target_host_));
+  // Compute away possibly introduced constant computation.
+  pass_seqs.push_back(transform::FoldConstant());
+  // Fuse the shape functions.
+  pass_seqs.push_back(transform::FuseOps());
+
 
 Review comment:
   ok makes sense, but batch_norm is decomposed by SimplifyInference, fuse_ops does something else.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406502991
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -53,12 +53,19 @@ class CodegenDNNL : public ExprVisitor, public CodegenCBase {
   }
 
   void VisitExpr_(const TupleGetItemNode* op) final {
-    // Do nothing
+    VisitExpr(op->tuple);
+    CHECK(out_.size() > static_cast<size_t>(op->index));
+
+    // Only keep the item we want for the child node.
+    // FIXME(@comaniac): The other items should still be requried for the primary outputs.
 
 Review comment:
   This looks ok to me, why "FIXME"? TupleGetItem only cares about one output.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406505427
 
 

 ##########
 File path: src/relay/backend/vm/compiler.cc
 ##########
 @@ -924,19 +924,20 @@ IRModule VMCompiler::OptimizeModule(const IRModule& mod, const TargetsMap& targe
   pass_seqs.push_back(transform::LambdaLift());
   pass_seqs.push_back(transform::InlinePrimitives());
 
+  // Manifest the allocations.
+  pass_seqs.push_back(transform::ManifestAlloc(this->target_host_));
+  // Compute away possibly introduced constant computation.
+  pass_seqs.push_back(transform::FoldConstant());
+  // Fuse the shape functions.
+  pass_seqs.push_back(transform::FuseOps());
+
 
 Review comment:
   Yeah, inlining should be after fusion. I missed the second fusion...

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406524552
 
 

 ##########
 File path: src/relay/backend/vm/compiler.cc
 ##########
 @@ -924,19 +924,20 @@ IRModule VMCompiler::OptimizeModule(const IRModule& mod, const TargetsMap& targe
   pass_seqs.push_back(transform::LambdaLift());
   pass_seqs.push_back(transform::InlinePrimitives());
 
+  // Manifest the allocations.
+  pass_seqs.push_back(transform::ManifestAlloc(this->target_host_));
+  // Compute away possibly introduced constant computation.
+  pass_seqs.push_back(transform::FoldConstant());
+  // Fuse the shape functions.
+  pass_seqs.push_back(transform::FuseOps());
+
 
 Review comment:
   yeah, if batch_norm is encapsulated in an external function, it will be lifted out and therefore invisible by simplifyinference. Later on, if we inline it and run fusion, fusion pass will see this op and complain that on OpPattern is registered for this op...

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] comaniac commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5288: [BYOC] Refine DNNL Codegen
URL: https://github.com/apache/incubator-tvm/pull/5288#discussion_r406505777
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -53,12 +53,19 @@ class CodegenDNNL : public ExprVisitor, public CodegenCBase {
   }
 
   void VisitExpr_(const TupleGetItemNode* op) final {
-    // Do nothing
+    VisitExpr(op->tuple);
+    CHECK(out_.size() > static_cast<size_t>(op->index));
+
+    // Only keep the item we want for the child node.
+    // FIXME(@comaniac): The other items should still be requried for the primary outputs.
 
 Review comment:
   In terms of the semantic, if we generate a partition function like `conv2d->BN->relu`, we should have a tuple output with 3 elements `(relu_out, BN_out_1, BN_out_2)` even the rest 2 are useless. In general we should achieve this semantic, but since no one cares the rest 2 outputs of `batch_norm` it's fine for now.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services