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


##########
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 have now updated the tests.
   tests/python/contrib/test_hexagon/test_cache_read_write.py::test_vtcm_limit
   
tests/python/unittest/test_tir_analysis_calculate_allocated_memory.py::test_scale_by
   
tests/python/unittest/test_tir_analysis_calculate_allocated_memory.py::test_matmul_mix_scope
   
   On your question: You mean tests that show how much memory was allocated 
through nd_mem_alloc_with_scope after lower, and compare this to what 
tir.analysis.calculate_allocated_bytes shows. Correct?
   
   Our interest in the line - 
   `let buffer_a_global.vtcm: Pointer(global.vtcm int8) = 
@tir.nd_mem_alloc_with_scope("global.vtcm", 1i64, 
@tir.tvm_stack_make_shape(1024, dtype=handle), dtype=handle)`
   in the example:
   ```
   @main = primfn(buffer_a_handle: handle, buffer_c_handle: handle) -> ()
     attr = {"global_symbol": "main", "tir.noalias": True}
     buffers = {buffer_a: Buffer(buffer_a_1: Pointer(global int8), int8, 
[8192], []),
                buffer_c: Buffer(buffer_c_1: Pointer(global int8), int8, 
[8192], [])}
     buffer_map = {buffer_a_handle: buffer_a, buffer_c_handle: buffer_c}
     preflattened_buffer_map = {buffer_c_handle: buffer_c_2: Buffer(buffer_c_1, 
int8, [8192], []), buffer_a_handle: buffer_a_2: Buffer(buffer_a_1, int8, 
[8192], [])} {
     let buffer_a_global.vtcm: Pointer(global.vtcm int8) = 
@tir.nd_mem_alloc_with_scope("global.vtcm", 1i64, 
@tir.tvm_stack_make_shape(1024, dtype=handle), dtype=handle)
     for (i_0: int32, 0, 8) {
       for (ax0: int32, 0, 1024) {
         buffer_a_global.vtcm_1: Buffer(buffer_a_global.vtcm, int8, [1024], [], 
scope="global.vtcm")[ax0] = buffer_a[((i_0*1024) + ax0)]
       }
       for (i_1: int32, 0, 4) {
         for (i_2: int32, 0, 2) {
           for (i_3: int32, 0, 128) {
             let cse_var_2: int32 = (i_1*256)
             let cse_var_1: int32 = (i_2*128)
             buffer_c[((((i_0*1024) + cse_var_2) + cse_var_1) + i_3)] = 
(buffer_a_global.vtcm_1[((cse_var_2 + cse_var_1) + i_3)]*2i8)
           }
         }
       }
     }
   }
   ```



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