Skip to content

Conversation

@Lunderberg
Copy link
Contributor

This PR replace the AllocateNode::extents variable, which represented the logical N-d shape of the tensor, with a 1-d AllocateNode::extent variable representing the amount of memory to be allocated. This is part of a larger push to support more flexible memory layouts across multiple device types, and to introduce a split between the physical layout in memory and the logical layout in a tensor or a compute definition.

The commits of this PR are divided up into discrete sections to hopefully make it easier to review.

  1. Change AllocateNode::extents (plural) to AllocateNode::extent (singular). This first commit is the motivation for the PR, and the remaining commits are the additional changes needed to be compatible with this first change.

  2. C++ changes necessary to compile against the new AllocateNode definition.

  3. A functionality addition to IRBuilder to output BufferRealize/BufferLoad/BufferStore nodes, in addition to Allocate/Load/Store. This minimizes the changes that will be needed in the unit tests, as they can continue using N-d indices and allocations with BufferRealize/BufferLoad/BufferStore, which are then flattened during the StorageFlatten pass.

  4. Update topi schedules to use 1-d extent.

  5. Update python unittests to use 1-d extent.

  6. Simplify() call added to workspace size calculation, needed for the workspace calculation unit tests.

  7. Updated UnrollLoop to count BufferStore in addition to Store. This resolves a breakage in the tests for unroll loop, and allows UnrollLoop to be used either before or after StorageFlatten.

  8. Refactor of the tests for unroll loop. Done as part of the investigation for previous point, but kept as an independent commit for readability.

@Lunderberg
Copy link
Contributor Author

@csullivan @tmoreau89

@tmoreau89
Copy link
Contributor

CC @kparzysz-quic

@Lunderberg
Copy link
Contributor Author

I've started a PR for an RFC that describes the motivation for this change in more detail. This change to AllocateNode::extent is listed under the "Impacted TIR Nodes" section.

@Lunderberg
Copy link
Contributor Author

Updated to resolve conflicts with main, change [size] to size in a unittest that I had missed the first time around.

@Lunderberg Lunderberg force-pushed the allocate_node_1d branch 2 times, most recently from 756ce1d to 73a854d Compare October 12, 2021 16:42
This commit has the primary goal of the PR, replacing the
AllocateNode::extents variable, which represented the N-d shape of the
tensor, with a 1-d AllocateNode::extent variable representing the
amount of memory to be allocated.  This is part of a larger push to
support more flexible memory layouts across multiple device types, and
to introduce a split between the physical layout in memory and the
logical layout in a tensor or a compute definition.
After updating to a 1-d index in AllocateNode::extent, this commit
adds all the secondary changes needed elsewhere in the codebase to be
compatible with the 1-d extent.
Allow the IRBuilder to output BufferRealize/BufferLoad/BufferStore
nodes, as well as Load/Store.  This minimizes the changes that will be
needed in the unit tests, as they can continue using N-d indices and
allocations, which are then flattened during the `StorageFlatten`
pass.
@Lunderberg Lunderberg force-pushed the allocate_node_1d branch 2 times, most recently from 0e294bf to b12082d Compare October 13, 2021 16:59
Some of the updated unit tests express allocation size as a product
rather than as a single integer, for readability, but those products
should still be treated as constant integers when determining the
workspace size needed.
If UnrollLoop is applied before StorageFlatten, there may be
BufferLoad/BufferStore nodes that haven't yet been lowered to
Load/Store nodes.  These should be counted equivalently to Store
nodes.
These changes were not necessary for the UnrollLoop change in the
previous commit to function, but were made as part of that
investigation.  They are kept as a separate commit in the PR for ease
of review.
Previous test of CopyOnWrite semantics during StmtMutator relied on
AllocateNode having an array parameter.  Rewrote these tests to check
the same behavior, but implemented over SeqStmtNode instead.
@Lunderberg
Copy link
Contributor Author

Updated to resolve breaks this caused in ethos unit tests.

Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Oct 22, 2021
Currently in PR at apache#9194, waiting on
RFC apache/tvm-rfcs#40.

Locally, this is a merge commit for the 'allocate_node_1d', to help me
keep track of which commits belong in which PRs.
@Lunderberg
Copy link
Contributor Author

Closing this PR, as changes resulting from discussion on apache/tvm-rfcs#39 has made this change no longer desirable.

@Lunderberg Lunderberg closed this Oct 28, 2021
@Lunderberg Lunderberg deleted the allocate_node_1d branch February 16, 2022 17:44
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.

2 participants