Docs · Memory expansion
How memory expansion is built
Memory expansion lets a kernel work on a vector larger than device memory. The vector is cut into pages, each page is a CTE blob, and each GPU keeps one cache of pages in device memory that every block of the kernel shares.
- Source
- context-transfer-engine/adapter/gpu_vector
- Backends
- CUDA, SYCL, CPU
- Page
- one CTE blob
Host side and device side
The work is split in two. The host side creates the vector, makes every allocation, and gives the kernel a device view. A kernel cannot allocate anything, so all memory a kernel will ever touch is sized before launch. The device view is the only thing the kernel sees.
Pages
The vector is cut into fixed-size pages. Page N is stored as a blob named N, in decimal, inside the vector's CTE tag. Pages therefore get every CTE property for free: placement across tiers, persistence, and the chain of modules. Any block of a kernel may touch any page; the vector does not divide pages among blocks.
How a vector is laid out
The page cache
Each GPU has one cache per vector, and every block of the kernel uses it, so a page that many blocks read is stored and transferred once. It is set-associative: a page's home set is a hash of its page number, and finding a page or claiming a slot for it happens under that set's lock. Every public call is block-collective: all threads of the block make it together.
- Slots and regions
- A slot is a 64-byte tag that points to a memory region only while it holds a page. Regions are handed out from per-block free lists, and a block whose list is empty takes one from another block's. Making the cache more associative therefore costs extra tags, not extra pages of memory.
- Pins
- A fetch pins every page it names, and the pin lasts until the kernel calls
UnpinRange. A hold only resolves a pointer into the pinned frame. A set full of pinned frames makes the next fetch yield and retry. - Eviction
- A freshly fetched page starts at eviction rank 1.0, and a kernel can rescore it; a higher rank means keep it longer. The victim is the unpinned frame with no transfer in flight and the lowest rank, oldest first among equals.
- Fetch
- A kernel brings pages in with a begin/await pair, so it can start a fetch and keep computing while the pages arrive.
- Flush
- There is no dirty bit. A kernel writes back the ranges it changed with a flush, and eviction never writes anything back, so a page must be flushed before it is unpinned.
Fetch, hold and flush
Prefetch hints
The prefetcher does not copy pages into the GPU cache; only the kernel does that. Instead it uses the state of yielding blocks to predict which pages are next and sends tier hints through the CTE's bulk rescore call, so those blobs move to a faster tier before the kernel asks for them.
Where missing data comes from
A fetch of a page that has no blob yet does not fail. If the vector's tag has a fault handler, the CTE asks it to produce the page: the CAE does this for data assimilated by reference, and the checkpoint module does it for a lazy Copy of another vector. That is how a file larger than memory can be opened as a vector without staging it first. With no handler, the CTE creates the blob and the page reads as zeros.
Backends
The adapter has CUDA, SYCL and CPU backends; adapter/cpu_vector provides the same model on host threads. Communication timing can be compiled in with the opt-in GV_COMM_TIMING build flag.
Tradeoffs
| Choice | Gain | Cost |
|---|---|---|
| Host owns all allocation | No allocator in kernels; memory use is known at launch | Cache size is fixed for the run |
| One cache shared by every block | A page many blocks read is stored and moved once | Set locks; a set full of pinned frames stalls fetches |
| Pages as CTE blobs | Tiering, persistence and faulting come from the CTE | Each miss is a runtime round trip |