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/10/07 22:21:01 UTC
[GitHub] [tvm] shingjan opened a new pull request #9224: [TIR] Add support for 0-dim buffer
shingjan opened a new pull request #9224:
URL: https://github.com/apache/tvm/pull/9224
This PR intends to add support and test cases for 0-dimensional buffer in TVM.
cc: @junrushao1994 @vinx13 @zxybazh
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r727364832
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,30 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ func = alloc_buffer_func
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ tvm.ir.assert_structural_equal(func, rt_func)
Review comment:
let's write a `expected_alloc_buffer_func` like previous test cases and assert structural equal
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,30 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ func = alloc_buffer_func
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ tvm.ir.assert_structural_equal(func, rt_func)
Review comment:
let's write an `expected_alloc_buffer_func` like previous test cases and assert structural equal
##########
File path: tests/python/unittest/test_tvmscript_ops.py
##########
@@ -101,5 +101,42 @@ def test_get_valid_counts_script_func():
_check_get_valid_counts_with_numpy(f, (1, 2500, 6), 0.0, 0, 1)
+@T.prim_func
+def alloc_zero_dim_buffer(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [], dtype="float32")
+ B = T.match_buffer(b, [], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([], dtype="float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+@T.prim_func
+def alloc_zero_dim_buffer_block(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, (), "float32")
+ B = T.match_buffer(b, (), "float32")
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer((), "float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+def test_alloc_zero_dim_buffer_round_trip():
+ func = alloc_zero_dim_buffer
+ func_with_block = alloc_zero_dim_buffer_block
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_func_with_block = tvm.script.from_source(func_with_block.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ rt_mod_with_block = tvm.build(rt_func_with_block, "llvm")
+ tvm.ir.assert_structural_equal(func, func_with_block)
Review comment:
we need to do e2e test against numpy here instead of roundtrip
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,40 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+@T.prim_func
+def expect_alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ B = T.match_buffer(b, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer([2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ rt_func = tvm.script.from_source(alloc_buffer_func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
Review comment:
```suggestion
```
remove this as it is beyond script complete
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#issuecomment-941277329
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] shingjan commented on pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
shingjan commented on pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#issuecomment-942589018
@vinx13 With https://github.com/apache/tvm/blob/main/src/te/operation/create_primfunc.cc#L105-L109 removed, all tests under `test_te_*` passed. Should be good to merge after the checks.
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#issuecomment-941277329
given we have 0-rank support in TIR, we can remove these lines to directly lower to 0-rank TIR https://github.com/apache/tvm/blob/main/src/te/operation/create_primfunc.cc#L105-L109. Please check if we can pass this test case https://github.com/apache/tvm/blob/main/tests/python/unittest/test_te_create_primfunc.py#L286-L300
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on a change in pull request #9224: [TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r728546565
##########
File path: tests/python/unittest/test_tvmscript_ops.py
##########
@@ -101,5 +101,65 @@ def test_get_valid_counts_script_func():
_check_get_valid_counts_with_numpy(f, (1, 2500, 6), 0.0, 0, 1)
+@T.prim_func
+def alloc_zero_dim_buffer(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [], dtype="float32")
+ B = T.match_buffer(b, [], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([], dtype="float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+@T.prim_func
+def alloc_zero_dim_buffer_block(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, (), "float32")
+ B = T.match_buffer(b, (), "float32")
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer((), "float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+def _check_alloc_zero_dim_buffer(f):
+ dtype = "float32"
+ ctx = tvm.cpu()
+
+ np_data = np.zeros(shape=()).astype(dtype)
+ np_out = np.zeros(shape=()).astype(dtype)
+ tvm_data = tvm.nd.array(np_data, ctx)
+ tvm_out = tvm.nd.array(np_out, ctx)
+
+ # np func exection
+ np_inter = np.array(1)
+ np_data[()] = 2.0
+ np_inter[()] = np_data[()] + np_out[()]
+ np_out[()] = np_inter[()]
+
+ # tvm func execution
+ f(tvm_data, tvm_out)
+ tvm.testing.assert_allclose(tvm_out.numpy(), np_out, rtol=1e-5)
+ print("test alloc_zero_dim_buffer end")
Review comment:
nit: remove this print
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] shingjan commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
shingjan commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r728331931
##########
File path: tests/python/unittest/test_tvmscript_ops.py
##########
@@ -101,5 +101,42 @@ def test_get_valid_counts_script_func():
_check_get_valid_counts_with_numpy(f, (1, 2500, 6), 0.0, 0, 1)
+@T.prim_func
+def alloc_zero_dim_buffer(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [], dtype="float32")
+ B = T.match_buffer(b, [], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([], dtype="float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+@T.prim_func
+def alloc_zero_dim_buffer_block(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, (), "float32")
+ B = T.match_buffer(b, (), "float32")
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer((), "float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+def test_alloc_zero_dim_buffer_round_trip():
+ func = alloc_zero_dim_buffer
+ func_with_block = alloc_zero_dim_buffer_block
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_func_with_block = tvm.script.from_source(func_with_block.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ rt_mod_with_block = tvm.build(rt_func_with_block, "llvm")
+ tvm.ir.assert_structural_equal(func, func_with_block)
Review comment:
done
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,40 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+@T.prim_func
+def expect_alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ B = T.match_buffer(b, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer([2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ rt_func = tvm.script.from_source(alloc_buffer_func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r727364832
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,30 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ func = alloc_buffer_func
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ tvm.ir.assert_structural_equal(func, rt_func)
Review comment:
let's write a `expected_alloc_buffer_func` like previous test cases and assert structural equal
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,30 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ func = alloc_buffer_func
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ tvm.ir.assert_structural_equal(func, rt_func)
Review comment:
let's write an `expected_alloc_buffer_func` like previous test cases and assert structural equal
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] shingjan commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
shingjan commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r727431386
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,30 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ func = alloc_buffer_func
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ tvm.ir.assert_structural_equal(func, rt_func)
Review comment:
done
##########
File path: tests/python/unittest/test_tvmscript_ops.py
##########
@@ -101,5 +101,42 @@ def test_get_valid_counts_script_func():
_check_get_valid_counts_with_numpy(f, (1, 2500, 6), 0.0, 0, 1)
+@T.prim_func
+def alloc_zero_dim_buffer(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [], dtype="float32")
+ B = T.match_buffer(b, [], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([], dtype="float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+@T.prim_func
+def alloc_zero_dim_buffer_block(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, (), "float32")
+ B = T.match_buffer(b, (), "float32")
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer((), "float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+def test_alloc_zero_dim_buffer_round_trip():
+ func = alloc_zero_dim_buffer
+ func_with_block = alloc_zero_dim_buffer_block
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_func_with_block = tvm.script.from_source(func_with_block.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ rt_mod_with_block = tvm.build(rt_func_with_block, "llvm")
+ tvm.ir.assert_structural_equal(func, func_with_block)
Review comment:
done
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,40 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+@T.prim_func
+def expect_alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ B = T.match_buffer(b, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer([2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ rt_func = tvm.script.from_source(alloc_buffer_func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] shingjan commented on pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
shingjan commented on pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#issuecomment-942589018
@vinx13 With https://github.com/apache/tvm/blob/main/src/te/operation/create_primfunc.cc#L105-L109 removed, all tests under `test_te_*` passed. Should be good to merge after the checks.
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] shingjan commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
shingjan commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r727431386
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,30 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ func = alloc_buffer_func
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ tvm.ir.assert_structural_equal(func, rt_func)
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.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r727433849
##########
File path: tests/python/unittest/test_tvmscript_ops.py
##########
@@ -101,5 +101,42 @@ def test_get_valid_counts_script_func():
_check_get_valid_counts_with_numpy(f, (1, 2500, 6), 0.0, 0, 1)
+@T.prim_func
+def alloc_zero_dim_buffer(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [], dtype="float32")
+ B = T.match_buffer(b, [], dtype="float32")
+ # body
+ # tir.with block("root")
+ C = T.alloc_buffer([], dtype="float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+@T.prim_func
+def alloc_zero_dim_buffer_block(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, (), "float32")
+ B = T.match_buffer(b, (), "float32")
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer((), "float32")
+ A[()] = T.float32(2)
+ C[()] = A[()] + B[()]
+ B[()] = C[()]
+
+
+def test_alloc_zero_dim_buffer_round_trip():
+ func = alloc_zero_dim_buffer
+ func_with_block = alloc_zero_dim_buffer_block
+ rt_func = tvm.script.from_source(func.script(show_meta=True))
+ rt_func_with_block = tvm.script.from_source(func_with_block.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
+ rt_mod_with_block = tvm.build(rt_func_with_block, "llvm")
+ tvm.ir.assert_structural_equal(func, func_with_block)
Review comment:
we need to do e2e test against numpy here instead of roundtrip
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on a change in pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on a change in pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#discussion_r727501661
##########
File path: tests/python/unittest/test_tvmscript_complete.py
##########
@@ -272,10 +272,40 @@ def test_complete_match_buffer():
tvm.ir.assert_structural_equal(match_buffer_func, expected_match_buffer_func)
+@T.prim_func
+def alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32")
+ B = T.match_buffer(b, [2, 2], dtype="float32")
+ C = T.alloc_buffer([2, 2], dtype="float32")
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+@T.prim_func
+def expect_alloc_buffer_func(a: T.handle, b: T.handle) -> None:
+ A = T.match_buffer(a, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ B = T.match_buffer(b, [2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ with T.block([], "root"):
+ T.reads([])
+ T.writes([])
+ C = T.alloc_buffer([2, 2], dtype="float32", elem_offset=0, align=128, offset_factor=1)
+ A[(0, 0)] = T.float32(2)
+ C[(0, 0)] = A[(0, 0)] + B[(0, 0)]
+ B[(0, 0)] = C[(0, 0)]
+
+
+def test_complete_alloc_buffer():
+ rt_func = tvm.script.from_source(alloc_buffer_func.script(show_meta=True))
+ rt_mod = tvm.build(rt_func, "llvm")
Review comment:
```suggestion
```
remove this as it is beyond script complete
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vinx13 commented on pull request #9224: [WIP][TIR] Add support for 0-dim buffer
Posted by GitBox <gi...@apache.org>.
vinx13 commented on pull request #9224:
URL: https://github.com/apache/tvm/pull/9224#issuecomment-941738896
Overall LGTM, please address comments and get it merged soon
--
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: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org