compute: prepare the compute pack on several threads (--jobs) #3472

Merged
lukaslw-lab merged 3 commits from upstream-pr/3472 into main 2026-12-01 00:19:40 +00:00
lukaslw-lab commented 2026-11-29 16:27:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-29T16:27:11Z.


Follows #3091, which added the pack.

compile_dxil --prepare-compute-pack translated the requests one at a time, on one core. They are independent:
the frontend keeps no state between them, and the IR cache publishes through unique temporary files. So they are
now prepared on every hardware thread (at most 64), or on --jobs N, and their records are appended in the sorted
request order. The pack is the same for every thread count; --jobs 1 is the old behaviour.

Captured slot 67 requests, empty cache, release build, 8 hardware threads one at a time default
2689 requests 882 s (before this change) 212 s (4.2x), peak 1.34 GiB
207 of them (every 13th), same build 75.3 s (--jobs 1) 20.5 s (3.7x)
207: prepared / unsupported / errors 67 / 140 / 0 67 / 140 / 0, pack byte-identical
  • In a debug build the CRT debug heap takes one lock for every allocation, so the threads mostly wait for each
    other there: use --jobs 1 with a debug build.
  • The 2689-request set now reaches the 256 MiB pack limit and 28 requests are left out; that is not from this
    change (the limit and its check are unchanged) and is filed as #3473.
  • Docs: docs/experiments/native-startup-request-cache.md (prewarming section).

Tests: native_compute_pack builds eleven requests (one prepared, ten refused, mixed in the sorted order) with
--jobs 1, --jobs 4 and the default, requires byte-identical packs that the checker accepts, and refuses
--jobs 0. Locally (Windows 10 19045, dev and release builds): ctest -R "^native_compute_pack$" passes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5552701010 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3472). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-29T16:27:11Z. --- Follows #3091, which added the pack. `compile_dxil --prepare-compute-pack` translated the requests one at a time, on one core. They are independent: the frontend keeps no state between them, and the IR cache publishes through unique temporary files. So they are now prepared on every hardware thread (at most 64), or on `--jobs N`, and their records are appended in the sorted request order. The pack is the same for every thread count; `--jobs 1` is the old behaviour. | Captured slot 67 requests, empty cache, release build, 8 hardware threads | one at a time | default | |---|---|---| | 2689 requests | 882 s (before this change) | **212 s** (4.2x), peak 1.34 GiB | | 207 of them (every 13th), same build | 75.3 s (`--jobs 1`) | **20.5 s** (3.7x) | | 207: prepared / unsupported / errors | 67 / 140 / 0 | 67 / 140 / 0, pack byte-identical | - In a debug build the CRT debug heap takes one lock for every allocation, so the threads mostly wait for each other there: use `--jobs 1` with a debug build. - The 2689-request set now reaches the 256 MiB pack limit and 28 requests are left out; that is not from this change (the limit and its check are unchanged) and is filed as #3473. - Docs: `docs/experiments/native-startup-request-cache.md` (prewarming section). Tests: `native_compute_pack` builds eleven requests (one prepared, ten refused, mixed in the sorted order) with `--jobs 1`, `--jobs 4` and the default, requires byte-identical packs that the checker accepts, and refuses `--jobs 0`. Locally (Windows 10 19045, dev and release builds): `ctest -R "^native_compute_pack$"` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Leyukaka commented 2026-11-29 17:27:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T17:27:01Z.

Review: APPROVED


Diff reading only at 788ff2e1; nothing built or run.

Checked:

  • Output order is fixed: workers write only records[i]; the pack, counts and errors are assembled afterwards in sorted marker order.
  • The size cut is unchanged: a record is 8 (key) + 64 (digest) + 4 + 4 + payload, the old 80 + payload.
  • The per-request calls already run in parallel on main: translate_compute(req, 0, true) in --refusals, prepare_direct_compute (which goes through cached_compute_ir) in --watch.

NIT src/direct_compute_cache.cpp:398-423: every record stays in memory until the assembly loop, including those past the 256 MiB cut, which the serial code dropped at once. Peak memory is the sum of all records, not the pack size. #3473 changes the same function.

NIT tests/native_compute_pack_check.py:43-51: the --jobs 1 / --jobs 4 comparison catches a completion-order append only through timing (the one prepared request has to finish after the quick refusals that sort after it). Two or more prepared requests, or a check that record keys follow the sorted marker names, would make it deterministic.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6103967655 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3472#pullrequestreview-6103967655). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T17:27:01Z. **Review:** APPROVED --- Diff reading only at 788ff2e1; nothing built or run. Checked: - Output order is fixed: workers write only `records[i]`; the pack, counts and errors are assembled afterwards in sorted marker order. - The size cut is unchanged: a record is 8 (key) + 64 (digest) + 4 + 4 + payload, the old `80 + payload`. - The per-request calls already run in parallel on main: `translate_compute(req, 0, true)` in `--refusals`, `prepare_direct_compute` (which goes through `cached_compute_ir`) in `--watch`. NIT `src/direct_compute_cache.cpp:398-423`: every record stays in memory until the assembly loop, including those past the 256 MiB cut, which the serial code dropped at once. Peak memory is the sum of all records, not the pack size. #3473 changes the same function. NIT `tests/native_compute_pack_check.py:43-51`: the `--jobs 1` / `--jobs 4` comparison catches a completion-order append only through timing (the one prepared request has to finish after the quick refusals that sort after it). Two or more prepared requests, or a check that record keys follow the sorted marker names, would make it deterministic.
lukaslw-lab commented 2026-11-29 23:52:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-29T23:52:52Z.


Thanks. Both nits:

  • Test order (e2b8e027): the check now reads the record keys from the --jobs 4 pack and requires them in sorted request order (pack_keys in tests/native_compute_pack_check.py). That no longer depends on the threads finishing in a particular order.
  • Peak memory: kept as is. On a real capture of 4,352 compute requests, --prepare-compute-pack with the default --jobs took 419 s at a peak of 1.43 GiB. #3484 keeps every part in memory until it publishes, so with both PRs the peak stays about one pack whichever merges first.

ctest -R "^native_compute_pack$": passed on release and dev (Windows 10 19045).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7264796072 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3472#issuecomment-7264796072). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-29T23:52:52Z. --- Thanks. Both nits: - **Test order** (`e2b8e027`): the check now reads the record keys from the `--jobs 4` pack and requires them in sorted request order (`pack_keys` in `tests/native_compute_pack_check.py`). That no longer depends on the threads finishing in a particular order. - **Peak memory:** kept as is. On a real capture of 4,352 compute requests, `--prepare-compute-pack` with the default `--jobs` took 419 s at a peak of 1.43 GiB. #3484 keeps every part in memory until it publishes, so with both PRs the peak stays about one pack whichever merges first. `ctest -R "^native_compute_pack$"`: passed on release and dev (Windows 10 19045).
lukaslw-lab commented 2026-11-30 09:33:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T09:33:51Z.


Rebased onto main after #3484. The threads now only translate; the records go into #3484's parts afterwards, in the sorted order, so the parts are the same as with --jobs 1. jobs is the 5th parameter, after part_limit. native_compute_pack and native_compute_pack_parts pass (dev + release).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7274379321 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3472#issuecomment-7274379321). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T09:33:51Z. --- Rebased onto main after #3484. The threads now only translate; the records go into #3484's parts afterwards, in the sorted order, so the parts are the same as with `--jobs 1`. `jobs` is the 5th parameter, after `part_limit`. `native_compute_pack` and `native_compute_pack_parts` pass (dev + release).
lukaslw-lab commented 2026-11-30 10:42:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T10:42:19Z.


Rebased onto main a27119db (head ec8030b3). The only conflict was the usage text in tools/startup/compile_dxil.cpp: #3539 added [--jobs N] to --index-graphics-interfaces, and this PR adds it to --prepare-compute-pack. Both are kept, and the code merged unchanged.

native_compute_pack and native_compute_pack_parts pass in dev and release. native_compute_pack_hardware fails on this host as before (the adapter lacks Shader Model 6.6).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7275963609 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3472#issuecomment-7275963609). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T10:42:19Z. --- Rebased onto `main` `a27119db` (head `ec8030b3`). The only conflict was the usage text in `tools/startup/compile_dxil.cpp`: #3539 added `[--jobs N]` to `--index-graphics-interfaces`, and this PR adds it to `--prepare-compute-pack`. Both are kept, and the code merged unchanged. `native_compute_pack` and `native_compute_pack_parts` pass in dev and release. `native_compute_pack_hardware` fails on this host as before (the adapter lacks Shader Model 6.6).
Leyukaka commented 2026-12-01 00:04:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T00:04:14Z.

Review: APPROVED


Re-read at ec8030b3, diff only. The workers fill only records[i], and the parts are assembled afterwards in sorted marker order (src/direct_compute_cache.cpp:474-489), so the pack does not depend on --jobs. pack_keys (tests/native_compute_pack_check.py:15, :73) now checks that order directly, which closes my earlier test NIT.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6122773725 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3472#pullrequestreview-6122773725). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T00:04:14Z. **Review:** APPROVED --- Re-read at `ec8030b3`, diff only. The workers fill only `records[i]`, and the parts are assembled afterwards in sorted marker order (`src/direct_compute_cache.cpp:474-489`), so the pack does not depend on `--jobs`. `pack_keys` (`tests/native_compute_pack_check.py:15`, `:73`) now checks that order directly, which closes my earlier test NIT.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!3472
No description provided.