Anndrey24 commented on code in PR #16660:
URL: https://github.com/apache/tvm/pull/16660#discussion_r1508709220
##########
tests/python/tir-schedule/test_tir_schedule_cache_read_write.py:
##########
@@ -1379,6 +1379,54 @@ def
test_cache_read_fail_invalid_storage_scope(use_block_name):
sch.cache_read(block_b, 0, "test_scope")
+def test_cache_read_allocate_const():
+ @T.prim_func
+ def before(A: T.Buffer((8), "float32"), C: T.Buffer((8), "float32")):
+ B = T.allocate_const([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7],
"float32", [8])
+ B_buf = T.decl_buffer((8), dtype="float32", data=B)
+ for i in T.serial(128):
+ with T.block("C"):
+ vi = T.axis.remap("S", [i])
+ T.reads(A[vi], B_buf[vi])
Review Comment:
Agreed! However, it seems that `B_buf` does not get automatically added to
the `T.reads()` annotations so I still specify it myself in the two blocks
where it is needed. This would be the error after removing all `T.reads()` and
`T.writes()`:
```
ScheduleError: An error occurred in the schedule primitive 'cache-read'.
E The IR with diagnostic is:
E # from tvm.script import ir as I
E # from tvm.script import tir as T
E
E @I.ir_module
E class Module:
E @T.prim_func
E def main(A_handle: T.handle, C_handle: T.handle):
E T.func_attr({"global_symbol": "before"})
E A = T.match_buffer(A_handle, (8,))
E C = T.match_buffer(C_handle, (8,))
E with T.block("root"):
E T.reads()
E T.writes()
E B_buf = T.allocate_const([0, 0.10000000149011612,
0.20000000298023224, 0.30000001192092896, 0.40000000596046448, 0.5,
0.60000002384185791, 0.69999998807907104], "float32", [8])
E B_buf_1 = T.decl_buffer((8,), data=B_buf)
E for i in range(8):
E # tir.Block#0
E with T.block("C"):
E ^^^^^^^^^^^^^^^^^^
E vi = T.axis.spatial(8, i)
E ^^^^^^^^^^^^^^^^^^^^^^^^^
E T.reads(A[vi])
E ^^^^^^^^^^^^^^
E T.writes(C[vi])
E ^^^^^^^^^^^^^^^
E C[vi] = A[vi] + B_buf_1[vi]
E ^^^^^^^^^^^^^^^^^^^^^^^^^^^
E Error message: The block tir.Block#0 has 1 read regions, so
`buffer_index` is required to be in [0, 1). However, the input `buffer_index`
is 1, which is out of the expected range.
```
--
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]