Skip to content

Fix make_buffer_copy unfoldable gap after skipped extent-1 dimensions - #9681

Open
derek-gerstmann wants to merge 1 commit into
mainfrom
dg/fix_make_buffer_copy
Open

derek-gerstmann wants to merge 1 commit into
mainfrom
dg/fix_make_buffer_copy

Conversation

@derek-gerstmann

Copy link
Copy Markdown
Contributor

Issue

make_buffer_copy() in src/runtime/device_buffer_utils.h skips extent-1 dimensions, but previously bounded both the sorted insertion search loop and the element-shift loop by the source dimension index i instead of the number of dimensions inserted so far. When an extent-1 dimension preceded a non-trivial dimension, an unused {extent = 1, stride = 0} slot remained at position 0 (or between inserted dimensions), preventing the contiguous-dimension folding loop (chunk_size == src_stride_bytes[0] && chunk_size == dst_stride_bytes[0]) from coalescing dense copies into a single chunk.

Changes

  • src/runtime/device_buffer_utils.h:
    • Track the count of inserted non-trivial dimensions (inserted) in make_buffer_copy().
    • Compute copy_extent = min(src->dim[i].extent, dst->dim[i].extent) and skip dimensions where copy_extent == 1.
    • Bound the insertion search loop (insert < inserted) and shift loop (j = inserted; j > insert; j--) by inserted rather than i.
  • test/runtime/device_buffer_utils.cpp:
    • Add regression tests covering dense buffers with leading, interior, and transposed extent-1 dimensions, strided buffers with skipped extent-1 dimensions, and overlapping crop copies with extent-1 dimensions.
  • test/performance/device_copy.cpp:
    • Add benchmark shapes with a leading extent-1 dimension ({1, 1024, 1024, 6}).

Fixes #9563

Breaking changes

None.

Checklist

  • Tests added or updated (not required for docs, CI config, or typo fixes)
  • Documentation updated (if public API changed)
  • Python bindings updated (if public API changed)
  • Benchmarks are included here if the change is intended to affect performance.
  • Commits include AI attribution where applicable (see Code of Conduct)

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

…#9563)

Track the count of inserted non-trivial dimensions in make_buffer_copy() and use it to bound the sorted insertion search and shift loops, preventing skipped extent-1 dimensions from leaving unused {extent = 1, stride = 0} slots that block contiguous chunk folding.

Fixes #9563

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

make_buffer_copy leaves an unfoldable gap after skipped extent-1 dimensions

1 participant