currently, loop partition has been enhanced and it can support eliminate ‘likely if’ conditions, but it is only for constant. But for variable, the ‘likely if’ still can’t be eliminated completely.
import tvm
def loop_partition():
n = tvm.var("n")
A = tvm.placeholder((n, ), name='A')
B = tvm.placeholder((n, ), name='B')
T = tvm.compute((n, ), lambda i: A[i]+B[i], name='T')
s = tvm.create_schedule(T.op)
xo, xi = s[T].split(T.op.axis[0], 16)
bounds = tvm.schedule.InferBound(s)
stmt = tvm.schedule.ScheduleOps(s, bounds)
print(stmt)
stmt = tvm.ir_pass.LoopPartition(stmt, True)
stmt = tvm.ir_pass.Simplify(stmt)
print(stmt)
loop_partition()
it print like this: in the second loop, it still has ‘if’, but sometimes we want to eliminate this ‘if’ too.
// attr [compute(T, 0x1a154f0)] realize_scope = ""
realize T([0, n]) {
produce T {
for (i.outer, 0, (n/16)) {
for (i.inner, 0, 16) {
T((i.inner + (i.outer*16))) =(A((i.inner + (i.outer*16))) + B((i.inner + (i.outer*16))))
}
}
for (i.outer, 0, (((n % 16) + 15)/16)) {
for (i.inner, 0, 16) {
if ((i.inner < (n - ((i.outer + (n/16))*16)))) {
T((i.inner + ((i.outer + (n/16))*16))) =(A((i.inner + ((i.outer + (n/16))*16))) + B((i.inner + ((i.outer + (n/16))*16))))
}
}
}
}
}
@tqchen, do you have plan to support this feature?