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/11 21:00:00 UTC

[GitHub] [incubator-tvm] zhiics opened a new pull request #5310: [BYOC] Enhance partitioning and external codegen

zhiics opened a new pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310
 
 
   This PR
   
   - Removes the duplicated outputs to the followed subgraphs. Previously, there would be two outputs from A to (B, C) if both B and C use the output from A where actually one is enough.
   
   - Enables MobileNet test on DNNL by allocating the large constant array on the static section instead of the heap and then assigning then one by one. Note the compilation time would be slightly longer (< 2mins on a P2 instance).
   
   - Fixes the way we used to save the intermediate output by directly caching and returning it in the post order way.
   
   @comaniac @masahi @soiferj @manupa-arm @trevor-m 

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407126384
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -40,35 +40,44 @@ using namespace backend;
  * purpose. Only several binary options are covered. Users
  * may need to extend them to cover more operators.
  */
-class CodegenC : public ExprVisitor, public CodegenCBase {
+class CodegenC : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
 
 Review comment:
   I think its' better to keep vector. We flatten tuple and may need to have multiple return values. No need to refactor in that case.

----------------------------------------------------------------
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 edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612547407
 
 
   @masahi Yeah, I only have some hypothetic explanations which motivated me to make this change. I think the reason why heap was slow was because we generated a huge amount of stmts for array initialization. It makes the code size so huge even though many of them are simple. But each optimization and codegen on it would be still very slow (particularly they are pointers). However, after we move the array to the data segment, we can remove these stmts but only have one pointer. Therefore, the compilation should be much faster. In the latter case, linking and data loading would take more time, but it is still insignificant compared to compilation. Does this make sense?
   
   Update: yeah, I didn't see your updated paragraph, but it is right.
   

----------------------------------------------------------------
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] soiferj commented on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
soiferj commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613177798
 
 
   You’re right, sorry about that

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125692
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -40,35 +40,44 @@ using namespace backend;
  * purpose. Only several binary options are covered. Users
  * may need to extend them to cover more operators.
  */
-class CodegenC : public ExprVisitor, public CodegenCBase {
+class CodegenC : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                 public CodegenCBase {
  public:
   explicit CodegenC(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
+
+    std::vector<Output> output;
+    if (expr.as<ConstantNode>()) {
+      output = VisitExpr_(expr.as<ConstantNode>());
+    } else if (expr.as<VarNode>()) {
+     output = VisitExpr_(expr.as<VarNode>());
+    } else if (expr.as<CallNode>()) {
+     output = VisitExpr_(expr.as<CallNode>());
+    } else {
+     LOG(FATAL) << "DNNL codegen doesn't support: " << expr->GetTypeKey();
 
 Review comment:
   s/DNNL/C (or something more proper)/

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407127503
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   Well it is not necessary, but it would be nice if we could add memo there. We don't have to add this overide in `CodegenDNN` and we can clean up many duped logic in other derived classes.
   
   But since that would be a big change, I agree that we should proceed with this impl 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

[GitHub] [incubator-tvm] lhutton1 commented on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
lhutton1 commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613316418
 
 
   Apologies, it was bank holiday in the UK :) Although this has now been merged, I've had a look into the constant tensor issue previously and this method of writing out the constant tensor causes very long compilation time for models like VGG16. I couldn't find a nice way to solve this when I was looking into it, but just wanted to raise it here so people are aware. Is this a pattern that we want people to follow in the future?

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407126898
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   yeah, we could do that, and we can do that in a separate PR if you feel 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.
 
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612550158
 
 
   Let's keep it open for a couple of days so that ARM people can have a look. @mbaret @lhutton1 @manupa-arm 

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613097942
 
 
   Let's bring this in since ARM folks haven't really changed the DNNL codegen code and the fix in partitioning is simple.

----------------------------------------------------------------
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] soiferj edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
soiferj edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613177798
 
 
   You’re right, sorry about that. So if our target was CUDA, we would need to first memcpy back to the host?
   
   It turns out the constant propagation in the PartitionGraph pass changed this behavior quite a bit. 

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125694
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   Here are dup-ed logic in another derived classes
   https://github.com/apache/incubator-tvm/blob/00014e20c3cc077727d467a67d3498260627e4e0/src/relay/backend/compile_engine.cc#L182-L191
   
   https://github.com/apache/incubator-tvm/blob/00014e20c3cc077727d467a67d3498260627e4e0/src/relay/backend/graph_runtime_codegen.cc#L320

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125692
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -40,35 +40,44 @@ using namespace backend;
  * purpose. Only several binary options are covered. Users
  * may need to extend them to cover more operators.
  */
-class CodegenC : public ExprVisitor, public CodegenCBase {
+class CodegenC : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                 public CodegenCBase {
  public:
   explicit CodegenC(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
+
+    std::vector<Output> output;
+    if (expr.as<ConstantNode>()) {
+      output = VisitExpr_(expr.as<ConstantNode>());
+    } else if (expr.as<VarNode>()) {
+     output = VisitExpr_(expr.as<VarNode>());
+    } else if (expr.as<CallNode>()) {
+     output = VisitExpr_(expr.as<CallNode>());
+    } else {
+     LOG(FATAL) << "DNNL codegen doesn't support: " << expr->GetTypeKey();
 
 Review comment:
   s/DNNL/C (or something more proper)/g

----------------------------------------------------------------
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] soiferj edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
soiferj edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613177798
 
 
   You’re right, sorry about that. So if our target was CUDA, we would need to first memcpy back to the host?
   
   It turns out the constant propagation in the PartitionGraph pass changed this behavior quite a bit. 
   
   Update: I think I see what’s happening - the value of the constant will be on the host. Nvm!

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407130767
 
 

 ##########
 File path: src/relay/transforms/partition_graph.cc
 ##########
 @@ -148,25 +148,42 @@ class Partitioner : public ExprMutator {
       CHECK_EQ(call->args.size(), 1U);
 
       // Traverse the rest graph.
-      auto input_expr = VisitExpr(call->args[0]);
+      Expr parent = call->args[0];
+      auto input_expr = VisitExpr(parent);
+
+      // Backtrace the parent to find the LCA node that is not a begin/ end op
 
 Review comment:
   Is it really LCA? To me it seems just an ancestor node.

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613182638
 
 
   It wasn't really constant before. It was variables. Therefore, you wouldn't have constants in the external codegen. With constant propagation, we will have them and leave it for the external codegen to handle. I think there is a thread in the discussion forum. 

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612537784
 
 
   Great! Can you also enable mobilenet exec in the dnnl fuse test, by uncommenting this?
   https://github.com/apache/incubator-tvm/blob/master/tests/python/relay/test_pass_partition_graph.py#L971-L973

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407127503
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   Well it is not necessary, but it would be nice if we could add memo there. We don't have to add this overide in `CodegenDNN` and we can clean up many duped logic in other derived classes. Since `ExprMutator` does have memo built in, I don't see why `ExprFunctor` shouldn't have memo as well.
   
   But since that would be a big change, I agree that we should proceed with this impl 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

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125980
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   ExprFunctor actually only has the pure virtual functions. It's developer's responsibility to implement them. Although we could have a map like `map<Expr, R>`, it probably makes sense to let users define your own memoization.

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407131055
 
 

 ##########
 File path: src/relay/transforms/partition_graph.cc
 ##########
 @@ -148,25 +148,42 @@ class Partitioner : public ExprMutator {
       CHECK_EQ(call->args.size(), 1U);
 
       // Traverse the rest graph.
-      auto input_expr = VisitExpr(call->args[0]);
+      Expr parent = call->args[0];
+      auto input_expr = VisitExpr(parent);
+
+      // Backtrace the parent to find the LCA node that is not a begin/ end op
 
 Review comment:
   yeah, it should be LCA, like A-->end1->begin->B
                                                    -->end2->begin->C
   
   If B and C are in the same region, A should have only one out this region instead of two. A is the LCA of B and C.

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613098159
 
 
   Thanks @masahi @comaniac 

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612547407
 
 
   @masahi Yeah, I only have some hypothetic explanations which motivated me to make this change. I think the reason why heap was slow was because we generated a huge amount of stmts for array initialization. It makes the code size so huge even though many of them are simple. But each optimization on it would be still very slow (particularly they are pointers). However, after we move the array to the data segment, we can remove these stmts but only have one pointer. Therefore, the compilation should be much faster. In the latter case, linking and data loading would take more time, but it is still insignificant compared to compilation. Does this make sense?
   

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125694
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   Here is dup-ed logic in another derived class
   https://github.com/apache/incubator-tvm/blob/00014e20c3cc077727d467a67d3498260627e4e0/src/relay/backend/compile_engine.cc#L182-L191

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125271
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -40,35 +40,44 @@ using namespace backend;
  * purpose. Only several binary options are covered. Users
  * may need to extend them to cover more operators.
  */
-class CodegenC : public ExprVisitor, public CodegenCBase {
+class CodegenC : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                 public CodegenCBase {
  public:
   explicit CodegenC(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
+
+    std::vector<Output> output;
+    if (expr.as<ConstantNode>()) {
+      output = VisitExpr_(expr.as<ConstantNode>());
+    } else if (expr.as<VarNode>()) {
+     output = VisitExpr_(expr.as<VarNode>());
 
 Review comment:
   indent (and rest bodies in else if).

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125302
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   I wonder why `ExprFunctor` doesn't have memoization built in? It would be nice if derived classes don't have to take care of this.

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613167430
 
 
   The reason is because we need to serialize it. We cannot save the pointer but we need the data.

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125980
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   ExprFunctor actually only has the pure virtual functions. It's developer's responsibility to implement them. Although we could have a map like `map<Expr, R>`, it probably makes sense to let users define their own memoization.

----------------------------------------------------------------
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 edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612550158
 
 
   Let's keep it open for a couple of days so that ARM people can have a look next week. @mbaret @lhutton1 @manupa-arm 

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125302
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   I wonder why `ExprFunctor` has memoization built in? It would be nice if derived classes don't have to take care of this.

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407126346
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   hmm but it does have one dispatching function 
   https://github.com/apache/incubator-tvm/blob/master/include/tvm/relay/expr_functor.h#L93
   
   Why can't we have memoization there? If a derived class wants a custom memoization it can overide this method.

----------------------------------------------------------------
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 merged pull request #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics merged pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310
 
 
   

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612944463
 
 
   @mbaret @lhutton1 @manupa-arm Could any of you take a look? I'd like to merge enhancement soon.

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407124067
 
 

 ##########
 File path: tests/python/relay/test_pass_partition_graph.py
 ##########
 @@ -973,6 +951,93 @@ def test_exec(mod, params, ref_mod, ref_params, out_shape):
     # test_exec(mod, params, ref_mod, ref_params, (1, 1000))
 
 
+def test_multiple_use_of_an_output():
 
 Review comment:
   need to add this function to the main. It is not being run

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407127503
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -128,42 +128,50 @@ std::vector<std::string> Add(const CallNode* call) {
 
 // TODO(@zhiics, @comaniac): This is a basic implementation. We should implement
 // all utilities and make a base class for users to implement.
-class CodegenDNNL : public ExprVisitor, public CodegenCBase {
+class CodegenDNNL : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
+                    public CodegenCBase {
  public:
   explicit CodegenDNNL(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
 
 Review comment:
   Well it is not necessary, but it would be nice if we could add memo there. We don't have to add this overide in `CodegenDNN` and we can remove many duped logic in other derived classes.
   
   But since that would be a big change, I agree that we should proceed with this impl 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

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407131055
 
 

 ##########
 File path: src/relay/transforms/partition_graph.cc
 ##########
 @@ -148,25 +148,42 @@ class Partitioner : public ExprMutator {
       CHECK_EQ(call->args.size(), 1U);
 
       // Traverse the rest graph.
-      auto input_expr = VisitExpr(call->args[0]);
+      Expr parent = call->args[0];
+      auto input_expr = VisitExpr(parent);
+
+      // Backtrace the parent to find the LCA node that is not a begin/ end op
 
 Review comment:
   yeah, we can juts say ancestor, not necessarily LCA

----------------------------------------------------------------
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 edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612547407
 
 
   @masahi Yeah, I only have some hypothetic explanations which motivated me to make this change. I think the reason why heap was slow was because we generated a huge amount of stmts for array initialization. It makes the code size so huge even though many of them are simple. But each optimization on it would be still very slow (particularly they are pointers). However, after we move the array to the data segment, we can remove these stmts but only have one pointer. Therefore, the compilation should be much faster. In the latter case, linking and data loading would take more time, but it is still insignificant compared to compilation. Does this make sense?
   
   Update: yeah, I didn't see your updated paragraph, but it is right.
   

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407124620
 
 

 ##########
 File path: tests/python/relay/test_pass_partition_graph.py
 ##########
 @@ -973,6 +951,93 @@ def test_exec(mod, params, ref_mod, ref_params, out_shape):
     # test_exec(mod, params, ref_mod, ref_params, (1, 1000))
 
 
+def test_multiple_use_of_an_output():
 
 Review comment:
   It would be still executed with pytest. But I added to main as well.

----------------------------------------------------------------
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 edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612545021
 
 
   @zhiics Do you know why compiling manually inlined constants is massively faster and memory efficient for static array than heap one? For my education :)
   
   I guess it is because for inlined array on heap the compiler needs to generate instruction for every value?

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613521173
 
 
   This is what I think of we can do for CSourceModule style external codegen. I have some initial thoughts/work of having a different runtime so that we only need to serialize a relay program and interpret it (i.e. the one used as the minimal example). I don't have much cycle recently. I will send an RFC once I have bandwidth on it later. But anyway, let's not continue talking about it here as it is a different topic.

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407264492
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -40,35 +40,40 @@ using namespace backend;
  * purpose. Only several binary options are covered. Users
  * may need to extend them to cover more operators.
  */
-class CodegenC : public ExprVisitor, public CodegenCBase {
+class CodegenC : public ExprFunctor<std::vector<Output>(const Expr&)>,
+                 public CodegenCBase {
  public:
   explicit CodegenC(const std::string& id) { this->ext_func_id_ = id; }
 
-  void VisitExpr_(const VarNode* node) final {
+  std::vector<Output> VisitExpr(const Expr& expr) final {
+    if (visited_.count(expr)) return visited_.at(expr);
+    std::vector<Output> output =
+        ExprFunctor<std::vector<Output>(const Expr&)>::VisitExpr(expr);
 
 Review comment:
   You can drop the type qualification in the base class call and simplify this to
   ```
   auto output = ExprFunctor::VisitExpr(expr);
   ```

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612545021
 
 
   @zhiics Do you know why compiling manually inlined constants is massively faster and memory efficient for static array than heap one? For my education :)

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407125613
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -40,35 +40,44 @@ using namespace backend;
  * purpose. Only several binary options are covered. Users
  * may need to extend them to cover more operators.
  */
-class CodegenC : public ExprVisitor, public CodegenCBase {
+class CodegenC : public relay::ExprFunctor<std::vector<Output>(const Expr&)>,
 
 Review comment:
   I'm debating if we really need to return a vector instead of a single output, because we always return a single value even for tuple nodes.

----------------------------------------------------------------
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] soiferj commented on issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
soiferj commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-613158127
 
 
   Hi all, sorry for being late to the party, it's been a really busy last couple of months. I was just pulling these changes and trying them out, and I have a question on the handling of constants. @zhiics, is there a reason why you copy the entire content of the constants instead of just using the value of the pointer?
   
   In other words, instead of `float const_1[1000] = {......}`, we could have `float* const_1 = dl_tensor.data`. We can pass that pointer around directly.

----------------------------------------------------------------
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 issue #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
zhiics commented on issue #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#issuecomment-612538495
 
 
   @masahi Thanks for the review. I uncommented those lines. It worked fine.

----------------------------------------------------------------
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 #5310: [BYOC] Enhance partitioning and external codegen

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #5310: [BYOC] Enhance partitioning and external codegen
URL: https://github.com/apache/incubator-tvm/pull/5310#discussion_r407124012
 
 

 ##########
 File path: src/relay/backend/contrib/dnnl/codegen.cc
 ##########
 @@ -176,33 +184,38 @@ class CodegenDNNL : public ExprVisitor, public CodegenCBase {
     CHECK_EQ(GetDtypeString(type_node), "float") << "Only float is supported for now.";
 
     std::ostringstream buf_stream;
-    buf_stream << "float* " << output.name << " = (float*)std::malloc(4 * " << num_elems << ");\n";
     const float* ptr = static_cast<float*>(array.ToDLPack()->dl_tensor.data);
-    for (int64_t i = 0; i < num_elems; i++) {
-      buf_stream << "  " << output.name << "[" << i << "] = " << ptr[i] << ";\n";
+
+    // Allocate large arrays on the static section to avoid stakc overflow.
+    // Note that this would probably increase compilation time as the source
+    // file could be really large.
+    buf_stream << "static float " << output.name << "[" << num_elems <<"] = {";
+    for (int64_t i = 0; i < num_elems - 1; i++) {
+      buf_stream << ptr[i] << ",";
     }
+    if (num_elems > 0) buf_stream << ptr[num_elems - 1];
+    buf_stream << "};\n";
 
     ext_func_body.insert(ext_func_body.begin(), buf_stream.str());
+    return {output};
   }
 
-  void VisitExpr_(const CallNode* call) final {
+  std::vector<Output> VisitExpr_(const CallNode* call) final {
     GenerateBodyOutput ret;
     if (const auto* func = call->op.as<FunctionNode>()) {
       ret = GenerateCompositeFunctionCall(func, call);
     } else {
       ret = GenerateOpCall(call);
     }
 
-    out_.clear();
-    for (size_t i = 0; i < ret.outputs.size(); ++i) {
-      buf_decl_.push_back(ret.buffers[i]);
-      out_.push_back(ret.outputs[i]);
-    }
+    buf_decl_.insert(buf_decl_.end(), ret.buffers.begin(), ret.buffers.end());
+    std::vector<Output> out = ret.outputs;
 
 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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services