From 771a6b9dd3a49bedb9fa388ca9e436ca79c4201d Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Mon, 30 Nov 2026 21:54:22 -0700 Subject: [PATCH] Make benchmark subprocess thread pools explicit Julia 1.12+ can add an interactive thread to a bare thread count, so a requested two-thread benchmark can register one interactive and one default processor while omitting another default processor on historical Dagger revisions. Use N,0 for benchmark workload and Distributed subprocesses on Julia 1.12+, retaining the accepted bare N syntax on 1.10/1.11 and explicit caller pool specifications at the Airspeed boundary. Pin AirspeedVelocity bare-julia launches to the driver executable directory and verify Distributed child versions before loading Dagger. Native 1.10.11 and 1.13.4 controls exercise real pinned Dagger tasks in plain, Distributed and two-rank MPI subprocesses; both CI launch expressions also select the current binary with a deliberately different Julia first on PATH. No scheduler, threshold or production/test thread policy changes. Written by an AI agent on jpsamaroo's review feedback. --- AGENTS.md | 15 +++++++++++++++ benchmark/benchmarks.jl | 8 +++++--- benchmark/ci.jl | 36 ++++++++++++++++++++++-------------- benchmark/threadpools.jl | 20 ++++++++++++++++++++ benchmark/worker.jl | 14 +++++++++++++- 5 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 benchmark/threadpools.jl diff --git a/AGENTS.md b/AGENTS.md index ad8c5740e..c2575226b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1217,3 +1217,18 @@ this section verbatim). Each entry is one bullet starting with `- `. the protocol alone is not enough for them. Test with a remote reader *and* a remote writer, in both orders: in one process every slot is the argument itself, so none of this is visible. + +109. **Specify both thread pools for benchmark subprocesses.** On Julia 1.13, + `--threads=2` starts two default threads plus an interactive thread. A + benchmark that records only `Threads.nthreads()` can therefore report two + threads while Dagger revisions that register physical IDs `1:2` include the + interactive thread and omit a default thread. Launch benchmark and + Distributed worker subprocesses with `--threads=N,0` so the requested + compute count also describes their physical default-thread IDs. Julia + 1.10/1.11 reject the explicit zero, so retain their bare `N` spelling, + which already disables the interactive pool. Preserve deliberately supplied + pool specifications. This is a benchmark topology control, separate from + production interactive-thread placement policy. AirspeedVelocity resolves + bare `julia` through `PATH`, so select the driver's executable directory + around its calls before choosing version-dependent flags. Check actual + Distributed worker versions rather than assuming a remote path matches. diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index 303f79e32..19f498559 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -94,8 +94,9 @@ # operators (keeps tile counts bounded at large N). Defaults to "16". # - BENCHMARK_PROCS: Worker/thread topology, as "numprocs:numthreads". This # starts `numprocs` Distributed workers *inside the benchmark worker process*, -# each with `numthreads` threads. Defaults to no extra workers (everything -# runs on the worker process, which uses the orchestrator's thread count). +# each with `numthreads` default-pool threads and no interactive pool. +# Defaults to no extra workers (everything runs on the worker process, +# which uses the orchestrator's default-pool thread count). # On Distributed CPU, the array and linalg suites also run addition into a # cyclic destination and LU! on a fresh cyclic workspace. Their matching # allocating leaves retain the scheduler's placement choices. Run the @@ -171,6 +172,7 @@ using BenchmarkTools import JSON3 +include(joinpath(@__DIR__, "threadpools.jl")) # --- AirspeedVelocity integration ------------------------------------------ # AirspeedVelocity calls `run(SUITE)` and serializes whatever it returns. We run @@ -204,7 +206,7 @@ const PROC_TIMEOUT = parse(Float64, get(ENV, "BENCHMARK_PROC_TIMEOUT", "3600")) const POLL = 0.05 worker_cmd() = - `$JULIA_BIN --project=$(Base.active_project()) --startup-file=no -t$NTHREADS $WORKER_SCRIPT $WORKDIR` + `$JULIA_BIN --project=$(Base.active_project()) --startup-file=no --threads=$(benchmark_thread_spec(NTHREADS)) $WORKER_SCRIPT $WORKDIR` function _atomic_write(path, data) tmp = path * ".tmp" diff --git a/benchmark/ci.jl b/benchmark/ci.jl index b0aeee518..ef7a0eacf 100644 --- a/benchmark/ci.jl +++ b/benchmark/ci.jl @@ -25,7 +25,10 @@ # change must clear before it is called a regression or an improvement # (default "1.0"). See "Regression check" below; set to "0" to disable the # spread gate; the five-sample and confirmation requirements still apply. -# - BENCHMARK_CI_THREADS: Julia threads for each benchmark run (default "4"). +# - BENCHMARK_CI_THREADS: Airspeed runner thread specification (default "4"). +# Bare counts disable its interactive pool; explicit pool specifications such +# as "2,1" are passed through unchanged. Workload subprocesses use the runner +# default-pool count with no interactive pool. # - BENCHMARK_OUTPUT_DIR: where JSON/plots/report are written # (default "benchmark_results"). @@ -39,6 +42,7 @@ using AirspeedVelocity using JSON3 using AirspeedVelocity.Utils: benchmark, load_results using AirspeedVelocity.TableUtils: create_table +include(joinpath(@__DIR__, "threadpools.jl")) const PROJECT_DIR = abspath(joinpath(@__DIR__, "..")) const SCRIPT = joinpath(@__DIR__, "benchmarks.jl") @@ -85,16 +89,18 @@ mkpath(OUTPUT_DIR) @info "Benchmarking $CUR_REV vs $BASE_REV" project = PROJECT_DIR script = SCRIPT -benchmark( - "Dagger", - [BASE_REV, CUR_REV]; - output_dir = OUTPUT_DIR, - script = SCRIPT, - path = PROJECT_DIR, - extra_pkgs = EXTRA_PKGS, - exeflags = `-t $CI_THREADS`, - tune = false, -) +with_benchmark_julia() do + benchmark( + "Dagger", + [BASE_REV, CUR_REV]; + output_dir = OUTPUT_DIR, + script = SCRIPT, + path = PROJECT_DIR, + extra_pkgs = EXTRA_PKGS, + exeflags = `--threads=$(benchmark_thread_spec(CI_THREADS))`, + tune = false, + ) +end include(joinpath(@__DIR__, "compare.jl")) function load_sampled_results(dir) @@ -154,9 +160,11 @@ if any(entry -> entry[2] == "time", comparison.regressions) confirmation_dir = joinpath(OUTPUT_DIR, "confirmation") mkpath(confirmation_dir) @info "Confirming timing regressions with a fresh comparison in reversed revision order" - benchmark("Dagger", [CUR_REV, BASE_REV]; output_dir=confirmation_dir, - script=SCRIPT, path=PROJECT_DIR, extra_pkgs=EXTRA_PKGS, - exeflags=`-t $CI_THREADS`, tune=false) + with_benchmark_julia() do + benchmark("Dagger", [CUR_REV, BASE_REV]; output_dir=confirmation_dir, + script=SCRIPT, path=PROJECT_DIR, extra_pkgs=EXTRA_PKGS, + exeflags=`--threads=$(benchmark_thread_spec(CI_THREADS))`, tune=false) + end confirmation = load_sampled_results(confirmation_dir) repeated = compare_benchmarks(confirmation[BASE_REV], confirmation[CUR_REV]; comparison_options...) comparison = confirm_timing_regressions(comparison, repeated) diff --git a/benchmark/threadpools.jl b/benchmark/threadpools.jl new file mode 100644 index 000000000..dfbd12934 --- /dev/null +++ b/benchmark/threadpools.jl @@ -0,0 +1,20 @@ +# Shared by the CI driver, benchmark orchestrator and Distributed worker setup. +# They launch the current Julia executable. Remote deployments must provide +# that same Julia version at the executable path used by Distributed. +function benchmark_thread_spec(threads) + spec = string(threads) + # Preserve an explicitly requested pool topology (and let Julia validate it). + occursin(',', spec) && return spec + # Julia 1.10/1.11 reject an explicit zero interactive count; their bare + # default-pool count already leaves the interactive pool disabled. + return VERSION >= v"1.12.0-DEV" ? "$spec,0" : spec +end + +# AirspeedVelocity launches bare `julia`, including its load-time samples. +# Keep that binary aligned with the VERSION used to select the thread syntax. +function with_benchmark_julia(f) + path = get(ENV, "PATH", "") + selected = isempty(path) ? Sys.BINDIR : + string(Sys.BINDIR, Sys.iswindows() ? ';' : ':', path) + return withenv(f, "PATH" => selected) +end diff --git a/benchmark/worker.jl b/benchmark/worker.jl index c02db363c..641e120b7 100644 --- a/benchmark/worker.jl +++ b/benchmark/worker.jl @@ -30,6 +30,7 @@ using Dates, Random, Statistics, LinearAlgebra, InteractiveUtils import JSON3 include(joinpath(@__DIR__, "common.jl")) +include(joinpath(@__DIR__, "threadpools.jl")) const WORKDIR = abspath(ARGS[1]) @@ -51,7 +52,9 @@ else const nt = 1 end -const worker_exeflags = `--project=$(Base.active_project()) -t $nt` +# Keep physical thread IDs and the requested compute-thread count aligned even +# on Julia versions that otherwise add an interactive thread by default. +const worker_exeflags = `--project=$(Base.active_project()) --threads=$(benchmark_thread_spec(nt))` if np > 0 addprocs(np; exeflags=worker_exeflags) end @@ -62,6 +65,15 @@ if haskey(ENV, "BENCHMARK_REMOTES") end end +# The flag spelling is selected by this driver's Julia version. Check the +# actual children too, especially when BENCHMARK_REMOTES names SSH hosts. +for worker in procs() + worker == myid() && continue + worker_version = remotecall_fetch(getfield, worker, Base, :VERSION) + worker_version == VERSION || + error("Benchmark worker $worker runs Julia $worker_version; driver runs $VERSION") +end + @everywhere using Dagger # --- Load acceleration backends (only if requested) ------------------------