Skip to content

vk_pipeline_check: a large module that must wait frees its worker (VK-PIPELINE-CHECK-LARGE-ADMISSION) - #2088

Open
c0pperlane wants to merge 2 commits into
ProjectLeonida:mainfrom
c0pperlane:vk-pipeline-large-admission
Open

c0pperlane wants to merge 2 commits into
ProjectLeonida:mainfrom
c0pperlane:vk-pipeline-large-admission

Conversation

@c0pperlane

@c0pperlane c0pperlane commented Nov 25, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: VK-PIPELINE-CHECK-LARGE-ADMISSION (#1608 (comment))

Depends on: #1890 (conflict only, one line: it edits the line above std::atomic<size_t> next{0}, done{0}; and this drops next from it; nothing is built on it)

What and why

A worker of vk_pipeline_check took the next index (next++) and only then waited in the large-module gate. With the memory budget full, spare workers blocked holding large modules while smaller modules behind them sat untaken, so the pool ran below --jobs (finding by akimfomin).

LargeModuleQueue in runtime/test/large_module_gate.h now hands out the indices. A large module the gate can't admit yet is put back and the worker takes the next module. The oldest module put back goes first as soon as the gate admits it, no later large module passes it (so none waits forever), and once every index is out a worker waits for it. Each module is still checked exactly once: every branch before the gate that counts or prints ends in continue before a module can be put back, so a module that comes back only re-reads its size. Nothing is put back while the gate admits each large module as it comes, so with one worker or room under the budget the order is the old one. --large-parallel 1 (and the unknown-memory fallback) and --large-module-bytes 0 never ask the queue to admit, so they behave as before. --large-parallel N (N ≥ 2, a count without a budget) puts modules back too. LargeModuleGate itself is unchanged. Main moved it to runtime/src/large_module_gate.h in RT-BIG-COMPUTE-BUDGET; its arrival order and demand-before-speculative ordering belong to the read-budget constructor, which only the runtime uses. vk_pipeline_check's fixed-budget gate admits whatever fits, so the order among the modules put back comes from this queue. LargeModuleQueue stays in the forwarding header runtime/test/large_module_gate.h. It admits with admits() and a blocking Ticket under its own mutex, which is atomic because every large module of vk_pipeline_check enters the gate through the queue. One sentence in docs/pipeline_check.md.

Tested

Windows 11 Pro (10.0.26300), MSVC 14.44.35207 (VS 2022 Build Tools), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0. First tested on db1a22d, then merged with main at 33bd07c (merge commit de3ee20, no rebase). The merge moves the queue's admission onto main's shared LargeModuleGate and changes nothing else.

  • On the merged tree:

    • A targeted build: large_module_gate_test big_compile_gate_test vk_pipeline_check pipeline_cache_seed_test, plus the d3d12_big_compute, pipeline-cache and compile tests that include runtime/src/large_module_gate.h.
    • ctest -R "large_module|pipeline_check|pipeline_summary|big_comp|compile|pipeline_cache": 20/20 passed.
    • python -m unittest discover -s tests -p "test_vk_pipeline_check*.py": 21 OK.
    • git merge-tree with main: clean.

    The bullets below ran before the merge.

  • CI-style Windows build (Ninja, RelWithDebInfo, LEONIDA_D3D12_SHIM_TESTS=ON, LEONIDA_REQUIRE_VULKAN=ON): 985 steps, no errors, no warnings from the changed files.

  • ctest --test-dir runtime/build --output-on-failure --timeout 300 -R "large_module|vk_pipeline_check" --repeat until-fail:3: 3/3 tests, 3 times each, on the rebased branch.

  • New cases in large_module_gate_test: a waiting large module frees its worker; oldest-first, with no double entry for a module that comes back with its place; unchanged order while the gate admits (one worker, --large-parallel 2 with room, counting only); every module once under 8 threads, 300 modules, budget never exceeded. With the queue switched back to claim-then-admit (take() returns the next index, admit() waits on a blocking ticket), the first case fails: line 145: (while_other_in == std::vector<size_t>{1, 2}).

  • A CPU probe compiled from the worker-loop and gate statements of main's and this branch's vk_pipeline_check.cpp, after the finding's fixture approach: main fails the full-budget case (waits on module 0, the small module never starts) and this branch passes it (1, then 0). The room-in-budget, --large-parallel 2, gate-disabled and exclusive cases give the same order and locks on both.

  • python -I tests/test_vk_pipeline_check_isolate.py: 10 OK.

  • vk_pipeline_check on 40 synthetic compute modules (20 over --large-module-bytes 2000) with --jobs 4 --large-parallel 2, the default budget, --large-parallel 1, --large-module-bytes 0 and --jobs 1: every run 40/40 modules and pipelines ok, large modules counted 20 wherever the gate is on, on both GPUs below.

  • Full ctest --test-dir runtime/build --output-on-failure --timeout 300 (serial), run on the branch's original base 9f9a7c5 before the rebase: 424 run, 422 passed, 11 skipped for lack of game files or hardware, 2 disabled (no SDL3). The two failures don't involve this change: d3d12_texture_tiles failed in its native-D3D12 half on the AMD Radeon 610M (got 0x20000cc, expected 0xcc020000, AMD's CopyTiles byte offset, the case test: texture tiles NOTE only for the measured CopyTiles offset rounding on AMD and Intel (D3D-TILES-AMD-BYTE-OFFSET) #964 covers; main has since changed this test in test: respect LEONIDA_HOST_ADAPTER and layer LUID in d3d12_texture_tiles (RT-TEXTURE-TILES-HOST-ADAPTER) #1941), and xs_proxy_mock failed once on its timing-dependent tear check (line 4487) and passed 3/3 reruns on this branch and 3/3 on main's sources. Neither binary changes with this pull request.

  • python -I scripts/check_no_game_data.py on every changed file: clean.

Not built on Linux or macOS here; throughput and peak memory on a real large corpus were not measured (that needs game files).

GPUs tested: NVIDIA GeForce RTX 5080 Laptop GPU (Windows driver 32.0.16.2124) and AMD Radeon 610M (driver 32.0.21030.34003), Windows 11; synthetic modules only. The gate tests themselves are CPU-only.

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

…-PIPELINE-CHECK-LARGE-ADMISSION)

A worker took the next index and only then waited in the large-module gate,
so with the memory budget full the modules behind a large one sat untaken
while spare workers blocked, and the pool ran below --jobs.

LargeModuleQueue (large_module_gate.h) now hands out the indices. A large
module the gate can't admit yet is put back and the worker takes the next
one. The oldest module put back goes first as soon as the gate admits it and
no later large module passes it; once every index is out, a worker waits for
it. Nothing is put back while the gate admits each large module as it comes,
so with one worker or room under the budget the order is unchanged, and
--large-parallel 1 and --large-module-bytes 0 never ask the queue to admit.

large_module_gate_test: the waiting module frees its worker (fails with the
old claim-then-admit order), oldest-first and no double entry, the unchanged
order, and every module once under 8 threads.

AI-assisted (Claude Code).
@ZroIsHere

Copy link
Copy Markdown
Contributor

Integration finding: #2088 needs rebasing because LargeModuleGate moved from runtime/test/large_module_gate.h to runtime/src/large_module_gate.h in RT-BIG-COMPUTE-BUDGET. The queue/try-admission logic must be added to the shared header rather than restoring a separate test copy; I recorded the compatible shape and passing large_module_gate_test in coordination #1608. AI-assisted.

…ission

Conflict in runtime/test/large_module_gate.h: kept main's forwarding header to runtime/src/large_module_gate.h (unchanged) and put LargeModuleQueue after the include; it admits with the gate's admits() and a blocking Ticket under its own mutex, so try_enter and the try_to_lock Ticket are no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants