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

[TIR][Compute-at] Utilize InverseAffineIterMap for dom estimation #14184

Conversation

wrongtest-intellif
Copy link
Contributor

In compute-at primitive currently, when estimate iteration domain to cover required buffer region, we use limited heuristic rules. The change try to improve using existing arith tool InverseAffineIterMap. Then theoretically, all single buffer access which is of bijective mapping from block iter vars are solvable.

A new test case describe that if a block represents arbitary transpose/reshape ops, compute-at this block would always expect to success.

@T.prim_func
def NCHW16c_to_NCHW8c(A: T.Buffer((1, 3, 5, 5, 16), "float32"), C: T.Buffer((1, 6, 5, 5, 8), "float32")):
    B = T.alloc_buffer((1, 3, 5, 5, 16))
    for i0, i1, i2, i3, i4 in T.grid(1, 3, 5, 5, 16):
        with T.block("compute"):
             v_i0, v_i1, v_i2, v_i3, v_i4 = T.axis.remap("SSSSS", [i0, i1, i2, i3, i4])
             B[v_i0, v_i1, v_i2, v_i3, v_i4] = A[v_i0, v_i1, v_i2, v_i3, v_i4] + T.float32(1)
    for ax0, ax1, ax2, ax3, ax4 in T.grid(1, 6, 5, 5, 8):
        with T.block("T_layout_trans"):
            v_ax0, v_ax1, v_ax2, v_ax3, v_ax4 = T.axis.remap("SSSSS", [ax0, ax1, ax2, ax3, ax4])
            C[v_ax0, v_ax1, v_ax2, v_ax3, v_ax4] = B[v_ax0, (v_ax1 * 8 + v_ax4) // 16, v_ax2, v_ax3, (v_ax1 * 8 + v_ax4) % 16]

Also fix one issue when the iter scale is -1.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Mar 3, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@wrongtest-intellif wrongtest-intellif changed the title [TIR][Compute-at] Utilize inverse iter map tool for compute_at iter region estimation [TIR][Compute-at] Utilize inverse iter map for compute_at dom estimation Mar 3, 2023
@wrongtest-intellif wrongtest-intellif changed the title [TIR][Compute-at] Utilize inverse iter map for compute_at dom estimation [TIR][Compute-at] Utilize InverseAffineIterMap for compute_at dom estimation Mar 3, 2023
@wrongtest-intellif wrongtest-intellif changed the title [TIR][Compute-at] Utilize InverseAffineIterMap for compute_at dom estimation [TIR][Compute-at] Utilize InverseAffineIterMap for dom estimation Mar 3, 2023
Copy link
Member

@yzh119 yzh119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @wrongtest-intellif for the PR, it helps addresses some of the issues we met when tensorize workloads with mma.

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

Successfully merging this pull request may close these issues.

4 participants