Skip to content

Scheduler placement: shared union scopes, cheap candidate ranking, targeted wake-ups - #806

Open
AnnaLena77 wants to merge 13 commits into
JuliaParallel:masterfrom
AnnaLena77:bundle/b5-placement
Open

AnnaLena77 wants to merge 13 commits into
JuliaParallel:masterfrom
AnnaLena77:bundle/b5-placement

Conversation

@AnnaLena77

Copy link
Copy Markdown
Collaborator

Category 1 (pure improvement), placement ordering: Internal changes to how the scheduler ranks candidate processors and wakes runners. No new API. One commit can change which candidate is tried first when costs differ slightly, and the wake-up logic changes, so it needs a careful review. It is based on #791, and you are welcome to push to the branch.

Based on #791 (and so on #790): until those are merged this branch also shows their commits; the five commits that belong to this PR are the last five.

  1. Datadeps: every processor of a memory space gets the same UnionScope object, so the compatible-set cache hit ends in a pointer comparison instead of comparing 64 scopes (fork, 64 threads: 22 us per task).
  2. Sch: a union of more than 8 scopes is keyed by length, first and last member instead of objectid (which hashes every member): 11.4 us at 16 threads, 39.9 us at 64 per task (fork). A key by address was tried and is worse, because it pollutes the frequency-ordered cache.
  3. perf: estimate_task_costs! ranks only the 4 cheapest candidates instead of shuffling and sorting all of them (ties stay random). Fan-out of 64 tiny tasks at 64 threads, 6 interleaved rounds: median 11.3 -> 10.7 ms (fork). It changes which candidate is tried first when costs differ slightly; the scheduler only needs the first usable one. New test of the candidate order.
  4. Sched: wake only the runners that can take the enqueued task. Every do_tasks rang every other processor's doorbell, which cost about T^2 lock operations per task. An ExactScope task wakes nobody; otherwise one parked, eligible runner. Fork, 1 process, 50 us bodies, 64 threads: unscoped 3.3k -> 5.6k tasks/s, pinned 5.5k -> 7.2k; within noise at 8 and 16 threads.
  5. Sched: do not read a TaskSpec after handing it to the queue. The previous commit would otherwise read a spec another runner may already have recycled (a TypeError on few threads, and the failure reported under the wrong task id). Regression test via AFTER_ENQUEUE_HOOK fails without the fix and passes with it.

Testing: Scheduler (including the new tests), Uniform Placement, Datadeps and Allocations suites. This changes the wake-up logic; it needs a careful review.

Measured on current master (30fa2e86) with this branch merged into it: (4x AMD Opteron 6272, 64 cores, exclusive node), one process, one run per sample, three rounds with the revisions interleaved in one allocation; medians (min to max).

master this PR
plain @spawn, 16 threads (us/task) 179 (176-190) 129 (127-134)
plain @spawn, 64 threads (us/task) 949 (929-982) 157 (154-159)
@spawn allocations per task, 16 / 64 threads 997 / 17082 269 / 590
Cholesky 8192/256, 16 threads (s) 2.06 (2.06-2.07) 1.83 (1.78-1.85)
Cholesky 8192/256, 64 threads (s) 5.79 (5.65-5.86) 2.34 (2.32-2.37)

This branch includes the commits of #790 and #791, so part of the change comes from those. The suites Scheduler, Thunk, Processors, Task Queues, Mutation, Datadeps and Options also pass on the cluster (7 of 7). Single node only.

AI disclosure: I prepared this change with the help of Claude (Anthropic) and reviewed it myself.
🤖 Generated with Claude Code

The scope Datadeps hands each task depends on the processor only through its
memory space, but get! built one UnionScope per processor, equal in content.
The scheduler's compatible-set lookup then ended every hit in a member-by-
member comparison of 64 scopes: 22 us per task at 64 threads on our cluster (flat
Datadeps Cholesky 8192/256; 1.3 us on a laptop, the cluster's cores are ~7x
slower per primitive). The first processor's scope is now shared with the
others (share_equal_scope), so the comparison is a pointer test.
…heap content key

objectid of a UnionScope hashes every member; Datadeps hands each task a
union of one ExactScope per thread, so the cache lookup cost O(threads) per
task (measured on our cluster, flat Datadeps Cholesky 8192/256: 11.4 us at 16
threads, 39.9 us at 64 threads, of ~190 us per schedule_one!). A union of
more than 8 scopes is keyed by its length and its first and last member,
which stays a function of the contents: the equal union a later Datadeps
region builds finds the earlier region's entry. (A key by address looks
cheaper but pollutes the frequency-ordered cache with 64 never-hit entries
per region; once it is full the new keys are evicted at once and every task
misses: 98 us per task at 64 threads, measured.) The hit test still
compares the scope (===), and a collision of two different unions only
replaces the entry. Everything else keeps objectid.
…all of them

estimate_task_costs! shuffled (randperm!) and sorted every candidate processor
for every unscoped task, although the scheduler takes the first usable one:
O(T log T) per task, 12 -> 24-58 us per task at 8 -> 32-64 threads on our cluster
(Opteron). The scheduler-facing path (costs === nothing) now rotates the
candidates by a random offset and selects the 4 cheapest into the front; ties
stay random, the tail keeps rotation order. The path that returns costs keeps
the full sort. The ordering is a plain function with concrete argument types.

Fan-out of 64 tiny unscoped tasks at 64 threads, spawn only, 6 interleaved
rounds in one allocation: median 11.3 -> 10.7 ms (about 6 % faster, better in
6 of 6 rounds).
After every do_tasks, every other processor's doorbell was rung "to make it steal".
Each woken runner then scanned the queues of all T processors, locking each one:
T wake-ups and ~T^2 lock operations per enqueued task. For a task whose scope is an
ExactScope nobody else can take it at all (proc_in_scope is proc == scope.processor),
and for an unscoped task one thief is enough.

* ExactScope tasks only: no kick.
* Otherwise wake at most one runner per enqueued task, chosen among the runners that
  are parked (ProcessorInternalState.parked, set before the runner looks for work and
  cleared when it takes a task: one that is not parked looks at the queues again by
  itself, so skipping it cannot lose a wake-up) and that could take a task (scope,
  acceleration, free occupancy: the same test the steal scan applies). The starting
  point rotates so the same runners are not always the thieves. The MPI rule
  (stealing_permitted) stays.

One process, no MPI, our cluster (Opteron 6272), tasks/s with 50 us bodies, before -> after,
8 / 16 / 32 / 64 threads (single runs, bench shm_scaling.jl):
  unscoped  6.6k / 4.9k / 5.7k / 3.3k -> 6.0k / 5.1k / 6.0k / 5.6k   (64 threads +69 %)
  pinned    7.0k / 7.2k / 8.3k / 5.5k -> 7.5k / 8.0k / 8.8k / 7.2k   (64 threads +32 %)
With 500 us bodies at 64 threads: unscoped 3.7k -> 4.2k, pinned 5.8k -> 7.5k.
Within noise at 8 and 16 threads, as expected: the wasted work grows with T^2. The
throughput no longer falls between 32 and 64 threads but stays at ~6-8k tasks/s: what
remains is the serial per-task cost of the submitting thread (~125-165 us here).

Tests: thunk, scheduler, processors, uniform-placement, scopes, options, task-queues,
task-affinity, mutation pass (-p 2 -t 2).
The previous commit's do_tasks enqueued a batch and then read each spec again
(scope for the all-pinned check, options.acceleration and est_occupancy for
the wake-up decision). From the moment a spec is in the queue another runner
may take it, run it and recycle it (reset_task_spec! sets scope and options to
nothing, thunk_id to 0), so on few threads with short tasks the scope
assertion threw a TypeError, the wake-up decision used stale values, and
FireTaskSpec reported the failure under first_task.thunk_id, read after the
recycle: id 0, or the id of whatever task had reused the spec, which failed an
innocent bystander.

The decision data (scope, acceleration, occupancy) is now captured in reusable
vectors inside the enqueue loop, while do_tasks still owns the spec, and the
all-pinned check and the kick loop use those; FireTaskSpec reads first_thunk_id
before do_tasks. Skipped (pre-cancelled / already running) tasks no longer
count towards maxkick.

Regression test: AFTER_ENQUEUE_HOOK (one load and compare per batch) lets the
test sleep right after the enqueue; with 2+ threads the batch counter
FIRE_FAILURES must not move. The test fails on the previous commit plus the
hook and passes with the fix.
Review finding 4 on PR JuliaParallel#806 (should-fix): The enqueue docstring now describes a counter
Requested: Attach the existing enqueue docstring to do_tasks again.

Keep the existing documentation next to the function it documents. An
isolated Julia Docs.meta probe on the exact declaration confirmed the
binding moved from KICK_CURSOR back to do_tasks.

Written by an AI agent on jpsamaroo's review feedback.
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.59091% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.48%. Comparing base (46f6315) to head (645782f).

Files with missing lines Patch % Lines
src/sch/Sch.jl 93.87% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #806      +/-   ##
==========================================
+ Coverage   64.35%   64.48%   +0.13%     
==========================================
  Files         126      126              
  Lines       20191    20267      +76     
==========================================
+ Hits        12993    13070      +77     
+ Misses       7198     7197       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Bring the placement branch onto reviewed scheduler and Datadeps fixes.

Written by an AI agent on jpsamaroo's review feedback.
Review finding F3 (should-fix) on PR JuliaParallel#806: Mixed-scope batches can scan every runner and task combination.

Skip pinned task metadata and use broad wakeups if the runner/task cross product exceeds 64 eligibility checks. Read runner occupancy under its queue lock on the selective path. This retains selective wakeups for small batches while bounding filtering work by the batch plus runner counts.

Written by an AI agent on jpsamaroo's review feedback.
Review finding F1 (should-fix) on PR JuliaParallel#806: Placement beyond the fourth candidate no longer follows cost order.

State which candidates are cost-ranked and which retain rotation order; the existing partial-ranking tests cover the implemented ordering.

Written by an AI agent on jpsamaroo's review feedback.
Review finding F6 (should-fix) on PR JuliaParallel#814, shared with PR JuliaParallel#806: Rotating candidates skews choices among tied minima.

Use reservoir sampling within each selection pass. A minimum no longer wins in proportion to the distance from the previous minimum. The regression places two minima behind unequal gaps and checks their first-choice counts.

Written by an AI agent on jpsamaroo's review feedback.
Follow-up on the bounded wakeup scan in PR JuliaParallel#806: A fixed 64-probe cap would wake every runner for a single task on a pool larger than64, restoring the scalability cliff this PR removes.

Bound filtering by eight times the combined runner and task counts instead. Singleton batches retain a linear selective scan; large cross-products still fall back to broad waking.

Written by an AI agent on jpsamaroo's review feedback.
jpsamaroo added a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 30, 2026
Review finding F3 (should-fix) on PR JuliaParallel#806: Mixed-scope batches can scan every runner and task combination.

Skip pinned task metadata and use broad wakeups if the runner/task cross product exceeds 64 eligibility checks. Read runner occupancy under its queue lock on the selective path. This retains selective wakeups for small batches while bounding filtering work by the batch plus runner counts.

Written by an AI agent on jpsamaroo's review feedback.
jpsamaroo added a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 30, 2026
Review finding F1 (should-fix) on PR JuliaParallel#806: Placement beyond the fourth candidate no longer follows cost order.

State which candidates are cost-ranked and which retain rotation order; the existing partial-ranking tests cover the implemented ordering.

Written by an AI agent on jpsamaroo's review feedback.
jpsamaroo added a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 30, 2026
Review finding F6 (should-fix) on PR JuliaParallel#814, shared with PR JuliaParallel#806: Rotating candidates skews choices among tied minima.

Use reservoir sampling within each selection pass. A minimum no longer wins in proportion to the distance from the previous minimum. The regression places two minima behind unequal gaps and checks their first-choice counts.

Written by an AI agent on jpsamaroo's review feedback.
jpsamaroo added a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 30, 2026
Follow-up on the bounded wakeup scan in PR JuliaParallel#806: A fixed 64-probe cap would wake every runner for a single task on a pool larger than64, restoring the scalability cliff this PR removes.

Bound filtering by eight times the combined runner and task counts instead. Singleton batches retain a linear selective scan; large cross-products still fall back to broad waking.

Written by an AI agent on jpsamaroo's review feedback.
Independent review of PR JuliaParallel#814 found that the shared JuliaParallel#806 scope optimization scans every cached scope on each new worker/device processor miss.

Stop after16 entries. Scope sharing remains an optional identity reuse optimization; missing a later match does not alter eligible processors. A counted1024-entry cache regression verifies a bounded miss and immediate reuse of an early match.

Validation: the counted miss reproduces 1,024 visits before versus 17 fetched entries (16 comparisons) afterwards. Both scope-sharing variants allocate 0 bytes across 1,000 warmed calls (minimum of three runs).

Written by an AI agent on jpsamaroo's review feedback.
jpsamaroo added a commit to AnnaLena77/Dagger_AL.jl that referenced this pull request Nov 30, 2026
Independent review of PR JuliaParallel#814 found that the shared JuliaParallel#806 scope optimization scans every cached scope on each new worker/device processor miss.

Stop after16 entries. Scope sharing remains an optional identity reuse optimization; missing a later match does not alter eligible processors. A counted1024-entry cache regression verifies a bounded miss and immediate reuse of an early match.

Written by an AI agent on jpsamaroo's review feedback.
Independent review of PR JuliaParallel#806 found that only the internal cost estimator docstring had been updated. The scheduler manual still promised the globally least costly eligible processor. Describe the four-best prefix and rotated fallback order where users read the scheduling policy.

Written by an AI agent on jpsamaroo's review feedback.

This branch has not been deployed

No deployments
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