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

[Hexagon] Use single allocation to back 2-d arrays #10903

Merged
merged 2 commits into from
Apr 6, 2022

Conversation

Lunderberg
Copy link
Contributor

Currently, each allocation allocates an entire page, so even a relatively small number of allocations can use very large amounts of VTCM. This commit changes calls to AllocVtcmWorkspace of shape [N,M] from performing N allocations of size M, to 1 allocation of size N*M. Since N is usually much smaller than a page, this reduces the total amount of memory required.

This is an intermediate step, where the long-term solution is to use static planning for VTCM allocations. This returns the same void** type as the static planning eventually will, but avoids excess memory use in the meantime.

@Lunderberg
Copy link
Contributor Author

To maintain alignment of each individual region, padding may be added to the single allocation. As a result, this PR is dependent on functionality introduced in #10878

@Lunderberg
Copy link
Contributor Author

Current CI failures are the expected differences at the C++ side, which are resolved in #10878. No changes expected to be needed for them, but will need to relaunch CI once it lands.

[2022-04-05T16:42:41.580Z]  196 - HexagonBuffer.nd_copy_from (Failed)
[2022-04-05T16:42:41.580Z] 	198 - HexagonBuffer.2d_copy_from_1d (Failed)
[2022-04-05T16:42:41.580Z] 	199 - HexagonBuffer.1d_copy_from_2d (Failed)
[2022-04-05T16:42:41.580Z] 	201 - HexagonBuffer.nd_copy_from_nd_smaller_size (Failed)
[2022-04-05T16:42:41.580Z] 	202 - HexagonBuffer.md_copy_from_nd (Failed)

Currently, each allocation allocates an entire page, so even a
relatively small number of allocations can use very large amounts of
VTCM.  This commit changes calls to `AllocVtcmWorkspace` of shape
`[N,M]` from performing `N` allocations of size `M`, to 1 allocation
of size `N*M`.  Since `N` is usually much smaller than a page, this
reduces the total amount of memory required.

This is an intermediate step, where the long-term solution is to use
static planning for VTCM allocations.  This returns the same `void**`
type as the static planning eventually will, but avoids excess memory
use in the meantime.
Previously, when a single monolithic allocation is used to back a 2-d
Hexagon buffer of shape `[nallocs, nbytes_per_allocation]`, the
allocation itself is aligned, but each individual region is not.  This
commit ensures that each individual region also followed the alignment
specified.
@Lunderberg Lunderberg force-pushed the hexagon_buffer_single_alloc branch from 2db1475 to 42e6e85 Compare April 5, 2022 21:05
@Lunderberg
Copy link
Contributor Author

Rebased onto main to restart CI.

@Lunderberg Lunderberg marked this pull request as ready for review April 5, 2022 21:05
@Lunderberg Lunderberg requested a review from csullivan April 6, 2022 14:30
Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

This is a great way to handle separate allocations, thanks @Lunderberg

@csullivan csullivan merged commit 591a000 into apache:main Apr 6, 2022
@Lunderberg Lunderberg deleted the hexagon_buffer_single_alloc branch April 6, 2022 16:00
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
* [Hexagon] Use single allocation to back 2-d arrays

Currently, each allocation allocates an entire page, so even a
relatively small number of allocations can use very large amounts of
VTCM.  This commit changes calls to `AllocVtcmWorkspace` of shape
`[N,M]` from performing `N` allocations of size `M`, to 1 allocation
of size `N*M`.  Since `N` is usually much smaller than a page, this
reduces the total amount of memory required.

This is an intermediate step, where the long-term solution is to use
static planning for VTCM allocations.  This returns the same `void**`
type as the static planning eventually will, but avoids excess memory
use in the meantime.

* [Hexagon] Maintain alignment of allocations

Previously, when a single monolithic allocation is used to back a 2-d
Hexagon buffer of shape `[nallocs, nbytes_per_allocation]`, the
allocation itself is aligned, but each individual region is not.  This
commit ensures that each individual region also followed the alignment
specified.
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Apr 11, 2022
* [Hexagon] Use single allocation to back 2-d arrays

Currently, each allocation allocates an entire page, so even a
relatively small number of allocations can use very large amounts of
VTCM.  This commit changes calls to `AllocVtcmWorkspace` of shape
`[N,M]` from performing `N` allocations of size `M`, to 1 allocation
of size `N*M`.  Since `N` is usually much smaller than a page, this
reduces the total amount of memory required.

This is an intermediate step, where the long-term solution is to use
static planning for VTCM allocations.  This returns the same `void**`
type as the static planning eventually will, but avoids excess memory
use in the meantime.

* [Hexagon] Maintain alignment of allocations

Previously, when a single monolithic allocation is used to back a 2-d
Hexagon buffer of shape `[nallocs, nbytes_per_allocation]`, the
allocation itself is aligned, but each individual region is not.  This
commit ensures that each individual region also followed the alignment
specified.
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
* [Hexagon] Use single allocation to back 2-d arrays

Currently, each allocation allocates an entire page, so even a
relatively small number of allocations can use very large amounts of
VTCM.  This commit changes calls to `AllocVtcmWorkspace` of shape
`[N,M]` from performing `N` allocations of size `M`, to 1 allocation
of size `N*M`.  Since `N` is usually much smaller than a page, this
reduces the total amount of memory required.

This is an intermediate step, where the long-term solution is to use
static planning for VTCM allocations.  This returns the same `void**`
type as the static planning eventually will, but avoids excess memory
use in the meantime.

* [Hexagon] Maintain alignment of allocations

Previously, when a single monolithic allocation is used to back a 2-d
Hexagon buffer of shape `[nallocs, nbytes_per_allocation]`, the
allocation itself is aligned, but each individual region is not.  This
commit ensures that each individual region also followed the alignment
specified.
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
* [Hexagon] Use single allocation to back 2-d arrays

Currently, each allocation allocates an entire page, so even a
relatively small number of allocations can use very large amounts of
VTCM.  This commit changes calls to `AllocVtcmWorkspace` of shape
`[N,M]` from performing `N` allocations of size `M`, to 1 allocation
of size `N*M`.  Since `N` is usually much smaller than a page, this
reduces the total amount of memory required.

This is an intermediate step, where the long-term solution is to use
static planning for VTCM allocations.  This returns the same `void**`
type as the static planning eventually will, but avoids excess memory
use in the meantime.

* [Hexagon] Maintain alignment of allocations

Previously, when a single monolithic allocation is used to back a 2-d
Hexagon buffer of shape `[nallocs, nbytes_per_allocation]`, the
allocation itself is aligned, but each individual region is not.  This
commit ensures that each individual region also followed the alignment
specified.
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.

2 participants