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/16 14:13:33 UTC

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

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