cuda.core.utils.copy_batch#
- cuda.core.utils.copy_batch(Stream stream: Stream, srcs: Sequence[Buffer], dsts: Sequence[Buffer], *, options: CopyOptions | Sequence[CopyOptions] | None = None) None#
Copy a batch of buffers asynchronously.
Source buffer and destination buffer sizes must match. For a single buffer, use
Buffer.copy_to()orBuffer.copy_from().The driver provides no graph-node form of
cuMemcpyBatchAsync, so this cannot be captured into a graph. Both passing aGraphBuilderand passing its underlyingstreamwhile capture is active are rejected. Build graph copies withgraph.GraphNode.memcpy()or per-bufferBuffer.copy_to().- Parameters:
stream (
Stream) – Stream for the asynchronous copy. First positional and required (mirrorslaunch()). Does not accept a capturing stream (including aGraphBuilder’s underlying stream); usegraph.GraphNode.memcpy()or per-bufferBuffer.copy_to()to build copies into a graph.srcs (Sequence[
Buffer]) – Source buffers. Must be a sequence, not a single Buffer.dsts (Sequence[
Buffer]) – Destination buffers. Must matchlen(srcs).options (
CopyOptions| Sequence[CopyOptions] | None) – Per-copy options. A single value applies to every copy; a sequence pairs by index and must matchlen(srcs).Noneuses stream-ordered defaults.
- Raises:
ValueError – If lengths or sizes mismatch.
TypeError – If a single Buffer is passed instead of a sequence, if a default-stream token (
LEGACY_DEFAULT_STREAM/PER_THREAD_DEFAULT_STREAM) is passed, or if the stream is currently in graph capture mode.
Notes
Batching through
cuMemcpyBatchAsyncrequires all three of:cuda.corebuilt against CUDA 13 headers,cuda.bindings13.0 or newer, and a driver reporting CUDA 13.0 or newer (cuDriverGetVersion() >= 13000).cuda.bindingsbinds only the CUDA 13.0 revision of the entry point, so a driver that predates it is refused even where it implements the earlier CUDA 12.8 signature.The driver may execute batch items concurrently and in any order. A batch must therefore not contain copies where the source range of one copy overlaps the destination range of another; such aliasing produces undefined results. Detecting overlaps at runtime is impractical; callers are responsible for ensuring no aliasing exists.
On pre-CUDA 13 installs the copies fall back to a Python-level loop over
cuMemcpyAsync, so the potential performance benefit of asynchronous batched copies is not realized.CopyOptionsare silently ignored on the fallback path.