cuda.core: Add copy_batch to cuda.core.utils - #2593
Conversation
|
/ok to test fd58e8f |
|
/ok to test 9e14ce1 |
9e14ce1 to
fbf7572
Compare
|
/ok to test fbf7572 |
|
/ok to test da4a376 |
|
|
/ok to test b811960 |
b811960 to
44715f1
Compare
|
/ok to test 44715f1 |
Items 6, 8, and 9 are minor and can follow in a later change. |
Andy-Jost
left a comment
There was a problem hiding this comment.
Looks good in general. Requested changes are detailed in a separate comment.
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.