Repository navigation
Docs and test: use ThreadPinning.jl to pin Dagger's threads - #810
Conversation
a9a2c5c to
b752e5f
Compare
|
This comment was written by an AI agent, acting on jpsamaroo's review feedback. @AnnaLena77, thank you for this, and for the clear write-up of the What we checked. ThreadPinning 1.1.1 with Dagger master, on Julia 1.10, 1.11 and 1.12, on a 12-CPU Linux machine. We ran two processes side by side under
Suggestion. Could this PR become tests and documentation for using ThreadPinning with Dagger, instead of new functions? For example, a short docs page, plus a test that starts a subprocess under using Dagger, ThreadPinning # ThreadPinning = "1" in [compat]
pinthreads(:affinitymask) # one default-pool thread per CPU of this process's maskPitfalls the page should mention, all of which we measured:
Thanks again. We're happy to help with the test and the docs page. |
Add a usage guide for pinning Julia's threads with ThreadPinning.jl instead of a Dagger-specific API: basic use with pinthreads(:affinitymask), and the pitfalls (ThreadPinning 1.x, addprocs before pinning, separate CPUs for same-node workers, interactive threads). Add a Linux-only test that starts Julia under taskset -c with a CPU range, pins, and checks that the threads, and the CPUs seen from inside Dagger tasks, lie inside the mask, are distinct, and are unchanged by a second call. It is skipped without Linux, taskset, four allowed CPUs, or ThreadPinning. ThreadPinning is a test-only dependency.
b752e5f to
d65e379
Compare
…uliaParallel#803, JuliaParallel#810, JuliaParallel#811) Four reviews run end to end through the worktree flow each reported the same frictions; this addresses them. - CI is compared with the base commit: collect fetches the base's check results, and the brief marks each failing configuration NEW or 'also fails on base', with how many of its jobs failed. Reviewers had been fetching master's statuses by hand to learn that only mpi-cuda (JuliaParallel#801) or two multithreaded jobs (JuliaParallel#810) were new. A re-run still in progress now reads 'pending', not 'pass/pass/pending'. - The brief no longer calls agreement between categories independent unless _meta.json says each was reviewed separately (reviewer.independent); one agent writing all thirteen fragments was being reported as several reviewers converging. - A rejected claim no longer also triggers verdict errors (E030-E034, E031) that tell the reviewer to change a verdict when the fault is a citation; those checks wait until the claims are valid. - A claim may depend on another fragment's question ("question": "necessity.q1"), so a finding raised by several categories hangs on one question. - `review.py attach` adds a measurement made during the review without setting fragments aside; re-collecting keeps earlier attachments when the diff is unchanged; every task lists the attached measurements. - The task rules state submit's limits (claim length, quote length, multi-line quotes, pointer escaping); prompts print paths that are right from any directory; commits record their authors. - Rubrics: Allocations and Performance are na (not an unmeasured pass) when nothing steady-state changed; precompile-workload changes are measured by precompile time and time to first use. - REVIEW.md: how to run Julia against a PR worktree without touching it or the maintainer's caches; one reviewer may do every category of a small change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
|
Thanks, that makes sense, and thanks for the detailed measurements. I replaced the API in this PR with a docs page and a test for ThreadPinning.jl, following your suggestion. The page covers your pitfalls (ThreadPinning 1.x, It passed 16/16 on a Linux node (Julia 1.13.1, ThreadPinning 1.1.1). I have not run it on Julia 1.10 to 1.12 or built the docs yet, and I did not check that it fails when pinning ignores the mask, so CI will be the first run for those. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #810 +/- ##
==========================================
- Coverage 64.42% 64.35% -0.08%
==========================================
Files 126 126
Lines 20192 20191 -1
==========================================
- Hits 13009 12993 -16
- Misses 7183 7198 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Julia 1.10/1.11 reject an explicit zero interactive thread count, so the restricted-affinity subprocess never starts and six assertions fail on CI. Use the single-count form on those versions, which already omit interactive threads, and retain the explicit zero on newer Julia. Correct the manual's startup example and record the compatibility rule. Verified in an isolated credential-free sandbox on Julia 1.10.11: all 16 ThreadPinning assertions pass for restricted masks with two and four threads, including repeated pinning and processor/CPU placement. The old flag failure is present in actual-head CI job 141322892787. git diff --check passes. Written by an AI agent on jpsamaroo's review feedback.
GitHub will not launch pull-request workflows while this source branch conflicts with master. Preserve both sets of agent lessons and the feature implementation while incorporating current scheduler and review fixes. The only manual merge resolution is AGENTS.md's appended lessons. Targeted feature suites will be rerun before pushing. Written by an AI agent on jpsamaroo's review feedback.
`__init__` registered `ThreadProc(myid(), tid)` for `tid in 1:Threads.nthreads()`. `nthreads()` counts only the default pool, but Julia numbers the interactive pool first: with an interactive thread (the default since Julia 1.12, or `-t N,1` on 1.10/1.11) thread 1 is interactive and the default pool is threads 2:N+1. So Dagger ran tasks on the interactive thread, where the main task and the REPL live, and never used the last default thread. Measured on Julia 1.12 with `-t 4` (found while checking ThreadPinning.jl against JuliaParallel#810): Dagger's ThreadProcs were tids [1, 2, 3, 4], and the CPU pinned to tid 5 never ran Dagger work. This loop dates from 2020-2021, before interactive threads existed, so using thread 1 was never a decision. Register the default pool's tids (`Threads.threadpooltids(:default)`, available since 1.9) instead. Dagger now never schedules tasks on an interactive thread: Julia reserves those for short, latency-sensitive work, and they are where the REPL and usually the eager scheduler's own loop run. Everything that meant "the first thread" by writing a literal 1 now asks for it: - The eager scheduler's long-lived thunk was pinned to `ExactScope(ThreadProc(1, 1))`, which no longer exists when thread 1 is interactive; pin it to the first default-pool thread. - The precompile workload registered `__cpu_thread_1__` directly (`__init__` has not run yet), and that Dict is saved in the package image. `__init__` used to overwrite that entry; now that it registers other names, a stale ThreadProc(1, 1) would survive into every session. Register the first default thread and delete the callback at the end of the workload. `Threads.nthreads()` elsewhere sizes parallel work by the default pool's size, which is still correct. `stealing_permitted` still excludes worker 1's thread 1 (the main thread); when that thread is interactive there is simply no ThreadProc for it. Tests that scheduled on `ThreadProc(1, 1)` or `thread=1` (or on a worker's threads 1 and 2) only passed on 1.12+ because tasks could run on the interactive thread; they now use the real first threads. CI's 1.12+ multithreaded jobs (`-t auto`) have an interactive thread, but 1.10/1.11 do not, so the processors suite also starts a `-t 2,1` subprocess and checks that ThreadProcs are exactly the default pool, that tasks pinned to each run there, and that no task runs on the interactive thread. That test fails on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dagger benchmarks:
|
| Backend | Regressions | Improvements | Within noise | Inconclusive time | Suites |
|---|---|---|---|---|---|
| Threads | 0 | 2 | 20 | 1 | 4/4 |
| Distributed | 1 | 2 | 2 | 0 | 4/4 |
| Distributed+Threads | 0 | 0 | 0 | 0 | 4/4 |
| MPI | 0 | 5 | 3 | 1 | 4/4 |
| MPI+Threads | 0 | 0 | 15 | 1 | 4/4 |
| Total | 1 | 9 | 40 | 3 | 20/20 |
Regressions across all backends
| Backend | Benchmark | Metric | Change |
|---|---|---|---|
| Distributed | linalg/dagger/N=1024 (block 128)/syrk (A'*A) |
allocs | +25.7% |
Improvements across all backends
| Backend | Benchmark | Metric | Change |
|---|---|---|---|
| Distributed | linalg/dagger/N=1024 (block 128)/matmul (A*A) |
time | -56.4% |
| Threads | stencil/dagger/N=256 (block 256)/multi-expr |
time | -55.3% |
| MPI | linalg/dagger/N=256 (block 128)/cholesky |
time | -52.8% |
| MPI | linalg/dagger/N=256 (block 128)/lu |
time | -47.3% |
| MPI | linalg/dagger/N=256 (block 128)/matmul (A*A) |
time | -47.1% |
| Distributed | linalg/dagger/N=1024 (block 128)/lu |
time | -46.2% |
| MPI | linalg/dagger/N=256 (block 128)/matvec (A*x) |
time | -37.8% |
| MPI | linalg/dagger/N=1024 (block 512)/solve (A\b via lu) |
time | -35.0% |
| Threads | linalg/dagger/N=1024 (block 128)/svd |
allocs | -30.5% |
Advisory allocation changes
Paired fixed-placement measurements gate Distributed CPU allocating LU counts and bytes and allocating X + X bytes. Review the advisory changes for costs specific to the allocating path. The original X + X count gate still applies.
| Backend | Benchmark | Metric | Change |
|---|---|---|---|
| Distributed | array/dagger/N=1024 (block 128)/add (X + X) |
memory | -26.3% |
Threads (1 process × 4 threads) — 0 regressions, 2 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 7 | 1 |
| linalg | 0 | 1 | 8 | 0 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 1 | 5 | 0 |
Improvements
| Benchmark | Metric | Change |
|---|---|---|
stencil/dagger/N=256 (block 256)/multi-expr |
time | -55.3% |
linalg/dagger/N=1024 (block 128)/svd |
allocs | -30.5% |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
stencil/dagger/N=1024 (block 512)/update (+) |
time | +209.5% |
array/dagger/N=256 (block 128)/alloc (rand) |
time | +209.3% |
linalg/dagger/N=1024 (block 512)/matvec (A*x) |
time | +137.1% |
linalg/dagger/N=256 (block 128)/matvec (A*x) |
time | +114.5% |
array/dagger/N=256 (block 128)/reduce (sum) |
time | +84.4% |
stencil/dagger/N=256 (block 128)/neighbors (Wrap) |
time | +75.0% |
stencil/dagger/N=256 (block 128)/update (+) |
time | +58.2% |
linalg/dagger/N=256 (block 128)/cholesky |
time | +49.2% |
stencil/dagger/N=256 (block 128)/neighbors (Reflect) |
time | +40.1% |
array/dagger/N=1024 (block 128)/reduce (sum) |
time | +39.0% |
array/dagger/N=256 (block 128)/transpose (permutedims) |
time | +32.2% |
linalg/dagger/N=1024 (block 128)/cholesky |
time | +28.4% |
stencil/dagger/N=256 (block 128)/neighbors (Clamp) |
time | +27.7% |
linalg/dagger/N=256 (block 256)/qr |
time | -27.6% |
linalg/dagger/N=256 (block 256)/matmul (A*A) |
time | -28.9% |
array/dagger/N=1024 (block 128)/transpose (permutedims) |
time | -29.6% |
array/dagger/N=1024 (block 512)/add (X + X) |
time | -31.8% |
linalg/dagger/N=256 (block 128)/matmul (A*A) |
time | -37.7% |
array/dagger/N=1024 (block 512)/reduce (sum) |
time | -53.5% |
linalg/dagger/N=256 (block 256)/matvec (A*x) |
time | -64.8% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=256 (block 128)/broadcast (X .+ 1) |
time | +55.6% |
Distributed (4 processes × 1 thread) — 1 regressions, 2 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 2 | 0 |
| linalg | 1 | 2 | 0 | 0 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 0 | 0 | 0 |
Regressions
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=1024 (block 128)/syrk (A'*A) |
allocs | +25.7% |
Improvements
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=1024 (block 128)/matmul (A*A) |
time | -56.4% |
linalg/dagger/N=1024 (block 128)/lu |
time | -46.2% |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=1024 (block 512)/transpose (permutedims) |
time | +66.2% |
array/dagger/N=1024 (block 512)/broadcast (X .+ 1) |
time | +36.1% |
Distributed+Threads (2 processes × 2 threads) — 0 regressions, 0 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 0 | 0 |
| linalg | 0 | 0 | 0 | 0 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 0 | 0 | 0 |
MPI (4 ranks × 1 thread) — 0 regressions, 5 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 1 | 0 |
| linalg | 0 | 5 | 2 | 1 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 0 | 0 | 0 |
Improvements
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=256 (block 128)/cholesky |
time | -52.8% |
linalg/dagger/N=256 (block 128)/lu |
time | -47.3% |
linalg/dagger/N=256 (block 128)/matmul (A*A) |
time | -47.1% |
linalg/dagger/N=256 (block 128)/matvec (A*x) |
time | -37.8% |
linalg/dagger/N=1024 (block 512)/solve (A\b via lu) |
time | -35.0% |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=1024 (block 512)/matmul (A*A) |
time | +92.3% |
array/dagger/N=1024 (block 512)/norm |
time | +60.3% |
linalg/dagger/N=256 (block 128)/syrk (A'*A) |
time | +46.5% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=1024 (block 128)/lu |
time | +49.5% |
MPI+Threads (2 ranks × 2 threads) — 0 regressions, 0 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 6 | 1 |
| linalg | 0 | 0 | 2 | 0 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 0 | 7 | 0 |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=256 (block 128)/norm |
time | +141.9% |
stencil/dagger/N=256 (block 128)/multi-expr |
time | +140.2% |
stencil/dagger/N=256 (block 128)/assign (const) |
time | +103.0% |
stencil/dagger/N=1024 (block 512)/update (+) |
time | +101.1% |
stencil/dagger/N=256 (block 128)/neighbors (Reflect) |
time | +79.6% |
linalg/dagger/N=256 (block 256)/qr |
time | +59.7% |
array/dagger/N=1024 (block 512)/reduce (sum) |
time | +59.3% |
stencil/dagger/N=256 (block 256)/assign (const) |
time | +52.7% |
array/dagger/N=1024 (block 512)/broadcast (X .+ 1) |
time | +46.4% |
linalg/dagger/N=256 (block 128)/syrk (A'*A) |
time | +38.4% |
stencil/dagger/N=256 (block 256)/neighbors (Clamp) |
time | -37.1% |
array/dagger/N=1024 (block 512)/norm |
time | -38.5% |
array/dagger/N=1024 (block 512)/alloc (rand) |
time | -41.7% |
stencil/dagger/N=256 (block 128)/update (+) |
time | -63.0% |
array/dagger/N=256 (block 256)/transpose (permutedims) |
time | -64.8% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=256 (block 128)/transpose (permutedims) |
time | +136.8% |
Full results and plots (download the benchmark-results-* artifacts).
|
Thanks so much! |
Pinning workflow once Dagger has no
pin_threads!(2026-11-29)Status: proposal only. No script was edited, and nothing was run on the cluster (ssh was not permitted in this session), so
ThreadPinning was NOT tested there.
src/numa.jl(thread_cpus,allowed_cpus,pin_threads!,threads_pinned,numa_threads)stays in the fork's integration branch until the scripts below are switched. Upstream PR #810 became a docs + test PR
(branch
pr/c8-threadpinning-docs) following jpsamaroo's review.How to pin
(
Pkg.add(name="ThreadPinning", version="1"); 0.7.x has no:affinitymask).using ThreadPinning; pinthreads(:affinitymask)before the first Dagger task. It pins default-poolthreads one per CPU inside the CPU mask (numactl/taskset/Slurm binding). Replaces
JULIA_EXCLUSIVE=1, which pins threadito CPUi-1and ignores the mask.addprocsfirst, then split the mask by hand (snippet in docs/src/threadpinning.md);distributed_pinthreads(:cores)ignores the mask.mpiexec --bind-to .../srun --cpu-bind); each rank callspinthreads(:affinitymask)and pins inside its binding.No
JULIA_EXCLUSIVE=1with several ranks per node (all ranks pin onto the same cores).-t N,0(or pin all threads, see the docs page) until upstream PR Register default-pool ThreadProcs and leave interactive threads free #841 is merged.Replacements for the fork helpers
Dagger.pin_threads!()pinthreads(:affinitymask)Dagger.thread_cpus()getcpuids()(0-based CPU id per Julia thread)Dagger.threads_pinned()all(getispinned())Dagger.allowed_cpus()findall(isone, getaffinity()) .- 1Dagger.numa_threads()getnumanodes()(NUMA node per thread); as a Dict:Dict(n => findall(==(n), getnumanodes()) for n in unique(getnumanodes()))getcpuid(s),getaffinity,getnumanode(s),getispinned,ispinned,numa,nnuma,pinthreads); not executed, and the semantics ofgetnumanodes()againstnuma_threads()were not compared.Script lines that have to change (nothing edited)
Pinning now happens from Julia: a one-file
pin.jl(using ThreadPinning,pinthreads(:affinitymask)) given asjulia -L pin.jl; in distributed scripts run it afteraddprocs.LLM_info/bench/numa_probe.sbatch:2,8,10: dropJULIA_EXCLUSIVE=$EXCL; setPINARG=""orPINARG="-L $PWD/pin.jl"per loop value and pass$PINARGtojulia. The grep patternthread_cpus|numa_|threads_pinnedmust follow the new printed names (numa_probe.jlitself calls no Dagger helper).LLM_info/bench/ss/ss_tf_numa.sbatch:3,16: variantspin/both(EX=1): drop theJULIA_EXCLUSIVE=$EXprefix, usePINARG=$([ $EX = 1 ] && echo "-L $PWD/pin.jl")andjulia --project=$ENVD -t 64 $PINARG ....LLM_info/bench/otus_scaling/ss_run.sbatch:24: removeJULIA_EXCLUSIVE=${PIN:-0}; add$PINARGafter-t $TwithPINARG=$([ "${PIN:-0}" = 1 ] && echo "-L $R/pin.jl").LLM_info/bench/otus_scaling/ss_series.sbatch:11,17,19:PIN=1stays; update the comment (the first CPUs of the allowed mask are used in order, not fixed CPUi-1).Also print
getcpuids()andall(getispinned())in each job so the log shows pinning took effect.INSTRUCTIONS_FOR_APP_AGENT.mdandpdf/Dagger_MPI_complete_EN.mdmention the helpers and need a note whensrc/numa.jlgoes (src/has no other user).Cluster prerequisite
Add ThreadPinning to
/data/dagger-*-envand the Otus scratch environments (stock and fork), so both revisions pin identically. Not tested there. First check on a node:taskset -c 4-7 julia -t 4 -e 'using ThreadPinning; pinthreads(:affinitymask); println(getcpuids())'.