mstar.utils.h2d#
Copy-only host-to-device staging, for work that runs beside a live CUDA graph.
Pre-planning builds step N+1’s small tensors on the plan stream while step N’s
graph replays. Any SM work it issues (a kernel, a fill_, a D2D copy) slows
the graph; H2D copies and event waits do not. So host values go to the device
in ONE copy from pinned memory (PinnedStager), padding written on the host,
never via a device-side staging tensor. An H2DMirror skips re-copying
values a destination already holds, as in a steady decode batch.
Classes
What the stager last copied into one device destination. |
|
|
A small ring of persistent pinned buffers for one dtype. |
- class mstar.utils.h2d.H2DMirror[source]#
Bases:
objectWhat the stager last copied into one device destination.
Lets
PinnedStager.copy_skip a copy whose values the destination already holds. Only sound for a destination nothing but that stager writes, and that lives as long as its mirror – hence an object the owner keeps with it, not a cache keyed by address (the allocator reuses addresses).
- class mstar.utils.h2d.PinnedStager(dtype, numel=256, depth=8)[source]#
Bases:
objectA small ring of persistent pinned buffers for one dtype.
copy_writes values into the next buffer and issues one non-blocking H2D copy from it on the current stream. Each buffer records an event after its copy and is not rewritten until that event has completed, so a copy still in flight never sees its source change. Thread-safe: the plan thread and the GPU thread may share one.- Parameters:
dtype (torch.dtype)
numel (int)
depth (int)
- copy_(dst, values, pad_value=None, mirror=None)[source]#
dst[:len(values)] = valuesin one non-blocking H2D copy.With
pad_value, the rest ofdstis set to it by the same copy (the padding is written on the host), sodstis fully overwritten without a device-side fill.dstmust be contiguous.With
mirror(dst’s, seeH2DMirror), nothing is issued whendstalready holds exactly this: the copy that put it there is ahead of anything that readsdstafter this call.