Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b23806c
MPI: run tasks that asked for no thread on any free thread of their r…
AnnaLena77 Nov 26, 2026
9efc465
mpi: a task on a communicator of one rank skips the status/type protocol
AnnaLena77 Nov 26, 2026
c0909f2
mpi: keep freed tile memory in the heap (mallopt) when the accelerati…
AnnaLena77 Nov 26, 2026
2bf92a2
mpi: the broadcast relay is migratable from 4 default threads on
AnnaLena77 Nov 26, 2026
7e6c0b3
mpi: a migratable broadcast relay no longer spins on yield()
AnnaLena77 Nov 26, 2026
2429986
Let an acceleration complete a task without a thunk (elide_task!)
AnnaLena77 Oct 16, 2026
f574158
MPI: owner elision with failure-only task status
AnnaLena77 Oct 16, 2026
1529bdf
test: owner elision (test/mpi/elide.jl)
AnnaLena77 Oct 16, 2026
f7727ae
MPI: elide tasks scoped to a whole rank, not only to one thread
AnnaLena77 Oct 16, 2026
eb28578
MPI: place tasks without a scope at spawn time so that they can be el…
AnnaLena77 Oct 17, 2026
68e413e
MPI: elide a task whose chunk arguments carry a scope restriction tha…
AnnaLena77 Oct 18, 2026
dcdd50f
MPI: record where the blocks of an array live, so a task that reads o…
AnnaLena77 Oct 18, 2026
69d5d1e
MPI: compute the scope chain of chunk arguments only when a chunk car…
AnnaLena77 Oct 18, 2026
1281f28
MPI: type the processor `elide_task!` works with
AnnaLena77 Oct 18, 2026
dc36340
MPI: read DATADEPS_THUNK_ID once in take_ref_id!
AnnaLena77 Oct 18, 2026
afd80d2
MPI: plan a rank-scoped task on a foreign rank as cheaply as an Exact…
AnnaLena77 Nov 26, 2026
aaa4192
Scopes: constrain(::UnionScope, ::AnyScope) is the union itself
AnnaLena77 Oct 23, 2026
8fadfc0
MPI: an elided task's placeholder names the processor its owner runs …
AnnaLena77 Nov 26, 2026
a7b8cef
Owner elision: switch it with Dagger.elide_foreign_tasks!, not an env…
AnnaLena77 Nov 27, 2026
6368a88
test: owner elision is off by default and nothing is elided while it …
AnnaLena77 Nov 27, 2026
859a159
Owner elision: changing the switch waits for the tasks already submitted
AnnaLena77 Nov 27, 2026
58761b9
Owner elision: world communicator only, and document it
AnnaLena77 Nov 27, 2026
74e45eb
MPI: a task failure is broadcast only under a valid tag, and the erro…
AnnaLena77 Nov 27, 2026
8741fa9
Create ThreadProcs for the default thread pool, not 1:nthreads()
jpsamaroo Nov 28, 2026
ebc75f2
procgrid: assign worker IDs to each worker's first default thread
jpsamaroo Nov 28, 2026
59f827a
MPIExt: run spectator copies on a default-pool thread
jpsamaroo Nov 28, 2026
60dfb7a
AGENTS.md: thread 1 is not always a Dagger thread
jpsamaroo Nov 28, 2026
9c080ee
Show how to migrate exact CPU scopes to default-pool threads
jpsamaroo Nov 29, 2026
0ec9b89
Resolve each worker once per integer processor grid
jpsamaroo Nov 29, 2026
6e38727
test: exercise an MPI copy with a separate spectator
jpsamaroo Nov 30, 2026
5450ce2
test: assign DArray tiles to a worker with a different thread pool
jpsamaroo Nov 30, 2026
e77e73a
Merge master into jps/threadproc-default-pool
jpsamaroo Nov 30, 2026
1e6fc50
Merge master into jps/threadproc-default-pool
jpsamaroo Nov 30, 2026
d63a9d5
test: assert processor placement inside the subprocess
jpsamaroo Nov 30, 2026
a94843c
test: use exact scopes to exercise each Datadeps processor
jpsamaroo Nov 30, 2026
d5aad8c
Merge commit 'a94843cc' into jps/review/pr815
jpsamaroo Nov 30, 2026
a789e4b
Merge remote-tracking branch 'origin/master' into jps/review/pr815
jpsamaroo Nov 30, 2026
f427447
Leave MPI allocator tuning to an explicit application call
jpsamaroo Nov 30, 2026
105bdf4
Share the CPU kernel invocation between pinned and migratable tasks
jpsamaroo Nov 30, 2026
70072de
Report the thread executing an MPI CPU processor query
jpsamaroo Nov 30, 2026
784d613
Check MPI thread eligibility with cached local scope membership
jpsamaroo Nov 30, 2026
71ac4c9
Specify the fixed-thread contract for pooled task launch hooks
jpsamaroo Nov 30, 2026
1eda4da
Preserve equivalent scope identities while caching MPI membership
jpsamaroo Nov 30, 2026
85c40a4
Document the normalized union membership hook contract
jpsamaroo Nov 30, 2026
736baa8
Merge master while preserving owner-elision submission hooks
jpsamaroo Nov 30, 2026
da20106
Match taint-scope hashing to its existing content equality
jpsamaroo Nov 30, 2026
a815d4c
Rebuild derived union-scope metadata after serialization
jpsamaroo Nov 30, 2026
8108871
Refresh cached scope tuples while retaining equal membership storage
jpsamaroo Nov 30, 2026
0d1cef2
Integrate validated MPI processor and scope prerequisites
jpsamaroo Nov 30, 2026
4294f76
Replace migratable pool slots pinned by async payloads
jpsamaroo Dec 1, 2026
176a605
Keep owner-elision failure state alive with task and result handles
jpsamaroo Dec 1, 2026
ab16c90
Apply owner elision to bulk submissions in dependency order
jpsamaroo Dec 1, 2026
9a6ad55
Select the first canonical elision candidate without copying and sorting
jpsamaroo Dec 1, 2026
33401b5
Keep free CPU execution inside extension compatibility constraints
jpsamaroo Dec 1, 2026
cd2b817
Preserve user options when pinning a proven elision placement
jpsamaroo Dec 1, 2026
76b7915
Wait for the receiver before sending an elided task argument
jpsamaroo Dec 1, 2026
f7270cf
Keep MPI request buffers alive until a failed wait completes cleanup
jpsamaroo Dec 1, 2026
f7eae29
Integrate free-CPU compatibility and reusable-slot retirement fixes
jpsamaroo Dec 1, 2026
d1508b6
Exercise GPU owner-elision metadata fallback in every shared backend …
jpsamaroo Dec 1, 2026
c552464
Inherit the reviewed relay scope and overlap regression repairs
jpsamaroo Dec 1, 2026
4625151
Keep checkpoint callbacks on every MPI rank
jpsamaroo Dec 1, 2026
6408686
Keep captured owner-elision protocol ahead of return inference
jpsamaroo Dec 1, 2026
6805d0b
Merge captured owner-failure state before validating broadcast tags
jpsamaroo Dec 1, 2026
67eb43f
Keep stolen Python calls on their GIL-owning thread
jpsamaroo Dec 1, 2026
2c53299
Tolerate absent execution options in failure notifications
jpsamaroo Dec 1, 2026
860e953
Use the selected Distributed provider in failure-hook tests
jpsamaroo Dec 1, 2026
7c6670b
Assert MPI free-thread progress before result delivery
jpsamaroo Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,125 @@ 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. **Thread 1 is not always a Dagger thread.** Julia numbers interactive
threads first and, since 1.12, starts one by default (`-t N` means N
default threads plus one interactive; `-t N,1` does the same on 1.10 and
1.11). Thread 1 is then interactive, the main task and REPL run on it, and
the default pool is threads `2:N+1`. `Threads.nthreads()` counts only the
default pool, so `1:nthreads()` is the wrong set: registering ThreadProcs
for it ran Dagger tasks on the interactive thread and never on the last
default thread. ThreadProcs come from `default_pool_tids()`; where code
means "the first thread", use `first_default_tid()` (or, for another
worker, its lowest-tid ThreadProc), never a literal `1`. A scope naming a
thread with no processor (`ExactScope(ThreadProc(1, 1))`) fails to
schedule rather than falling back, so a stray literal breaks only on
configurations with an interactive thread. In CI those are the 1.12+
multithreaded jobs (`-t auto`) and MPI ranks (`--threads=2`), not 1.10/1.11
or the distributed job (`JULIA_NUM_THREADS=1`); the processors suite runs a
`-t 2,1` subprocess so every version covers it.

110. **Start Distributed test workers before the first eager Dagger task.**
`eager_context()` takes its worker list from `procs()` when it is first
created. A local warmup or a processor probe that spawns a task can
initialize it before the test calls `addprocs`. The workers will
then appear in Distributed's list while exact Dagger scopes naming them
fail to schedule. Launch and load Dagger on the workers first, or use
`Dagger.addprocs!(ctx, workers)` to extend an existing context.

111. **Mutable metadata changes immutable scope identity.** Adding a `Set` field
to `UnionScope` makes separately constructed scopes unequal under `===`,
even when their retained tuples and `==` results match. The scheduler
keys compatible-processor entries with `objectid(scope)` and checks `===`,
so that change loses reuse across equivalent regions. Keep retained
membership sets in an external bounded cache and put only deterministic
immutable metadata in the scope. Check fresh constructor identity and
compatible-set identity, not just equality. A hot cache key must also avoid
indexing an abstract `Tuple`: that boxes its immutable elements. Retain a
content hash at construction instead, and measure the lookup allocations.
Derived hashes must be rebuilt after serialization because member
identities can change. Do not serialize cached identity hashes as data.
Specializing a function on a large scope tuple also incurs its full tuple
ABI cost: a three-member fingerprint prototype took 18 s to compile at 1024
members and its lookup scaled with tuple size despite zero allocations.

112. **An elided result's failure protocol belongs to its handles.** A live
optimization flag cannot decide whether an existing MPI result checks for
poison: disabling elision after submission otherwise strands nonowners and
desynchronizes later generic fetch tags. Capture the protocol at root
submission, retain its failure state through the DTask and every result
MPIRef, and keep relay registration weak. Failure delivery may precede a
lagging rank's submission; retain only those early messages until ordered
root registration reaches their task id. Generate that id after metadata
hooks finish, so reentrant submission cannot skip a registration gap.
A per-task checkpoint hook makes every rank a participant, even when its
result is only metadata there. Reject checkpointed tasks after option
defaults are applied; elision must preserve each rank's callback.
Captured failure-only mode also precedes inference-based broadcast planning:
an explicitly declared result can infer as `Union{}` when it always throws,
but elided ranks still cannot consume an ordinary metadata/error FIFO slot.

113. **An MPI source may reach a later argument before its receiver.** Moves
are ordered within each rank, not across ranks: a spectator of argument 1
can already post argument 2's rendezvous send while the owner still waits
for argument 1. If argument 1 fails, the owner never receives argument 2;
MPI.Cancel does not guarantee that unmatched send will complete. Failure-only
owner elision therefore waits for receiver readiness before posting each
cross-rank argument. Route readiness through the independent metadata relay,
and make readiness waits poisonable, so no data request depends on a peer
that already abandoned the task. Preserve live request buffers until MPI
completes or cancels their transfer when an active wait throws.

114. **Async payloads can permanently pin a reusable task.** A cache setup
callback runs only when its slot is created. A later payload that schedules
`@async` makes that Task sticky, so a pool advertised as migratable can
silently accumulate pinned slots. Retire a formerly migratable slot that
becomes sticky; do not unset sticky while its children may still rely on
the affinity. Close its channel before publishing readiness, and replace
closed slots on dispatch, so a new payload cannot be lost during retirement.

115. **Free-thread execution still needs processor compatibility.** A broad
MPI scope does not imply that an extension's `iscompatible_func` or
`iscompatible_arg` accepts every CPU thread. Before making a task
migratable, check those predicates across its rank's CPU candidates with
the scheduler's function/argument types. Otherwise a logically compatible
selected processor can execute on an incompatible physical thread. Test
restrictive hooks while their sole eligible thread is busy.

116. **Stolen Python work still needs Python's GIL.** The CPU work stealer's
broad compatibility predicate can select a Python callable even though
direct placement prefers `PythonProcessor`. Registering only default-pool
CPU threads exposes this when the GIL belongs to interactive thread 1.
Delegate typed `ThreadProc`/`Py` execution to the GIL-safe Python executor,
retaining CPU profiling and exception handling. Use a private result per
offloaded call: PythonCall's shared reply channel can mix concurrent or
cancelled callers, and its error printer runs on the receiving thread
without the GIL. Remember the interpreter's actual initialization thread
rather than assuming thread 1. A one-shot task there can return the original
captured exception as a value, without formatting it there. A successful
direct-placement test does not exercise the stealing dispatch. Do not give
the offloaded task pooled Dagger TLS: cancellation can recycle that metadata
while Python is still finishing. Copy only the logging flag and scalar ID.

117. **Failure notifications must tolerate absent execution options.** A
`Thunk`'s options are optional, and dependency failure propagation visits
thunks without scheduling them first. A newly added acceleration hook must
check for missing options before selecting an acceleration; throwing there
aborts the scheduler before downstream futures receive the original error.
Exercise the complete failure/future path, as well as a positive accelerated
notification and duplicate-completion suppression. Build test channels with
Dagger's selected Distributed provider so their concrete transport types
match the scheduler under both Distributed and DistributedNext.

118. **Assert free-thread progress inside the kernel, before result delivery.**
Timing `fetch` in an MPI scheduling test includes result metadata and
broadcast progress after the kernel has run. Keep an explicitly pinned
thread occupied behind a rank-local atomic gate and record whether a
broad-scope kernel runs before release. Waiters must sleep, release the
gate in `finally`, and give the non-yielding busy kernel a bounded escape
deadline. Record wait statuses while occupied, then report assertions only
after release. In the forced-bound control, reporting an assertion before
`finally` deferred release past the busy kernel's watchdog. Fetch every
busy task before resetting shared test state. An
exact-scope negative control must run only after release. This distinguishes
execution progress from delivery latency without relaxing a speed bound.
27 changes: 18 additions & 9 deletions docs/src/darray.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ The `assignment` argument accepts the following values:
* `AbstractArray{<:Int, N}`:

* Provide an integer **N**-dimensional array of worker IDs. The dimension **N** must match the number of dimensions of the `DArray`.
* Dagger maps blocks to worker IDs in a block-cyclic manner according to this processor-array. The block at index `(i,j,...)` is assigned to the first CPU thread of the worker with ID `assignment[mod1(i, size(assignment,1)), mod1(j, size(assignment,2)), ...]`. This pattern repeats block-cyclically across all dimensions.
* The block at index `(i,j,...)` is assigned to the first default-pool CPU thread of the worker with ID `assignment[mod1(i, size(assignment,1)), mod1(j, size(assignment,2)), ...]`. This pattern repeats block-cyclically across all dimensions.

* `AbstractArray{<:Processor, N}`:

* Provide an **N**-dimensional array of `Processor` objects. The dimension **N** must match the number of dimensions of the `DArray` blocks.
* Blocks are mapped in a block-cyclic manner according to the `Processor` objects in the assignment array. The block at index `(i,j,...)` is assigned to the processor at `assignment[mod1(i, size(assignment,1)), mod1(j, size(assignment,2)), ...]`. This pattern repeats block-cyclically across all dimensions.
* Each explicit `ThreadProc(worker, tid)` must name a registered default-pool thread on that worker. If existing code uses `ThreadProc(worker, 1)` to mean the first CPU thread, use an integer worker assignment or look up its registered CPU processors as shown below.

#### Examples and Usage

Expand All @@ -265,7 +266,10 @@ The `assignment` argument works similarly for `DArray`, `DVector`, and `DMatrix`

* `rand`, `randn`, `sprand`, `ones`, `zeros`: Functions to create DArrays with initial values, also supporting `assignment`.

Here are some examples using a setup with one master process and three worker processes.
Here are some examples using one master process and three worker processes. The
sample outputs show a configuration without interactive threads. Julia assigns
interactive thread IDs first when that pool is enabled, so the default-pool IDs
can differ across workers.

First, let's create some sample arrays for `distribute` (and constructor functions):

Expand Down Expand Up @@ -419,7 +423,7 @@ M = zeros(5, 5, 5) # 3D array
# distribute(sprand(7,11, 0.2), Blocks(2, 2), assignment_2d)
```

The assignment is an integer matrix of worker IDs, the blocks are assigned in block-cyclic manner to the first CPU thread of each worker. The assignment for `Ad` (and `Rd`) would be:
The assignment is an integer matrix of worker IDs. Blocks are assigned in a block-cyclic manner to the first default-pool CPU thread of each worker. The assignment for `Ad` (and `Rd`) would be:

```julia
4×6 Matrix{Dagger.ThreadProc}:
Expand All @@ -431,21 +435,26 @@ M = zeros(5, 5, 5) # 3D array

4. **Block-Cyclic Assignment with Processor Array:**

This example assumes at least three default-pool threads on each process.

```julia
assignment_2d = [Dagger.ThreadProc(3, 2) Dagger.ThreadProc(1, 1);
Dagger.ThreadProc(4, 3) Dagger.ThreadProc(2, 2)]
cpu_procs(worker) = sort!([p for p in Dagger.get_processors(Dagger.OSProc(worker))
if p isa Dagger.ThreadProc]; by=p -> p.tid)
cpus1, cpus2, cpus3, cpus4 = cpu_procs.(1:4)

assignment_2d = [cpus3[2] cpus1[1]; cpus4[3] cpus2[2]]
Ad = distribute(A, Blocks(2, 2), assignment_2d)
# DMatrix(A, Blocks(2, 2), assignment_2d)

assignment_1d = [Dagger.ThreadProc(2,1), Dagger.ThreadProc(3,1), Dagger.ThreadProc(1,1), Dagger.ThreadProc(4,1)]
assignment_1d = [cpus2[1], cpus3[1], cpus1[1], cpus4[1]]
vd = distribute(v, Blocks(3), assignment_1d)
# DVector(v, Blocks(3), assignment_1d)

assignment_3d = cat([Dagger.ThreadProc(1,1) Dagger.ThreadProc(2,1); Dagger.ThreadProc(3,1) Dagger.ThreadProc(4,1)],
[Dagger.ThreadProc(4,1) Dagger.ThreadProc(3,1); Dagger.ThreadProc(2,1) Dagger.ThreadProc(1,1)], dims=3)
assignment_3d = cat([cpus1[1] cpus2[1]; cpus3[1] cpus4[1]],
[cpus4[1] cpus3[1]; cpus2[1] cpus1[1]], dims=3)
Md = distribute(M, Blocks(2, 2, 2), assignment_3d)
# DArray(M, Blocks(2, 2, 2), assignment_3d)
Rd = rand(Blocks(2, 2), 7, 11; assignment=assignment_2d))
Rd = rand(Blocks(2, 2), 7, 11; assignment=assignment_2d)
# distribute(rand(7,11), Blocks(2, 2), assignment_2d)
```

Expand Down
42 changes: 42 additions & 0 deletions docs/src/mpi.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ with rank information:
- `MPIMemorySpace` — a rank-stamped [memory space](data-management.md)
(CPU RAM, or device VRAM) used to track where data resides.

An MPI CPU task whose scope permits every default-pool thread of its rank can
run on any free default-pool thread when its function and arguments are also
compatible with every CPU thread. A scope or extension compatibility predicate
that excludes any of those threads keeps the task on the scheduler's selected
thread. `Dagger.task_processor()`
reports the MPI processor for the thread executing that query; a migratable task
can observe a different thread after yielding. Interactive threads remain outside
the CPU processor pool.

MPI activation leaves process allocator settings unchanged. Applications that
want glibc to retain freed tile buffers can explicitly call `Dagger.tune_malloc!()`;
the setting applies to the whole process and persists after MPI deactivation.

You can enumerate the processors of the cluster (useful for building scopes):

```julia
Expand Down Expand Up @@ -346,6 +359,35 @@ hooks — `Dagger.mpi_device_direct`, `Dagger.mpi_device_sync`,
`Dagger.mpi_library_gpu_aware`, and `Dagger.mpi_remap_space` — are overridable
per backend for advanced setups.

## Skipping tasks a rank takes no part in (owner elision)

Under SPMD every rank plans every task, including tasks it neither runs nor owns
data for. `Dagger.elide_foreign_tasks!(true)` lets such a rank skip the thunk,
scheduling and placeholder execution of a task (it only takes the task id, so ids
and tags stay equal on every rank). It is off by default, and every rank must set
it to the same value at the same point of the program; changing it waits for the
tasks already submitted.

A CPU task is eligible when its result type proves host storage, its owner is
known at submission, it has no explicit tag, and this rank owns none of its
arguments. A rank scope supplies the owner; an unscoped task can use deterministic
placement at submission. Placement uses the scheduler's registered processors,
option defaults, and function/argument compatibility checks. GPU processors and
custom result types retain the normal metadata exchange. A rank-wide CPU scope
still permits execution on a free thread of that rank.

Elision applies to root-task submissions through the ordinary queue and
`spawn_bulk`. Tasks inside Datadeps regions and inside other tasks are never
elided, and neither are tasks of another communicator or tasks submitted while
`check_uniformity!(true)` is on.

The consequence to be aware of: the owner of an elided task reports only
failures. A rank that never fetches the task or consumes its result does not wait
for it and does not notice that it finished or failed; a rank that does consume
it sees the owner's error.
The task and its result handles retain that failure for repeated fetches, including
after elision is disabled. Failure state is released when its last handle dies.

## Collecting and fetching results

`collect(DA)` performs a deterministic, rank-uniform gather: it returns the full
Expand Down
Loading
Loading