Skip to content

Shaders: split compute pieces share one pool of piece builders - #2931

Draft
KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:shaders-piece-queue
Draft

KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:shaders-piece-queue

Conversation

@KOLESNiii

Copy link
Copy Markdown

--pipelines and startup shader preparation start a fresh group of up to XCL_PIPELINE_THREADS helper threads for every split compute program. All the groups wait at the same 4-slot running gate. With 17 shader workers on four-piece programs, that is 68 helpers for 4 driver slots. Each helper also reads its piece's driver blob (driver_cache::load, a full fs::read) before the gate, so on a warm run every waiting helper holds a blob in memory.

This PR starts XCL_PIPELINE_THREADS piece builders once per precompile, and the pieces of every split program go through them. The native-create limit is unchanged, and at most XCL_PIPELINE_THREADS pieces have read their blob at a time. A program's worker still waits for its own pieces, so progress reporting and the summary counters behave as before.

Part of #2880. Whether the old scheme costs anything measurable is the open question in #2880, and this PR is mainly there so it can be measured A/B against main. If it only changes thread counts, it may not be worth merging.

What is in it

  • crates/xcl/src/shaders.rs: PieceQueue / PieceJob, Pipelines::{queue_pieces, build_pieces, open_pieces, close_pieces}; precompile starts the builders and closes the queue once its shader workers have returned. make called outside precompile (tests) keeps its own per-program helpers.
  • A GPU test, split_programs_share_the_piece_builders: four three-piece programs on two builders. Every piece is cached when make returns, the queue drains, the builders exit and the gate count returns to 0.

Testing wanted: please post baseline figures, not only the smoke run

The standard smoke run is useful as a regression check, but it doesn't reach what this PR changes. What's needed is the profile from the #2880 comment, run on main and on this PR's head with everything else held constant:

  • Adapter: wave32-only (NVIDIA, Intel, or AMD with XCL_SPLIT_WAVE64=1). Give the GPU, driver, CPU and RAM.
  • Env, fixed for all runs: XCL_DXC_THREADS (same value throughout, e.g. 15), XCL_PIPELINE_THREADS=4, default XCL_PIPELINE_MAX_KB, a dedicated XCL_DXIL_CACHE, a release build.
  • Command: xcl shaders <pack> --precompile --only cs --pipelines, on a pack whose split compute programs: N (M pieces) line shows at least a few hundred pieces.
  • Cache states, 3 runs each, for each build:
    1. driver-cold: warm DXIL cache, with %XCL_DXIL_CACHE%\driver and the driver's shader cache (NVIDIA\DXCache / D3DSCache) deleted before each run
    2. warm: rerun without deleting anything. Here the blob read before the gate matters.
    3. optional fully cold: empty XCL_DXIL_CACHE
  • Record: the time … s line; the pipelines made / refused / loaded from the driver cache and split compute programs lines; peak live threads and total threads created (WPR, or a ≤10 ms sampler; sampled peaks miss short-lived helpers); process peak commit (PeakPagefileUsage, or a ≤50 ms PrivateMemorySize64 sampler).
  • Equivalence: the same set of file names in %XCL_DXIL_CACHE%\driver and the same made / refused / reused counts on both builds.

Tested

  • RTX 2070 SUPER (wave32 only), Windows 11 26300, stable MSVC Rust, debug: cargo build -p xcl and cargo test -p xcl --lib --no-run build with no new warnings.
  • GPU test runs (the shaders:: tests and the whole suite) are waiting in this machine's exclusive-run queue. Their counts will be added here; nothing has been run on a GPU yet.

Regression run

  • pending: scripts/smoke.ps1 on main and on this head, to be added when they have run

Not tested

AI use

  • Claude Code with Claude Opus 5.5 wrote the code, the test and this description. The author reviewed them.

🤖 Generated with Claude Code

`--pipelines` and startup shader preparation started a fresh scoped group
of up to `XCL_PIPELINE_THREADS` helpers for every split compute program.
All the groups wait at the same `running` gate, so 17 shader workers each
on a four-piece program could hold 68 helpers for 4 driver slots. Each
helper also reads its piece's driver blob from disk before the gate, so
on a warm run every waiting helper holds a blob in memory (xcl-dev#2880).

`precompile` now starts `XCL_PIPELINE_THREADS` piece builders once. A
split program's worker queues its pieces and waits for them as before,
so progress and the summary counters do not change. At most
`XCL_PIPELINE_THREADS` pieces are past `make_one`'s blob read at a time.
`make` outside `precompile` (the tests) keeps its own helpers.

Not measured yet: the cost of the old scheme on a split-heavy corpus is
the open question in xcl-dev#2880.

Part of xcl-dev#2880

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Paired offline benchmark for #2880 on RTX 5070 Ti Laptop 12 GiB (621.24), Ryzen 9 8945HX, 31.8 GiB usable RAM, Windows 11 26200.9974, Rust 1.97.1 MSVC, DXC/DXIL 1.8.2502.11. Clean release builds of 8b957bec6f82495aec940944c6bf47faa02db590 and 093a5fcdc2d8db1358c78e0074567960e1e1560e.

Synthetic RPF9 with 160 variants of the existing wave32 split compute fixture. xcl shaders <pack> --precompile --only cs --pipelines --windows 1, XCL_DIRECT_DXIL=1, XCL_DIRECT_SPLIT_INSTRUCTIONS=12, XCL_DXC_THREADS=15, XCL_PIPELINE_THREADS=4, default size cap. Three cold/warm pairs per build, interleaved base/head/head/base/base/head. Each pair started with an identical copy of the translation cache and an empty XCL driver folder. I left the NVIDIA system cache in place, so the XCL-cold rows are not a driver-cold comparison.

Cache / build Median wall s Peak live threads, sampled range Distinct thread IDs seen, range Median peak process commit (MiB)
XCL-cold / base 0.771 99 672 112.61
XCL-cold / head 0.730 35 36 100.82
Warm / base 0.441 99–101 573–607 150.47
Warm / head 0.471 35 36 141.71

Thread snapshots: median interval 4.17–4.57 ms across runs, maximum 5.95 ms. IDs seen are a lower bound, not an ETW thread-create total. Peak commit is the Windows PeakPagefileUsage counter. All 12 runs made 800 pieces, refused 0, and ended with the identical set of 800 .pso filenames. XCL reported 0 cache loads on the first run of each pair and 800 on the warm run. The first base XCL-cold run was an outlier at 5.669 s and 278.62 MiB, so I would not infer a cold-time change from this setup. The repeatable difference is thread count, with warm wall time slightly higher on this short fixture. A retail title, a cold NVIDIA cache and full workspace tests were outside this run. OpenAI Codex (6.2sol) assisted with verification.

@KOLESNiii

Copy link
Copy Markdown
Author

Thank you @ettehn, a paired, interleaved A/B with matched cache states is exactly what this needed. I've written up what it shows, together with the two runs on #2880, in this comment. In short: thread starts per pass go from about 640 to 4 and peak commit drops about 10 MiB, consistent with thread stacks. Cold time doesn't change, because the 4-slot gate is the limit. The small warm slowdown may come from this PR dropping the blob read-ahead that the waiting helpers gave main. I'll try a 2 × XCL_PIPELINE_THREADS builder variant to check that.

AI use: Claude Code (Claude Opus 5.5) drafted this comment.

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