Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing predicates in split loops #2249

Closed
derisavi opened this issue Dec 6, 2018 · 1 comment
Closed

missing predicates in split loops #2249

derisavi opened this issue Dec 6, 2018 · 1 comment

Comments

@derisavi
Copy link
Contributor

derisavi commented Dec 6, 2018

Consider the following program in which we split a loop by a factor of 48 and then we split the inner loop (which is of size 48) by a factor of 32.

import tvm
m=100
A=tvm.placeholder((m,), name='A')
C=tvm.compute((m,), lambda *index: A(*index), name='C')
s=tvm.create_schedule(C.op)
do,di=s[C].split(C.op.axis[0], 48)
di0,di1 = s[C].split(di, 32)
print(tvm.lower(s, [A,C], simple_mode=True))

The generated Halide IR is:

produce C {
  for (i0.outer, 0, 3) {
    for (i0.inner.outer, 0, 2) {
      for (i0.inner.inner, 0, 32) {
        if (likely(((i0.outer*48) < ((100 - i0.inner.inner) - (i0.inner.outer*32))))) {
          C[(((i0.outer*48) + (i0.inner.outer*32)) + i0.inner.inner)] = A[(((i0.outer*48) + (i0.inner.outer*32)) + i0.inner.inner)]
        }
      }
    }
  }
}

While the generated code is functionally correct but it's inefficient in the sense that some points of the iteration space are visited more than once. In particular, when i0.outer is 0, we execute the assignment for points [0-63], when i0.outer is 1, we execute it for points [48-99], and when i0.outer is 2, we execute it for points [96-99].

If we add a predicate that relates i0.inner.outer and i0.inner.inner (i.e., i0.inner.outer*32 + i0.inner.inner < 48) the problem will be solved.

@derisavi
Copy link
Contributor Author

derisavi commented Dec 6, 2018

I have a patch for this that I will submit hopefully tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants