[quote="xiacijie, post:9, topic:10113"]
I am confused when we already declare a 128 * 128 loop outer, we still have to 
put `[128, 128]` as a parameter when using `tir.block`
[/quote]

The syntax below describes the signature of a block:

```python
with tir.block([128, 128], "init") as [vi, vj]:
```

TensorIR is designed with the "block isolation" philosophy, and a block here 
describes a chunk of computation without needing context. When desugared, your 
particular example above expands to:

```python
for i in range(0, 128):
  for j in range(0, 128):
    with tir.block([128, 128], "init") as [vi, vj]:
      # vi's domain is [0, 128), and it is data-parallel
      # vj's domain is [0, 128), and it is data-parallel
      tir.bind(vi, i)  # binds `i` to `vi`
      tir.bind(vi, j)  # binds `j` to `vj`
      tir.reads([])  # reads nothing
      tir.writes(C[vi : vi + 1, vj : vj + 1]) 
      C[vi, vj] = 0
```

The property of the block is that:
* Instances of block execution are described with pair `(vi, vj)`, where `vi, 
vj \in [0, 128)`.
*  For a certain instance of a block `(vi, vj)`, it doesn't read anything, and 
writes to a buffer region `C[vi : vi + 1, vj : vj + 1]`
* `vi, vj` are both data parallel, which means block instances `(vi, vj)` can 
be executed in arbitrary orders or in parallel

Block bindings (`tir.bind`) describe how those loops "drags" the block 
execution. It is possible that we execute in another order:

```python
for i in range(0, 128):
  for j in range(0, 128):
    with tir.block([128, 128], "init") as [vi, vj]:
      tir.bind(vi, 127 - i)  # binds `127 - i` to `vi`
      tir.bind(vi, 127 - j)  # binds `127 - j` to `vj`
```

In short, in TensorIR, we decouple "in which order loop runs" and "the 
computation in the block body". Therefore, over-complete information may occur 
(as you described) when the binding is trivial, and we provide syntactic sugars 
for this case.





---
[Visit 
Topic](https://discuss.tvm.apache.org/t/combining-separate-tir-block-using-compute-at/10113/11)
 to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.apache.org/email/unsubscribe/52f01f94c94b2908e2847278951e45a9464a2393fdd3cac14a8d9b38c5609d6d).

Reply via email to