Lunderberg commented on code in PR #14280:
URL: https://github.com/apache/tvm/pull/14280#discussion_r1133951480
##########
tests/python/unittest/test_tir_transform_lower_warp_memory.py:
##########
@@ -347,5 +348,105 @@ def test_lower_warp_memory_divide_by_factor():
tvm.tir.transform.LowerWarpMemory()(mod)["f_kernel0"]
[email protected]_func
+def func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [32], "float32")
+ B = T.match_buffer(b, [32], "float32")
+ for i in range(32):
+ with T.block("warp_shuffle"):
+ vi = T.axis.spatial(32, i)
+ B[vi] = A[(vi % 4) * 8 + vi // 4] + T.float32(1)
+
+
+def test_warp_shuffle_transform():
+ @tvm.script.ir_module
+ class Before:
+ @T.prim_func
+ def main(A: T.handle("float32", "global"), B: T.handle("float32",
"global")):
+ blockIdx_x = T.env_thread("blockIdx.x")
+ threadIdx_x = T.env_thread("threadIdx.x")
+ T.func_attr(
Review Comment:
It looks like the test case only requires the `"target"` attribute, and only
requires `"kind"` and `"thread_warp_size"` within that. Can we remove the
extra attributes from the unit test?
##########
tests/python/unittest/test_tir_transform_lower_warp_memory.py:
##########
@@ -347,5 +348,105 @@ def test_lower_warp_memory_divide_by_factor():
tvm.tir.transform.LowerWarpMemory()(mod)["f_kernel0"]
[email protected]_func
+def func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [32], "float32")
+ B = T.match_buffer(b, [32], "float32")
+ for i in range(32):
+ with T.block("warp_shuffle"):
+ vi = T.axis.spatial(32, i)
+ B[vi] = A[(vi % 4) * 8 + vi // 4] + T.float32(1)
+
+
+def test_warp_shuffle_transform():
+ @tvm.script.ir_module
+ class Before:
+ @T.prim_func
+ def main(A: T.handle("float32", "global"), B: T.handle("float32",
"global")):
+ blockIdx_x = T.env_thread("blockIdx.x")
+ threadIdx_x = T.env_thread("threadIdx.x")
+ T.func_attr(
+ {
+ "calling_conv": 2,
+ "global_symbol": "main",
+ "target": T.target(
+ {
+ "host": {"keys": ["cpu"], "kind": "llvm", "tag":
""},
+ "keys": ["cuda", "gpu"],
+ "kind": "cuda",
+ "max_num_threads": 1024,
+ "tag": "",
+ "thread_warp_size": 32,
+ }
+ ),
+ "tir.device_thread_axis": [
+ T.iter_var(blockIdx_x, [0, 1], "ThreadIndex",
"blockIdx.x"),
+ T.iter_var(threadIdx_x, [0, 32], "ThreadIndex",
"threadIdx.x"),
+ ],
+ "tir.is_global_func": 1,
+ "tir.noalias": 1,
+ }
+ )
+ T.launch_thread(blockIdx_x, 1)
+ A_warp = T.allocate([32], "float32", "warp")
+ B_warp = T.allocate([32], "float32", "warp")
+ T.launch_thread(threadIdx_x, 32)
+ A_warp_1 = T.Buffer((32,), data=A_warp, scope="warp")
+ A_1 = T.Buffer((32,), data=A)
Review Comment:
Instead of having a separate `A: T.handle` and `A_1: T.Buffer`, the buffer
could be declared as a parameter `A_1: T.Buffer(32)`. It does result in
slightly different TIR, as it follows the style from before `MakePackedAPI` is
applied, but for a unit test would help to emphasize the change being tested.
##########
tests/python/unittest/test_tir_transform_lower_warp_memory.py:
##########
@@ -347,5 +348,105 @@ def test_lower_warp_memory_divide_by_factor():
tvm.tir.transform.LowerWarpMemory()(mod)["f_kernel0"]
[email protected]_func
+def func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [32], "float32")
+ B = T.match_buffer(b, [32], "float32")
+ for i in range(32):
+ with T.block("warp_shuffle"):
+ vi = T.axis.spatial(32, i)
+ B[vi] = A[(vi % 4) * 8 + vi // 4] + T.float32(1)
+
+
+def test_warp_shuffle_transform():
+ @tvm.script.ir_module
+ class Before:
+ @T.prim_func
+ def main(A: T.handle("float32", "global"), B: T.handle("float32",
"global")):
+ blockIdx_x = T.env_thread("blockIdx.x")
+ threadIdx_x = T.env_thread("threadIdx.x")
+ T.func_attr(
+ {
+ "calling_conv": 2,
+ "global_symbol": "main",
+ "target": T.target(
+ {
+ "host": {"keys": ["cpu"], "kind": "llvm", "tag":
""},
+ "keys": ["cuda", "gpu"],
+ "kind": "cuda",
+ "max_num_threads": 1024,
+ "tag": "",
+ "thread_warp_size": 32,
+ }
+ ),
+ "tir.device_thread_axis": [
+ T.iter_var(blockIdx_x, [0, 1], "ThreadIndex",
"blockIdx.x"),
+ T.iter_var(threadIdx_x, [0, 32], "ThreadIndex",
"threadIdx.x"),
+ ],
+ "tir.is_global_func": 1,
+ "tir.noalias": 1,
+ }
+ )
+ T.launch_thread(blockIdx_x, 1)
+ A_warp = T.allocate([32], "float32", "warp")
+ B_warp = T.allocate([32], "float32", "warp")
+ T.launch_thread(threadIdx_x, 32)
+ A_warp_1 = T.Buffer((32,), data=A_warp, scope="warp")
+ A_1 = T.Buffer((32,), data=A)
+ A_warp_1[threadIdx_x] = A_1[threadIdx_x]
+ B_warp_1 = T.Buffer((32,), data=B_warp, scope="warp")
+ T.tvm_storage_sync("warp")
+ B_warp_1[threadIdx_x] = A_warp_1[threadIdx_x % 4 * 8 + threadIdx_x
// 4] + T.float32(1)
Review Comment:
Could we add a comment here, indicating that this line is the one that
should be updated correctly?
##########
tests/python/unittest/test_tir_transform_lower_warp_memory.py:
##########
@@ -347,5 +348,105 @@ def test_lower_warp_memory_divide_by_factor():
tvm.tir.transform.LowerWarpMemory()(mod)["f_kernel0"]
[email protected]_func
+def func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [32], "float32")
+ B = T.match_buffer(b, [32], "float32")
+ for i in range(32):
+ with T.block("warp_shuffle"):
+ vi = T.axis.spatial(32, i)
+ B[vi] = A[(vi % 4) * 8 + vi // 4] + T.float32(1)
+
+
+def test_warp_shuffle_transform():
Review Comment:
The test looks reasonable as-is, though there's also a
`tvm.testing.CompareBeforeAfter` that you could use to further reduce the
boilerplate.
```python
class TestWarpShuffleTransform(tvm.testing.CompareBeforeAfter):
transform = tvm.tir.transform.LowerWarpMemory()
def before(A: T.handle("float32", "global"), B: T.handle("float32",
"global")):
...
def expected(A: T.handle("float32", "global"), B: T.handle("float32",
"global")):
...
```
--
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]