cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
326 stars 92 forks source link

[Schedule] support reorder #21

Closed Huyuwei closed 6 years ago

Huyuwei commented 6 years ago

This PR adds reorder schedule. Now we can write code:

  a = hcl.placeholder((10, 20, 30, 40))
  b = hcl.placeholder((10, 20, 30, 40))
  c = hcl.compute(a.shape, lambda i, j, k, l: a[i, j, k, l] + b[i, j, k, l])
  s = hcl.create_schedule(c)
  s[c].reorder(c.axis[2], c.axis[1])
  ir = hcl.lower(s, [a, b, c])

The generated IR is:

// attr [0] extern_scope = 0
for (i, 0, 10) {
  for (k, 0, 30) {
    for (j, 0, 20) {
      for (l, 0, 40) {
        compute8[(((l + (k*40)) + (j*1200)) + (i*24000))] = int32((int34(placeholder6[(((l + (k*40)) + (j*1200)) + (i*24000))]) + int34(placeholder7[(((l + (k*40)) + (j*1200)) + (i*24000))])))
      }
    }
  }
}
comaniac commented 6 years ago

Could you modify the samples to demonstrate the usability in practice, and add unit tests?

rzhao01 commented 6 years ago

I feel like reorder should work similar to np.transpose or tf.transpose and take a list of integers. Is that possible?

On Tue, Jul 17, 2018, 3:51 PM Cody Hao Yu notifications@github.com wrote:

Could you modify the samples to demonstrate the usability in practice, and add unit tests?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cornell-zhang/heterocl/pull/21#issuecomment-405753393, or mute the thread https://github.com/notifications/unsubscribe-auth/AGYd0Nru7R2htCWUnjO-ysW9CI7Ogm0xks5uHmpcgaJpZM4VTrR9 .

zhangzhiru commented 6 years ago

I agree with @comaniac . It's very important for us to create unit tests for each new feature we add as well as each bug fix.

seanlatias commented 6 years ago

We do have a unit test for this.

https://github.com/cornell-zhang/heterocl/blob/master/heterocl/tests/test_schedule.py

Nonetheless, we will make it more complete in the future.

seanlatias commented 6 years ago

It is similar to transpose. It's a good idea to directly take in a list of integers.