cuda.core: Add copy_batch to cuda.core.utils - #2593
Draft
juenglin wants to merge 2 commits into
Draft
Conversation
Contributor
Contributor
Author
|
/ok to test |
Contributor
@juenglin, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/ |
Contributor
Author
|
/ok to test fd58e8f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
copy_batchtocuda.core.utils, wrappingcuMemcpyBatchAsyncso a set oftransfers is issued in a single driver call. This is the P0 item of #1333; the P1
items (prefetch / discard / discard-prefetch) landed in #1775. Closes #1333.
Batched-only, mirroring the
*_batchfunctions from #1775: a loneBufferisrejected in favour of
Buffer.copy_to/Buffer.copy_from.Public API
New exports from
cuda.core.utils:copy_batch,CopyOptions,MemcpySrcAccessOrder,MemcpyOverlapMode. Nothing is added to top-levelcuda.core.CopyOptionsis a frozen dataclass mapping ontoCUmemcpyAttributes:src_access_order,src_location_hint,dst_location_hint,overlap_mode.options=Noneselects stream-ordered defaults.Behaviour
src.sizemust equaldst.size.Partial-buffer copies are out of scope.
CopyOptionsbroadcasts to every copy; a sequence pairs by index andmust match
len(srcs), otherwiseValueError. Non-defaultCopyOptionsrequireattrs/attrsIdxspair, soa broadcast reaches the driver as
numAttrs == 1instead of being repeated percopy.
cuda.bindingsor when using an older driver,copy_batchis emulated by a sequence ofcuMemcpyAsynccalls, consistent withprefetch_batch.GraphNode.memcpyfor graph copies.overlap_mode="prefer_overlap_with_compute"is a Tegra-only hint. On anon-integrated GPU the driver silently ignores it, so a
UserWarningis emittedand the copy proceeds with default behaviour.
Refactor to existing files
_coerce_batch_bufferswas duplicated between the new_copy_ops.pyxand_managed_memory_ops.pyx, so it now lives once as Buffer_coerce_batch in_buffer.pyx/_buffer.pxd, parameterized by the per-buffer API to suggest. That accounts for the changes to_buffer.*and_managed_memory_ops.pyx(no behaviour changes for the #1775 functions).Relation to the #1775 batched-API contract
Follows the contract on pairing, scalar broadcast,
ValueErroron length mismatch, and options as a frozen dataclass. Three deliberate deviations, which match what #1775 shippedrather than what that comment described:
copy()accepting one-or-many. Add managed-memory advise, prefetch, and discard-prefetch free functions #1775 shipped batch-only freefunctions with instance methods for N=1; this mirrors that split.
srcs/dstssequences rather than a sequence of pairs, matchingprefetch_batch(stream, buffers, locations).streamargument:cuMemcpyBatchAsynctakes oneCUstream, so thereis no per-copy stream array to mirror.
Tests
tests/memory/test_copy_batch.pycovers data movement — H2D, D2H, D2D, mixedsizes, agreement with sequential
Buffer.copy_to, stream ordering, and thegraph-capture rejection.
tests/memory/test_copy_batch_options.pycovers theoptions surface, the attribute run-length encoding, and every validation path.
Shared fixtures live in
tests/memory/conftest.py. The newexamples/batched_memcpy.pyis exercised by the existing example-test glob.