Icemist commented on code in PR #13349:
URL: https://github.com/apache/tvm/pull/13349#discussion_r1030600187


##########
tests/python/unittest/test_tir_analysis_calculate_allocated_memory.py:
##########
@@ -0,0 +1,65 @@
+# 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.
+import pytest
+
+import tvm
+from tvm import tir
+from tvm.script import tir as T
+
+
+# fmt: off
[email protected]_func
+def matmul_some_scope(a: T.handle, b: T.handle, c: T.handle) -> None:
+    A = T.match_buffer(a, [128, 128], scope="global")
+    A_ = T.alloc_buffer([128, 128], dtype="float32", scope="global.texture")
+    B = T.match_buffer(b, [128, 128], scope="global")
+    B_ = T.alloc_buffer([128, 128], dtype="float32", scope="global.texture")
+    C = T.match_buffer(c, [128, 128], scope="global")
+    C_ = T.alloc_buffer([128, 128], dtype="float32", scope="global")
+    
+    for i, j in T.grid(128, 128):
+        with T.block("A_.texture"):
+            A_[i, j] = A[i, j]
+    for i, j in T.grid(128, 128):
+        with T.block("B_.texture"):
+            B_[i, j] = B[i, j]
+
+    for i, j, k in T.grid(128, 128, 128):
+        with T.block("update"):
+            vi, vj, vk = T.axis.remap("SSR", [i, j, k])
+            with T.init():
+                C_[vi, vj] = 0.0
+            C_[vi, vj] = C_[vi, vj] + A_[vi, vk] * B_[vj, vk]
+    
+    for i, j in T.grid(128, 128):
+        with T.block("C"):
+            C[i, j] = C_[i, j]
+# fmt: on
+
+
[email protected](
+    "scope,size", [("global", 131072), ("global.texture", 131072*2), 
("global.texture-nhwc", 0)]
+)
+def test_allocates(scope, size):

Review Comment:
   I meant comparing the memory counted with pass and how much memory is 
allocated with nd_mem_alloc_with_scope after lowering.
   Something like(a sketch): 
    ```
      def calc(irmod):
           size = 0
           def _visit(stmt):
               nonlocal size
               if isinstance(stmt, tvm.tir.expr.Call) and isinstance(stmt.op, 
tvm.ir.op.Op) and stmt.op.name == "tir.nd_mem_alloc_with_scope":
                   storage_scope, extents_size, call = stmt.args
                   extents, = call.args
                   dtype = call.dtype
                   print("ATTRS", storage_scope, extents_size, extents, dtype)
                   if storage_scope == "global.vtcm":
                       size += extents_size * dtype.bytes() #
   
           tvm.tir.stmt_functor.post_order_visit(irmod["main"].body, _visit)
           return size
   
       print(calc(lowered))
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to