Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

docs(vulkan): staged uploads straight from host memory, COLI_VK_UP_IMPORT and the import fault point

JustVuggaf99bcf3800b
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
index b32b3de9..6d16d219 100644
--- a/docs/ENVIRONMENT.md
+++ b/docs/ENVIRONMENT.md
@@ -229,7 +229,8 @@ Per-drive byte counts are reported in a `MIRROR:` stats line. Combine with `DIRE
| `COLI_VK_GEMM_TILE` | measured | `bm,bn,bk,tm,tn[,pf]`: one tile for every width of the fp32 GEMM instead of the measured pair. Tuning only (`COLI_VK_TEST_GEMM_BENCH`). |
| `COLI_VK_COOP_TILE` | measured | `bm,bn,wm,wn,bk`: one tile for every width of the cooperative-matrix GEMM. Tuning only. |
| `COLI_VK_STAGED` | auto | Staged uploads: resident data (the weights, the expert tier, the MLA KV mirror, `COLI_VK_DEV2`'s experts) copied into device-local memory the host does not map, through a host staging buffer, instead of written through a mapping of the host-visible device-local memory. `1` on, `0` off. Unset: on when the host-visible device-local heap is under a quarter of the largest device-local heap, as on a discrete card without Resizable BAR (about 256 MB of 8 GB, where the mapped path fails or spills to system RAM); off on a card with Resizable BAR, an integrated GPU or Lavapipe. See [vulkan.md](vulkan.md#memory-placement-without-resizable-bar). |
-| `COLI_VK_STAGED_FAULT` | unset | Tests: `<point>[:n]` makes the n-th staged upload (the first by default) fail at `stage` (the staging buffer), `pwstage` (the KV mirror's), `block` (a device-local block), `kvbuf` (a KV mirror or norm-weight buffer), `record` (a command buffer's begin or end), `submit`, `wait` (a fence wait: the device is then lost) or `commit` (a tier expert's commit after its first matrix); a `[VK] COLI_VK_STAGED_FAULT` line says when it fired. |
+| `COLI_VK_STAGED_FAULT` | unset | Tests: `<point>[:n]` makes the n-th staged upload (the first by default) fail at `stage` (the staging buffer), `pwstage` (the KV mirror's), `block` (a device-local block), `kvbuf` (a KV mirror or norm-weight buffer), `record` (a command buffer's begin or end), `submit`, `wait` (a fence wait: the device is then lost), `commit` (a tier expert's commit after its first matrix) or `import` (an import of host memory, which is then staged); a `[VK] COLI_VK_STAGED_FAULT` line says when it fired. |
+| `COLI_VK_UP_IMPORT` | on | Staged uploads copy straight from host memory where the device has `VK_EXT_external_memory_host` (the source pages imported as a transfer source, no copy into the staging buffer). `0` stages every copy ([vulkan.md](vulkan.md#memory-placement-without-resizable-bar)). |
| `COLI_VK_HOST_VISIBLE_CAP_MB` | unset | Tests: treat the host-visible device-local heap as at most this many MiB in the `COLI_VK_STAGED` decision, so a device with Resizable BAR or unified memory takes the decision a card without it would (`246` emulates an RTX 3070 on its launch VBIOS). |
### The routed-expert tier (`vk_tier.c`, every MoE engine)
diff --git a/docs/vulkan.md b/docs/vulkan.md
index a27b6663..cd3061ea 100644
--- a/docs/vulkan.md
+++ b/docs/vulkan.md
@@ -2117,6 +2117,22 @@ first matrix. RADV places them in system RAM instead, where every access crosses
**Staged uploads** put resident data in a DEVICE_LOCAL memory type the host does not map
and copy it there from a host staging buffer with `vkCmdCopyBuffer`.
+**Straight from host memory.** Where the device has `VK_EXT_external_memory_host`, a
+staged upload skips the staging buffer: the source pages are imported as a transfer
+source and the device copies from them directly, so the CPU does not copy the bytes a
+second time. It applies to:
+- the tier's experts (and the streaming slots' refills), from the host image they are
+ converted in, which is allocated aligned to the device's import alignment;
+- the trunk's rows from the weights themselves, when they need no padding.
+
+An import lives until its command buffer's fence. Pages the driver will not import (some
+file-backed mappings, a refusal) are staged as before. The second device (`COLI_VK_DEV2`)
+does the same. `COLI_VK_UP_IMPORT=0` stages every copy; a `[VK] staged uploads: copied
+straight from host memory` line says imports are on, and the exit report counts the
+imported bytes and copies and the refused ones. On Lavapipe the results are the same bits
+either way. On a discrete card it removes a host copy of every uploaded byte, which matters
+most for the tier's warm start and the trunk's placement; its speed there was not measured.
+
**The rule** (`place_decide` in `backend_vulkan.c`). `COLI_VK_STAGED=1` stages,
`COLI_VK_STAGED=0` keeps the mapped path. Unset: staged when the host-visible
device-local heap holds less than a quarter of the largest device-local heap, or there is