cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
37 stars 15 forks source link

[Transform][ReuseAt] Update non-reduction loop iv expressions after setting new loop bound #183

Closed zzzDavid closed 9 months ago

zzzDavid commented 1 year ago

Summary

This issue is caused by reuse_at implementation on stride > 1 loops where the induction variable is also used in an if condition inside the loop body.

Explanation

The issue is that non-reduction loop's bound is updated, but the induction variable expressions are not. https://github.com/cornell-zhang/hcl-dialect/blob/f2f5e43a93173f9a86671c8f5004d5fb21cb329b/lib/Transforms/LoopTransformations.cpp#L1696-L1697

In binary convolution, we have a if_mac function that checks row and column axis to skip padding values. The expression looks like this:

iv * stride + reduction_iv * dilation >= padding_left
iv * stride + reduction_iv * dilation < padded_width - padding_right

And we have updated the induction variable as:

new_iv = iv * stride + reuse_distance

which means

iv = (new_iv - reuse_distance) / stride

Therefore, we just need to replace all iv with (new_iv - reuse_distance) / stride.

zzzDavid commented 1 year ago

I will add the HeteroCL program test after this PR is merged

chhzh123 commented 1 year ago

Any updates on this PR? It also requires rebasing to enable the latest CI.

chhzh123 commented 9 months ago

@zzzDavid Can this PR be merged?