bfhp: pre-zero quantized padding in loader; add --gpu-host-import flag#9
Open
doctorjei wants to merge 3 commits into
Open
bfhp: pre-zero quantized padding in loader; add --gpu-host-import flag#9doctorjei wants to merge 3 commits into
doctorjei wants to merge 3 commits into
Conversation
added 3 commits
April 25, 2026 23:14
bfhp = buffer from host pointer. First commit to add support for the flag; implementation to follow.
When bfhp is active, add zero-fill protection; collapses to no-op when it is known that pages are already "clean".
Activated more nuanced zero-fill to avoid penalty when zero-fill is already known (e.g., hugepages)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fix-forward for 4b95731 (merged as a9f3521). The earlier review-feedback commit moved padding-zeroing for external (bfhp) buffers from GPU cudaMemset to host-side memset through ctx->host_ptr, but assumption of writability doesn't always hold; it's fine for --hugepages (PROT_RW during load, PROT_R after) but not for file-mmap (PROT_R from the start) — resulting in SIGSEGV on any non-hugepages model load with bfhp active (yikes).
This Fix
Moves zero-pass into loader (where mapping writability / lifetime are known), removes unsafe host-memset from ggml-cuda.cu, and adds --gpu-host-import flag so users can opt out (or explicitly opt in) for non-hugepages mmap loads.
The fix is broken into 3 commits for readability:
adds GPU host import switch (bfhp) — Pure plumbing; --gpu-host-import / --no-gpu-host-import CLI flags (env LLAMA_ARG_GPU_HOST_IMPORT), and common→model wiring. No behavioral change on its own.
adds zero-fill protection for buffers from host pages in model loader. (walks tensors backed by mapping idx zeros out slide in host mapping. Early-returns for hugetlb mappings (kernel already zero-fills anon allocation). For file-mmap, does a scoped mprotect(PROT_RW) → memset → restore.
streamlines zero-fill to avoid regression — init_tensor no longer host-memsets external buffers (now in loader), so external branch collapses to a no-op and surviving cudaMemset only runs for owned device buffers. Replaces the four NULL vtable slots imported buffer interface with GGML_ABORT wrappers.
Results (Benchmarks)
73a6481--no-gpu-host-import--gpu-host-import--hugepages(AUTO ⇒ on)Considerations
The
--gpu-host-importand--no-gpu-host-importflags were added because, at the moment, host import is only performant with the hugepages implementation. However, it is likely that this solution could be extended to solve problems with other architectures, and there may be cases were a user or developer may need or want to use imported host pages without hugepages.Due to the performance issue of bfhp without hugepages, the
AUTOsetting for bfhp defaults to match hugepages - on or off together.