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 2021/04/15 16:32:03 UTC

[GitHub] [tvm] manupa-arm opened a new pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

manupa-arm opened a new pull request #7859:
URL: https://github.com/apache/tvm/pull/7859


   This commit introduces functionality to query the workspace sizeas required by a tir primfunc by looking at tir.allocates inside of it.
   I needed to do a small fix for tvmscript parser and scope handler to make the test cases work.
   
   
   
   
   


-- 
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



[GitHub] [tvm] manupa-arm commented on pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #7859:
URL: https://github.com/apache/tvm/pull/7859#issuecomment-821207900


   Thanks @jcf94 for the review -- I think I've addressed your comments.


-- 
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



[GitHub] [tvm] manupa-arm edited a comment on pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

Posted by GitBox <gi...@apache.org>.
manupa-arm edited a comment on pull request #7859:
URL: https://github.com/apache/tvm/pull/7859#issuecomment-821207900


   Thanks @jcf94 for the review -- I think I've addressed your comments. I think it could be zero where the primfunc does not require tir.allocates or additional workspace to perform the operation.


-- 
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



[GitHub] [tvm] manupa-arm commented on pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #7859:
URL: https://github.com/apache/tvm/pull/7859#issuecomment-821958968


   @jcf94 Yes, we are planning to use it there and we think it'd be a good utility for memory planning project 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



[GitHub] [tvm] jcf94 commented on a change in pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

Posted by GitBox <gi...@apache.org>.
jcf94 commented on a change in pull request #7859:
URL: https://github.com/apache/tvm/pull/7859#discussion_r614501192



##########
File path: include/tvm/tir/analysis.h
##########
@@ -178,6 +178,12 @@ Array<Array<BufferRegion>> GetBlockAccessRegion(const Block& block,
  */
 TVM_DLL size_t CalculateExprComplexity(const PrimExpr& expr);
 
+/*!
+ * \brief Calculate the workspace size in bytes needed by the TIR allocates inside the TIR PrimFunc
+ * \param func The TIR PrimFunc for which the workspace size to be calculated
+ */
+TVM_DLL int CalculateWorkspaceBytes(const PrimFunc& func);

Review comment:
       ```suggestion
   TVM_DLL size_t CalculateWorkspaceBytes(const PrimFunc& func);
   ```

##########
File path: src/tir/analysis/calculate_workspace.cc
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tir/analysis/calculate_workspace.cc
+ * \brief Calculate any intermediary memory required by PrimFuncs.
+ */
+#include <tvm/arith/analyzer.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/function.h>
+#include <tvm/tir/stmt_functor.h>
+
+namespace tvm {
+namespace tir {
+
+class WorkspaceCalculator : public StmtExprVisitor {
+ public:
+  WorkspaceCalculator() = default;
+  int operator()(const PrimFunc& func);
+
+ private:
+  void VisitStmt_(const AllocateNode* op) override;
+  int CalculateExtentsSize(const AllocateNode* op);
+  int current_size = 0;
+  int max_size = 0;
+};
+
+int WorkspaceCalculator::operator()(const PrimFunc& func) {
+  this->VisitStmt(func->body);
+  return this->max_size;
+}

Review comment:
       ditto. Update `int` to `size_t`




-- 
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



[GitHub] [tvm] manupa-arm commented on a change in pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on a change in pull request #7859:
URL: https://github.com/apache/tvm/pull/7859#discussion_r614870603



##########
File path: include/tvm/tir/analysis.h
##########
@@ -178,6 +178,12 @@ Array<Array<BufferRegion>> GetBlockAccessRegion(const Block& block,
  */
 TVM_DLL size_t CalculateExprComplexity(const PrimExpr& expr);
 
+/*!
+ * \brief Calculate the workspace size in bytes needed by the TIR allocates inside the TIR PrimFunc
+ * \param func The TIR PrimFunc for which the workspace size to be calculated
+ */
+TVM_DLL int CalculateWorkspaceBytes(const PrimFunc& func);

Review comment:
       Done.

##########
File path: src/tir/analysis/calculate_workspace.cc
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tir/analysis/calculate_workspace.cc
+ * \brief Calculate any intermediary memory required by PrimFuncs.
+ */
+#include <tvm/arith/analyzer.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/function.h>
+#include <tvm/tir/stmt_functor.h>
+
+namespace tvm {
+namespace tir {
+
+class WorkspaceCalculator : public StmtExprVisitor {
+ public:
+  WorkspaceCalculator() = default;
+  int operator()(const PrimFunc& func);
+
+ private:
+  void VisitStmt_(const AllocateNode* op) override;
+  int CalculateExtentsSize(const AllocateNode* op);
+  int current_size = 0;
+  int max_size = 0;
+};
+
+int WorkspaceCalculator::operator()(const PrimFunc& func) {
+  this->VisitStmt(func->body);
+  return this->max_size;
+}

Review comment:
       Done.




-- 
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



[GitHub] [tvm] jcf94 merged pull request #7859: [TIR] An analysis pass to calculate workspace size for primfuncs

Posted by GitBox <gi...@apache.org>.
jcf94 merged pull request #7859:
URL: https://github.com/apache/tvm/pull/7859


   


-- 
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