-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[TensorIR][PASS][M1c] CompactBufferAllocation #7923
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -560,3 +560,53 @@ def PlanAndUpdateBufferAllocationLocation(): | |
| The result pass | ||
| """ | ||
| return _ffi_api.PlanAndUpdateBufferAllocationLocation() | ||
|
|
||
|
|
||
| def ConvertBlocksToOpaque(): | ||
| """Substitute all the block vars with the PrimExprs they are bound to, indicated by | ||
| the corresponding iter_values in BlockRealize, and then convert the blocks into | ||
| opaque ones by removing all the iter_values in BlockRealize and iter_vars in Block. | ||
|
|
||
| Returns | ||
| ------- | ||
| fpass : tvm.transform.Pass | ||
| The result pass | ||
| """ | ||
| return _ffi_api.ConvertBlocksToOpaque() | ||
|
|
||
|
|
||
| def CompactBufferAllocation(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So,is this pass doing the same job as InferBound?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the functionality should be similar, except that infer bound needs to walk through the schedule tree, while in this case the split/reorder already updated the index, so the impl should be simpler
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for explaination! |
||
| """Compact the buffer access region. by removing the buffer regions that are not accessed, | ||
| i.e. narrowing the buffer shape and adjust the access region if necessary. | ||
|
|
||
| Example | ||
| ------- | ||
| Before narrowing, `B` is a `[16, 16]` buffer, but only a skinny vector `B[i, 0:16]` is accessed. | ||
| .. code-block:: python | ||
|
|
||
| for i in range(0, 16): | ||
| with tir.block([]): | ||
| B = tir.alloc_buffer(16, 16) | ||
| for j in range(0, 16): | ||
| B[i, j] = A[i, j] + 1 | ||
| for j in range(0, 16): | ||
| C[i, j] = B[i, j] + 1 | ||
| This pass narrows the buffer shape and adjust its accessed region accordingly. | ||
| In this particular case, because only a `1 * 16` vector of `B` is accessed, | ||
| the pass narrows `B` to shape `[1, 16]`, and changes the access to `B[i, j]` to `B[0, j]`. | ||
| .. code-block:: python | ||
|
|
||
| for i in range(0, 16): | ||
| with tir.block([]): | ||
| B = tir.alloc_buffer(1, 16) | ||
| for j in range(0, 16): | ||
| B[0, j] = A[i, j] + 1 | ||
| for j in range(0, 16): | ||
| C[i, j] = B[0, j] + 1 | ||
|
|
||
| Returns | ||
| ------- | ||
| fpass : tvm.transform.Pass | ||
| The result pass | ||
| """ | ||
| return _ffi_api.CompactBufferAllocation() | ||
Uh oh!
There was an error while loading. Please reload this page.