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] Generalized HexagonBuffer::CopyTo/CopyFrom #10878

Merged
merged 5 commits into from
Apr 5, 2022

Conversation

Lunderberg
Copy link
Contributor

This changes the HexagonBuffer::CopyTo and HexagonBuffer::CopyFrom functions to operate on the allocation regions in a HexagonBuffer, rather than referencing the managed allocation owned by a buffer, and to handle copies between two sets of possibly discontiguous regions. This will be necessary to handle discontiguous buffers that cannot be statically planned at compile-time, such as user-initiated allocations, within a shared memory pool.

Contiguous regions of memory are recognized and result in a single DMA call.

This change operates on the allocation regions in a `HexagonBuffer`,
rather than referencing the managed allocation owned by a buffer,
handling copies between two sets of possibly discontiguous regions.
This will be necessary to handle discontiguous buffers that cannot be
statically planned at compile-time, such as user-initiated
allocations, within a shared memory pool.

Contiguous regions of memory are recognized and result in a single DMA
call.
Copy between 3-region buffers and 4-region buffers is now allowed.
@Lunderberg Lunderberg requested a review from csullivan April 4, 2022 19:28
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 really great! One quick CR below, and unfortunately I'll have to finish the review tomorrow as I've run out of time today.

src/runtime/hexagon/hexagon/hexagon_buffer.cc Outdated Show resolved Hide resolved
Comment on lines +261 to 276
void hexagon_buffer_copy_across_regions(const BufferSet& dest, const BufferSet& src,
size_t bytes_to_copy) {
// First, determine all copies that do not cross boundaries in
// either source or destination region.
auto micro_copies = BufferSet::MemoryCopies(dest, src, bytes_to_copy);

// If regions are contiguously allocated, we can reduce the number
// of copies required by merging adjacent copies.
auto macro_copies = MemoryCopy::MergeAdjacent(std::move(micro_copies));

// Finally, do the memory copies.
for (const auto& copy : macro_copies) {
int error_code = hexagon_user_dma_1d_sync(copy.dest, copy.src, copy.num_bytes);
CHECK_EQ(error_code, 0);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@Lunderberg Lunderberg merged commit 6dada80 into apache:main Apr 5, 2022
@Lunderberg Lunderberg deleted the hexagon_buffer_copy branch April 5, 2022 20:30
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
* [Hexagon] Generalized HexagonBuffer::CopyTo/CopyFrom

This change operates on the allocation regions in a `HexagonBuffer`,
rather than referencing the managed allocation owned by a buffer,
handling copies between two sets of possibly discontiguous regions.
This will be necessary to handle discontiguous buffers that cannot be
statically planned at compile-time, such as user-initiated
allocations, within a shared memory pool.

Contiguous regions of memory are recognized and result in a single DMA
call.
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Apr 11, 2022
* [Hexagon] Generalized HexagonBuffer::CopyTo/CopyFrom

This change operates on the allocation regions in a `HexagonBuffer`,
rather than referencing the managed allocation owned by a buffer,
handling copies between two sets of possibly discontiguous regions.
This will be necessary to handle discontiguous buffers that cannot be
statically planned at compile-time, such as user-initiated
allocations, within a shared memory pool.

Contiguous regions of memory are recognized and result in a single DMA
call.
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
* [Hexagon] Generalized HexagonBuffer::CopyTo/CopyFrom

This change operates on the allocation regions in a `HexagonBuffer`,
rather than referencing the managed allocation owned by a buffer,
handling copies between two sets of possibly discontiguous regions.
This will be necessary to handle discontiguous buffers that cannot be
statically planned at compile-time, such as user-initiated
allocations, within a shared memory pool.

Contiguous regions of memory are recognized and result in a single DMA
call.
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