Repository navigation
GPU: map the pipeline library's file instead of reading it into memory - #2129
0xkn0wh3r3 wants to merge 3 commits into
Conversation
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Pipeline library file mapped instead of read into memory — possible duplicate of #2132 (same pipeline-library mapping change); maintainer should pick one.
|
I opened #2132 for the same change four minutes after this one, without having seen it; I'm closing mine in favour of this PR, which also takes the save-time copy away. Three things from that work that may be useful here, from synthetic tests on Windows 11 (no GPU, no title):
AI-assisted (Claude Code). No game data was used. |
|
A pending save can replace a newer successful save at the next load. I reproduced this on Windows at
Follow-up on One tradeoff I verified: if the pending file itself is held without delete sharing, the new save returns an error and preserves the previous successful save. The old code reported success in that case but reopened the previous pending bytes anyway. These checks used one process; cross-process ordering and crash durability remain untested. |
|
Thanks, all three were useful. I've pushed 2ef0c75 for them:
Each new check was mutation-tested (the table is in the description). |
|
I ran the pipeline-library tests at 2ef0c75 on native Windows with D3D12 WARP. The suite returned 14 passed and one ignored measurement. I also extended the concurrent load test so it replaces the canonical file while the original library still owns its mapped view. A freshly opened library must load the newly added compute PSO, and the threads must still load the original PSOs from the old mapping. The extended suite passed with mapping enabled. When I deliberately republished the previous snapshot, the added assertion failed at the load of the new PSO with HRESULT 0x80070057. Optional regression test on your exact head. If you fold the test into your commit, please retain this trailer. Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com AI-assisted. Synthetic shaders only. |
|
Automated triage for the maintainers. Merge candidate (unchanged). The push since the last triage (
Optional, as before: the module doc and the share-mode comment cite run figures and the fork, which would sit better in the PR description. CI: passing ( Recommending a look, not approving. Generated by Claude Code |
|
Measured on an RTX 3070 with a 3,843 MB library (27,160 pipelines): read whole it is one 3,665 MB private allocation for the run, and AI-assisted. |
|
Thanks. Both points are fixed in 3294cf6.
@andrewpozdnakov7-jpg, thanks for the concurrent-replacement test. I'd rather keep it as your own commit. If the maintainer wants it in, it can go in as it is. @Slay326, thanks for the commit-charge numbers: 15.6 → 10.3 GB at start with no full rewrites is the effect I was after. |
…ng it into memory) into demo
The host pipeline library was read into a buffer at start and kept for the whole run, because the host reads the bytes a library was made from for as long as it lives; a save serialised the whole library into a second buffer and wrote it out. On fxceless/victory-fork a world run's library was 1,352 MB, all of it in the process's own memory; a save of a 1.7 GB library failing for lack of memory is what Marvisak#2007 handles. The file is now mapped: its pages are the file's, only those the host reads are in memory, and the system can drop them without writing them anywhere. A save serialises the library straight into a mapping of a uniquely named staging file and renames it over the library. The mapped file's handle stays open while it is mapped. A save renames over the file this run has mapped, and with the handle closed Windows gives up the old file's contents, so pages of the mapping not in memory then read as zeros, which the host would take for stored pipelines (the fork lost the device that way). Where a system refuses to replace a mapped file, the new library waits as `host-pipelines.next` and takes the old one's place at the next start. `VICTORY_LIBRARY_MAP=0` reads and writes through buffers, as before; that buffer, and the one used where a staging file cannot be mapped, is Marvisak#2007's fallible one, so a save the host has no memory for is still left for later instead of aborting. Ported from fxceless/victory-fork (commit 578d459): the mapping only, on top of upstream's concurrent loads, unique staging files and pre-build list (not that commit's other library changes). Tests: - `the_library_file_is_mapped_and_replaced`: a mapped file reads as its bytes; a save through a mapped staging file replaces the mapped library, the old mapping still reads the old bytes, the next start reads the new ones, the returned tag is the new bytes', no staging file is left, and a failed serialisation leaves the library as it was. - `a_replaced_library_file_still_reads_from_the_disk`: an 8 MiB file written past the system cache, mapped, then replaced by a save; every page still reads as the old file. With the handle closed it fails (page 16 reads zeros on an RTX 5070 Ti host). - `pipelines_load_on_many_threads_at_once` now opens its library from a mapped file. Co-authored-by: fxceless <36782933+fxceless@users.noreply.github.com>
…ns are removed The library's file was opened with the standard library's sharing (read, write and delete), so another process could write it in place or truncate it while the host reads the mapping. It is now opened sharing read and delete only: writing or truncating it fails with a sharing violation, while a save still renames the new library over it (delete sharing is what that needs; read-only sharing refuses the rename). A run that ended during a save left its staging file behind for good: the name carries the process ID, and the library's is as big as the library. A load now removes the staging files of our three files whose process has ended: no such process (only that refusal counts; denied access is a running process), or exited with only a handle left. Tests: - a_mapped_library_file_cannot_be_written_meanwhile - staging_names_give_their_process - staging_files_of_ended_runs_are_removed - library_file_memory (ignored measurement): 256 MiB file, 256.5 MiB private read into memory, 0.5 MiB mapped.
…g one A save renamed the new library over the library's file and wrote it to `host-pipelines.next` only when that rename failed; a later save whose rename worked left that older pending file in place, and the next start renamed it over the newer library (reported on the PR by Dathinel). Every save now goes to `host-pipelines.next` first and is renamed from there over the library's file, the step a start also takes. The pending file is therefore always the newest library saved, or not there: a save that replaces the library takes it along, and one that cannot is it. A pending file that cannot itself be replaced (held open without delete sharing) fails the save, which leaves the library saved before it for the next start. `staging_files_of_ended_runs_are_removed` no longer starts processes: an ID no process can have (IDs are multiples of four from a far smaller table) stands for an ended run, and this process and PID 4 for running ones. The case of an exited process whose handle is still held is no longer covered by a test. Tests: - `the_next_start_reads_the_library_saved_last`: the library held without delete sharing, two saves wait as the pending file (the second replacing the first); released, the next save replaces the library and leaves no pending file, and a start reads it. A held pending file fails the save and the start reads the one before. It fails on the previous code at the stale pending file.
3294cf6 to
7577fdb
Compare
With Marvisak#2907: the summary lines go through progress::say, and Marvisak#2951's time section follows them; the library save keeps Marvisak#2129's directory creation and staging files beside Marvisak#2951's timing.
The problem
The host pipeline library is read into memory at start and kept for the whole run: D3D12 reads the bytes a library was made from for as long as it lives. Each save then builds a second full-size copy to write out. Measured on fxceless/victory-fork, the library was 1,352 MB, all of it in the process's own memory.
The fix
Blob::Mapped). Only the pages D3D12 touches are in memory, and Windows can drop them without writing anything.host-pipelines.bin.tmp-*, and the early and pre-build lists' files) left by runs that ended during a save. A file is removed only if its process ID is not running: "no such process" (error 87) or exited. Denied access counts as running.host-pipelines.nextfirst and is renamed from there over the library, the step a start also takes. If a system refuses to replace a mapped file, the new library waits there and takes over at the next start; the pending file is always the newest library saved.VICTORY_LIBRARY_MAP=0restores the old behaviour. Its buffer (and the fallback when a staging file can't be mapped) is GPU: a pipeline library save the host has no memory for waits, not aborts (1.7 GB library on NVIDIA) #2007's falliblezeroed, so a save without memory is still left for later instead of aborting, with GPU: a pipeline library save the host has no memory for waits, not aborts (1.7 GB library on NVIDIA) #2007's warning.Ported from fxceless/victory-fork (commit 578d459): the mapping only, re-applied on top of upstream's concurrent loads, unique staging files and pre-build list.
Testing
New tests:
the_library_file_is_mapped_and_replaced: a save replaces a mapped library while the old mapping still reads the old bytes; the next start reads the new one; a failed serialisation leaves the library as it was and no staging file behind.a_replaced_library_file_still_reads_from_the_disk: an 8 MiB file written past the system cache still reads correctly page by page after being replaced. It fails with the file closed: page 16 reads zeros here.the_next_start_reads_the_library_saved_last: with the library held, saves wait as the pending file (a newer one replacing an older); released, the next save replaces the library and leaves no pending file.a_mapped_library_file_cannot_be_written_meanwhile: while mapped, opening the file to write or truncate fails with a sharing violation; reading it and a save's rename over it work.staging_names_give_their_process,staging_files_of_ended_runs_are_removed: staging files whose process ended are removed (no such process, or exited with a handle held). Those of this process, of a running process, of PID 4 and other files are kept.pipelines_load_on_many_threads_at_oncenow opens its library from a mapped file.Memory (
library_file_memory, ignored measurement, release): for a 256 MiB library file, reading it into memory adds 256.5 MiB of private memory; mapping it and reading every page adds 0.5 MiB.Mutation checks, each caught:
a_mapped_library_file_cannot_be_written_meanwhilestaging_files_of_ended_runs_are_removedcargo test -p victory-gpu --libon an RTX 5070 Ti, with mapping on and withVICTORY_LIBRARY_MAP=0: all pass except the two tests that already fail onmainfrom the NVIDIA heap cap (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.Not covered / Related
zeroedfor its buffer fallback and needs no buffer when mapping works. GPU: pipeline library loads do not wait for a save #2179 (merged) loads without the library's lock; the mapped bytes stay with the locked library, which is never dropped.Rebased onto f3578e3
Re-expressed on top of #2007 and #2179: this branch's own fallible buffer and its test (
a_save_buffer_the_host_cannot_give_is_an_error) are dropped in favour of #2007'szeroedanda_save_buffer_the_host_cannot_give_is_refused; a save without memory logs #2007's "saved later" warning. Saves keep #2179's lock split (loads lock nothing).cargo test -p victory-gpu --lib: all pass but the two that fail onmainhere (NVIDIA heap cap); clippy clean with and without--features diagnostics.