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

Open
opened 2026-11-26 21:20:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2088
Author: @c0pperlane
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: vk-pipeline-large-admission


📝 Commits (2)

  • 6c6a8cd vk_pipeline_check: a large module that must wait frees its worker (VK-PIPELINE-CHECK-LARGE-ADMISSION)
  • de3ee20 Merge remote-tracking branch 'origin/main' into vk-pipeline-large-admission

📊 Changes

4 files changed (+230 additions, -7 deletions)

View changed files

📝 docs/pipeline_check.md (+3 -1)
📝 runtime/test/large_module_gate.h (+71 -0)
📝 runtime/test/large_module_gate_test.cpp (+150 -0)
📝 runtime/test/vk_pipeline_check.cpp (+6 -6)

📄 Description

Claimed in the coordination issue as: VK-PIPELINE-CHECK-LARGE-ADMISSION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171910784)

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 db1a22d2, then merged with main at 33bd07cf (merge commit de3ee203b2, 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 9f9a7c5f 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 #964 covers; main has since changed this test in #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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2088 **Author:** [@c0pperlane](https://github.com/c0pperlane) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `vk-pipeline-large-admission` --- ### 📝 Commits (2) - [`6c6a8cd`](https://github.com/ubiquitarianism/leonida/commit/6c6a8cd47d74e5dc94751f4efdaa603e893b20f9) vk_pipeline_check: a large module that must wait frees its worker (VK-PIPELINE-CHECK-LARGE-ADMISSION) - [`de3ee20`](https://github.com/ubiquitarianism/leonida/commit/de3ee203b23eb6cb3a20d7f1b78ea1d6473ba927) Merge remote-tracking branch 'origin/main' into vk-pipeline-large-admission ### 📊 Changes **4 files changed** (+230 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `docs/pipeline_check.md` (+3 -1) 📝 `runtime/test/large_module_gate.h` (+71 -0) 📝 `runtime/test/large_module_gate_test.cpp` (+150 -0) 📝 `runtime/test/vk_pipeline_check.cpp` (+6 -6) </details> ### 📄 Description Claimed in the coordination issue as: VK-PIPELINE-CHECK-LARGE-ADMISSION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171910784) 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](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7148018607)). `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 db1a22d2, then merged with main at 33bd07cf (merge commit de3ee203b2, 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 9f9a7c5f 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 #964 covers; main has since changed this test in #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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2094
No description provided.