A Managed buffer's pages that a guest RAM's chunk imports hold are copied in by the GPU from them

What: a Managed no-copy buffer on a device without unified memory can have
a host copy that is its pages alone, because its own import would map pages
a live import holds or the device refused it. Where a guest RAM's chunk
imports hold all of those pages, it now keeps the pieces of those imports
(host_ram.rs RamOnDevice::pieces_of, ChunkPiece). The caller's resolver is
still asked once: its answer is kept for the pieces.
- Its copies in (as it is made, at a rebind, and each range
  did_modify_range names under AtSubmission) are GPU copies from those
  imports' VkBuffers, one per piece. They are held as a host copy
  (Keeps::HostCopy): nothing is staged, no bound applies, no submission is
  made. AtCommit still stages a named range on the CPU at the commit.
- New public WorkCounts, so a pass can tell the paths apart:
  - managed_bytes_staged_in, the bytes the CPU staged for copies in;
  - managed_bytes_copied_in_from_ram;
  - managed_pages_alone_refused, managed_pages_alone_over_imports and
    managed_pages_alone_unwritable, why a host copy is its pages alone;
  - managed_pages_in_ram_chunks.
- Tests: tests/host_ram_managed.rs, a buffer across a chunk's end with
  both chunks imported, under both policies. It checks the counts (pages
  alone over imports, held by the chunks, nothing imported, gate unasked),
  the bytes the GPU reads as the buffer is made and after a named CPU
  write across the end, and which path copied them.
- Docs: managed_copy.rs, managed.rs, buffer.rs, HostMemory::with_runs,
  docs/API.md, and FAST-PATHS row 51. Signatures blessed.

Why: such pages were staged by the CPU at every commit that took a named
range. That is a CPU copy and staging memory, on the commit's thread, for
bytes the device already maps through the chunk imports. Zero copy first.

Verified: not run at this commit. The 2080 equality tests and the bench
(before at the bench commit, after here) and lint follow on the rebased
branch.
This commit is contained in:
Anees Iqbal committed 2026-11-13 01:56:44 -08:00
1 parent 0ab26709c9
commit 2d98657ca8
11 files changed
+441 -36

No files matched your search

+5 -2
View File
@@ -551,9 +551,12 @@ copies) read the bytes at the commit. `ManagedCopyInPolicy::AtCommit`, which `ex
selects, takes the 5300M's answer: the commit copies each range on the CPU into staging buffers
of host-cached system memory, a cost of the range's bytes, and a write after it reaches no
command buffer committed before it, however late the GPU reaches it (docs/FAST-PATHS.md). Pages
no import maps are staged so at the commit under either. A CPU write that no `did_modify_range` names is not seen by the GPU. A blit encoder's `synchronize_resource` copies the GPU's copy out to the pages in its
no import of their own maps are staged so at the commit under either, but where a guest RAM's
chunk imports hold them all (`HostRam`): there the default copies them by the GPU from those
imports, as from an import of their own (`WorkCounts::managed_bytes_copied_in_from_ram`). A CPU write that no `did_modify_range` names is not seen by the GPU. A blit encoder's `synchronize_resource` copies the GPU's copy out to the pages in its
command buffer's order, which the CPU sees once the command buffer completed. The copies run
from an import of the pages where the device makes one (never a copy of them), else through
from an import of the pages where the device makes one (never a copy of them), or from the
chunk imports of a guest RAM that hold them, else through
staging buffers the runtime frees once their work completed, at most 256 MiB staged ahead
(`WorkCounts::managed_*`). A texture over the buffer's bytes is over the GPU's copy and follows
it, its `replace_region` copying in and its `synchronize_resource` or `synchronize_texture`