Skip to content

[Codegen] Support broadcast op with symbolic shape#3389

Merged
yzhliu merged 10 commits into
apache:masterfrom
yzhliu:bcast_buffer
Jul 2, 2019
Merged

[Codegen] Support broadcast op with symbolic shape#3389
yzhliu merged 10 commits into
apache:masterfrom
yzhliu:bcast_buffer

Conversation

@yzhliu

@yzhliu yzhliu commented Jun 18, 2019

Copy link
Copy Markdown
Member

@junrushao junrushao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@tqchen tqchen added the status: need RFC need RFC discussion label Jun 18, 2019
@tqchen

tqchen commented Jun 18, 2019

Copy link
Copy Markdown
Member

Thanks for the RFC, I like the idea. Sorry that I didn't get enough time to comment specifically about the behavior, can you please open an RFC issue? So we can discuss it a bit more.

The things to be improved are

  • Document the behavior independent of arg_binder.
    • Maps buffer[i][j][k] -> buffer[i][0][k] if dimension i's shape equals 0
  • Debate on the name (auto broadcast?), enum vs string as type key
  • Discuss how would the behavior affect topi implementation of broadcast and reduce ops
  • Think about alternative implementations
    • Do we have to introduce stride?
    • e.g. j -> min(j, shape[ndim])
    • j -> j * scale(scale = 0 or 1)

@junrushao

Copy link
Copy Markdown
Member
  • Do we have to introduce stride?
  • e.g. j -> min(j, shape[ndim])
  • j -> j * scale(scale = 0 or 1)

I do think it is proper to introduce stride. First, as far as we could see, using strides does not seem to have too much overhead, compared with other workarounds. Second, it seems to pave ways for other possible hacks to the buffer.

@junrushao

Copy link
Copy Markdown
Member

@were Could you review this PR?

@were

were commented Jun 28, 2019

Copy link
Copy Markdown
Contributor

LGTM, too.

@yzhliu yzhliu added status: need review and removed status: need RFC need RFC discussion labels Jun 30, 2019
@yzhliu

yzhliu commented Jul 1, 2019

Copy link
Copy Markdown
Member Author

@tqchen modified per suggestion.

Comment thread python/tvm/api.py Outdated
auto_broadcast buffer allows one to implement broadcast computation
without considering whether dimension size equals to one.
TVM will insert `strides[i] = shape[i] == 1 ? 0 : strides[i]` during arg binding.
See src/pass/arg_binder.cc for reference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let us avoid refer to c++ code in the python side, would be great if python doc can stand by itself

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

addressed

@yzhliu yzhliu merged commit 0af5c21 into apache:master Jul 2, 2019
@yzhliu

yzhliu commented Jul 2, 2019

Copy link
Copy Markdown
Member Author

Thanks @tqchen @junrushao1994 @were for review.

wweic pushed a commit to wweic/tvm that referenced this pull request Jul 11, 2019
* [Codegen] Support broadcast op with symbolic shape

* fix case where last dim = 1

* use enum; simplify stride calculation; improve doc

* fix lint

* improve py doc
wweic pushed a commit to wweic/tvm that referenced this pull request Jul 11, 2019
* [Codegen] Support broadcast op with symbolic shape

* fix case where last dim = 1

* use enum; simplify stride calculation; improve doc

* fix lint

* improve py doc
wweic pushed a commit to neo-ai/tvm that referenced this pull request Jul 11, 2019
* [Codegen] Support broadcast op with symbolic shape

* fix case where last dim = 1

* use enum; simplify stride calculation; improve doc

* fix lint

* improve py doc
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.

4 participants