tqchen commented on a change in pull request #10843:
URL: https://github.com/apache/tvm/pull/10843#discussion_r839585218



##########
File path: tests/python/unittest/test_tir_transform_regenerate_def.py
##########
@@ -0,0 +1,94 @@
+# 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 sys
+
+import tvm
+from tvm.script import tir as T
+from tvm.tir.function import PrimFunc
+from tvm.tir.stmt import Block
+
+
+def _check_func_signature(lhs: PrimFunc, rhs: PrimFunc):
+    for x, y in zip(lhs.params, rhs.params):
+        assert x != y
+        assert lhs.buffer_map[x] != rhs.buffer_map[y]
+
+
+def _check_block_signature(lhs: Block, rhs: Block):
+    for x, y in zip(lhs.iter_vars, rhs.iter_vars):
+        assert x != y
+    for x, y in zip(lhs.alloc_buffers, rhs.alloc_buffers):
+        assert x != y
+    for x, y in zip(lhs.match_buffers, rhs.match_buffers):
+        assert x != y
+
+
+def test_simple():
+    @T.prim_func
+    def elementwise(A: T.Buffer[(128, 128), "float32"], C: T.Buffer[(128, 
128), "float32"]):
+        B = T.alloc_buffer((128, 128), "float32")
+        for i, j in T.grid(128, 128):
+            with T.block("B"):
+                vi, vj = T.axis.remap("SS", [i, j])
+                B[vi, vj] = A[vi, vj] * 2.0
+        for i, j in T.grid(128, 128):

Review comment:
       Would be great to have a case where the access region are explicitly 
marked

##########
File path: tests/python/unittest/test_tir_transform_regenerate_def.py
##########
@@ -0,0 +1,94 @@
+# 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 sys
+
+import tvm
+from tvm.script import tir as T
+from tvm.tir.function import PrimFunc
+from tvm.tir.stmt import Block
+
+
+def _check_func_signature(lhs: PrimFunc, rhs: PrimFunc):
+    for x, y in zip(lhs.params, rhs.params):
+        assert x != y
+        assert lhs.buffer_map[x] != rhs.buffer_map[y]
+
+
+def _check_block_signature(lhs: Block, rhs: Block):
+    for x, y in zip(lhs.iter_vars, rhs.iter_vars):
+        assert x != y
+    for x, y in zip(lhs.alloc_buffers, rhs.alloc_buffers):
+        assert x != y
+    for x, y in zip(lhs.match_buffers, rhs.match_buffers):
+        assert x != y
+
+
+def test_simple():
+    @T.prim_func
+    def elementwise(A: T.Buffer[(128, 128), "float32"], C: T.Buffer[(128, 
128), "float32"]):
+        B = T.alloc_buffer((128, 128), "float32")
+        for i, j in T.grid(128, 128):
+            with T.block("B"):
+                vi, vj = T.axis.remap("SS", [i, j])
+                B[vi, vj] = A[vi, vj] * 2.0
+        for i, j in T.grid(128, 128):
+            with T.block("C"):
+                vi, vj = T.axis.remap("SS", [i, j])
+                C[vi, vj] = B[vi, vj] + 1.0
+
+    f1 = elementwise
+    f2 = tvm.tir.stmt_functor.regenerate_def(f1)
+    tvm.ir.assert_structural_equal(f1, f2)
+
+    _check_func_signature(f1, f2)
+    _check_block_signature(f1.body.block, f2.body.block)
+    assert f1.body.block.body[0].loop_var != f2.body.block.body[0].loop_var
+
+    def _get_block(f):
+        return f.body.block.body[0].body.body.block
+
+    _check_block_signature(_get_block(f1), _get_block(f2))
+
+
+def test_match_buffer():
+    @T.prim_func
+    def func_match_buffer(A: T.Buffer[(128, 128), "float32"], B: 
T.Buffer[(128, 128), "float32"]):
+        with T.block("root"):
+            A0 = T.match_buffer(A[0:128, 0:128], (128, 128), "float32")
+            for i, j in T.grid(128, 128):
+                with T.block("B"):
+                    vi, vj = T.axis.remap("SS", [i, j])

Review comment:
       we need a case where we remapped the buffer then access the buffer 
elements including:
   
   - shape vars (when it is defined by match buffer)
   - 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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to