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

[tvm][codegen] Make buffer auto broadcast independent to the order of input args #3956

Merged
merged 2 commits into from
Sep 16, 2019

Conversation

zhiics
Copy link
Member

@zhiics zhiics commented Sep 13, 2019

Currently auto_broadcast of buffer may cause a problem when it hoists the if guard, as the lifted expression may use the arg before it is defined through let binding.

For example, the following code will cause problems during codege, because we will have something like if (o1/x == 1) ... because o1 and x are bound.

    n0, m0, x = tvm.var('n0'), tvm.var('m0'), tvm.var('x')
    n1, m1 = tvm.var('n1'), tvm.var('m1')
    o0, o1 = tvm.var('o0'), tvm.var('o1')

    A = tvm.placeholder((m0, n0), name='A')
    B = tvm.placeholder((m1, n1), name='B')
    C = tvm.compute((o0, o1/x), lambda i, j: A[i, j] + B[i, j], name='C')

    Ab = tvm.decl_buffer(A.shape, A.dtype, name="Ab", buffer_type="auto_broadcast")
    Bb = tvm.decl_buffer(B.shape, B.dtype, name="Bb", buffer_type="auto_broadcast")
    Cc = tvm.decl_buffer(C.shape, C.dtype, name="Cc", buffer_type="auto_broadcast")
    s = tvm.create_schedule(C.op)

This fix hoist the let binding before the uses of the assert/if statements.

Another problem we might need to solve is the the current input arg can only be a single variable instead of an expression, i.e. A = tvm.placeholder((m/x, n), name='A') would fail, @yzhliu has also observed this. We can probably solve this in a follow-up PR. This PR will feed all these args directly in the build statement so that they can be correctly bound.

CC @yzhliu, @icemelon9, @tqchen

Copy link
Contributor

@cchung100m cchung100m left a comment

Choose a reason for hiding this comment

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

LGTM

src/pass/make_api.cc Outdated Show resolved Hide resolved
@icemelon icemelon merged commit 8577c81 into apache:master Sep 16, 2019
@icemelon
Copy link
Member

Thanks @zhiics

@zhiics zhiics deleted the auto_broadcast branch September 20, 2019 20:45
wweic pushed a commit to wweic/tvm that referenced this pull request Sep 30, 2019
… input args (apache#3956)

* [tvm][codegen] Make buffer auto broadcast independent to the order of the input arg

* fix indent
wweic pushed a commit to wweic/tvm that referenced this pull request Sep 30, 2019
… input args (apache#3956)

* [tvm][codegen] Make buffer auto broadcast independent to the order of the input arg

* fix indent
wweic pushed a commit to neo-ai/tvm that referenced this pull request Oct 1, 2019
… input args (apache#3956)

* [tvm][codegen] Make buffer auto broadcast independent to the order of the input arg

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

Successfully merging this pull request may close these issues.

5 participants