Skip to content

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

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
lukaslw-lab:compute/parallel-pack
Dec 1, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
lukaslw-lab:compute/parallel-pack

Conversation

@lukaslw-lab

@lukaslw-lab lukaslw-lab commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

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

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff reading only at 788ff2e; 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

Copy link
Copy Markdown
Contributor Author

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. compute: publish every compute pack record across numbered parts #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

Copy link
Copy Markdown
Contributor Author

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 and others added 3 commits November 30, 2026 11:24
compile_dxil --prepare-compute-pack translated the requests one at a time. 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, or on
--jobs N, and their records are appended in the sorted request order: the pack is the
same for every thread count. native_compute_pack builds eleven requests with 1, 4 and the
default count and compares the bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The --jobs 1 / --jobs 4 comparison caught a completion-order append only when the one prepared request finished after
the refusals that sort after it. Read the record keys from the --jobs 4 pack and require them in sorted request order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukaslw-lab
lukaslw-lab force-pushed the compute/parallel-pack branch from f99cacf to ec8030b Compare November 30, 2026 10:42
@lukaslw-lab

Copy link
Copy Markdown
Contributor Author

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 Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 7e4f379 into R0Y00:main Dec 1, 2026
5 checks passed
@lukaslw-lab
lukaslw-lab deleted the compute/parallel-pack branch December 1, 2026 01:11
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.

3 participants