Hi Qiu,
From my point of view, ProducerConsumer is a feature first used in Halide. In TVM, each tensor(or buffer) has exactly three stage(except for the output) : Allocate->Producer->Consumer. It’s straight forward. In Allocate phase, it help allocate the memory used to store that buffer, and in Producer phase, it will calculate the value of each element in that buffer, and then, used them in consumer. In Producer phase, the buffer is WRITE ONLY, and in Consumer phase, is READ ONLY.
For example, for the following TVM code
a = tvm.placeholder([10])
b = tvm.compute((10,),lambda i:a[i],name=‘b’)
c = tvm.compute((10,),lambda i:b[i],name=‘c’)
and it willgenerate the following stmt:
// attr [b] storage_scope = “global”
allocate b[float32 * 10]
produce b {
for (i, 0, 10) {
b[i] = placeholder[i]
}
}
produce c {
for (i, 0, 10) {
b[i] = b[i]
}
}
for the produce b
part, it’s produce for tensor(buffer) b, and produce c
is produce for tensor c, but also consume for tensor b.