Repository navigation
Conversation
PR #792 fixed core Datadeps slot logic (`aliased_object!`), which every acceleration shares, but its only test lived in the MPI suite -- whose own header says acceleration-independent Datadeps behavior belongs in test/datadeps.jl. That left the threads and Distributed configurations, which most users run, untested. The test also created every value on the rank of the task that read it, so it only exercised the in-place path, where the slot is the value itself. The path where #792's bypass actually makes a new slot -- a value copied into another memory space -- ran in no test at all. Move the body into test/noaliasing_defs.jl (as stencil_defs.jl and sparse_defs.jl do) and call it from both entry points, with both planners, in place and across memory spaces (several distinct values landing in one destination space). The across-spaces cases fail with #792's guard removed: every task reads the first value. Also replace the MPI test's header, which cited a private reference, with a description of the scenario. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#792 bypassed the aliased-object cache for bare `NoAliasing` only, by a hard-coded `isa` check. An empty `CombinedAliasing` -- what any struct whose fields all report `NoAliasing` gets, e.g. one wrapping a value declared `NoAliasing` -- has no identity either: every empty one compares equal, so distinct arguments still collided on one cache key and a task silently received another argument's value. The new wrapped-value tests fail this way on master, in place and across spaces, with both planners. Name the property instead: `describes_memory(ainfo)` is `false` for `NoAliasing` and for a `CombinedAliasing` made only of such parts, and the bypass keys on it. Being a generic function, a third-party `AbstractAliasing` that describes no memory can opt in too. `UnknownAliasing` deliberately stays on the cache path. It means "may alias any memory", the opposite of describing none: two arguments with unknown aliasing may be one object reached through different wrappers, and giving each a private copy would split it. Distinct objects with unknown aliasing do still share a key; fixing that needs a real identity (or refusing such arguments), not this bypass. Dagger's own `aliasing` methods throw rather than return it, so only user methods can produce it. The four dependency helpers that skip `NoAliasing` keep testing bare `NoAliasing`: an empty `CombinedAliasing` is tracked today, which keeps successive uses of one such argument ordered, and this change is not meant to alter dependency tracking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… space #792's bypass returned `f(x)` unconditionally. That skipped two things the cached path guarantees: - An object already in the cache's space is its own slot. The cached path registers it as the original and returns it without calling `f`. The bypass called `f` anyway, which inside `move_rewrap` is a same-space transfer -- and for an isbits `Array`, a `libc_backed` copy. A copy in the argument's own space would silently lose writes, since an argument is assumed current where it lives and is never copied back there. The top-level in-place path happens to pass `Returns(data)`, but a wrapper's children reach this point through `move_rewrap` too. - The assertion that a new slot landed in `cache.space`, which catches a backend's move putting a copy in the wrong space. Move the bypass into `unkeyed_object!`, which returns the object itself in its own space and otherwise asserts the copy's space, as the cached path does. The check is a field comparison and allocates nothing. Also correct the comment on `generate_slot!`'s in-place branch, which said the cache always records the object; it no longer does for these arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since #792, a copy made for an argument whose aliasing describes no memory bypasses the aliased-object cache, and the region-end free loop only walks the cache, so such copies were never `unsafe_free!`d (#822). That only matters where `unsafe_free!` does anything: Libc-backed copies of isbits `Array`s and GPU arrays declared `NoAliasing`, which then waited for finalizers that GC pressure does not account for. Simply putting them back in a free loop would not be enough. Their aliasing describes no memory, so `get_write_deps!` returns no tasks for them: the free would race the very tasks reading the copy. (This is what happened to such copies before #792, when they were cached under the shared `NoAliasing` key.) Datadeps orders nothing on such aliasing, so the free has to wait for every task that used the slot. So: - `unkeyed_object!` records each copy in the cache store (`unkeyed`), in creation order, which is rank-uniform. - `generate_slot!` attributes the copies made while building a slot to that slot (a leaf, or a wrapper's children), only when there are any. - `add_reader!`, which every task touching a slot passes through (writers included), records the task as a user of such a slot. - `free_unkeyed_copies!`, called by both planners after their cache free loop, frees each copy with all of its slot's users as syncdeps (plus, in the hierarchical planner, the same shared-chunk owner syncdep the cached frees get, now factored into `push_shared_owner_syncdep!`). The common path pays one extra empty `Vector` per region (in the cache store), two `length` reads per slot and one `nothing` check per recorded reader. The per-slot bookkeeping is allocated lazily, only in regions that make an unkeyed copy. The new test reads a cross-space `Vector` of an isbits type declared `NoAliasing` from two slow tasks. Without the tracking, the copy is still allocated after the region (fails on master); with the free but without the user syncdeps, the readers see it freed under them. Closes #822. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record why `free_unkeyed_copies!` tracks a slot's users itself, and the related, still-open gap it exposed: a consumer of a cross-space `NoAliasing` argument is not ordered after its own copy-to, which only shows up with multithreaded workers. Numbered 100 because lesson 99 (on `type_may_alias`) is pending on another branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Dagger benchmarks:
|
| Backend | Regressions | Improvements | Within noise | Inconclusive time | Suites |
|---|---|---|---|---|---|
| Threads | 0 | 2 | 18 | 6 | 4/4 |
| Distributed | 3 | 0 | 0 | 1 | 4/4 |
| Distributed+Threads | 0 | 0 | 0 | 2 | 4/4 |
| MPI | 0 | 0 | 2 | 2 | 4/4 |
| MPI+Threads | 0 | 1 | 20 | 1 | 4/4 |
| Total | 3 | 3 | 40 | 12 | 20/20 |
Regressions across all backends
| Backend | Benchmark | Metric | Change |
|---|---|---|---|
| Distributed | sparse/dagger/N=1024 (block 64)/cg solve (laplacian) |
memory | +59.7% |
| Distributed | sparse/dagger/N=1024 (block 64)/cg solve (laplacian) |
allocs | +50.7% |
| Distributed | sparse/dagger/N=256 (block 16)/cg solve (laplacian) |
allocs | +25.7% |
Improvements across all backends
| Backend | Benchmark | Metric | Change |
|---|---|---|---|
| MPI+Threads | linalg/dagger/N=1024 (block 512)/matvec (A*x) |
time | -77.7% |
| Threads | stencil/dagger/N=256 (block 128)/alloc (neighbors Wrap) |
time | -63.9% |
| Threads | linalg/dagger/N=256 (block 128)/matmul (A*A) |
time | -40.5% |
Threads (1 process × 4 threads) — 0 regressions, 2 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 6 | 1 |
| linalg | 0 | 1 | 8 | 2 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 1 | 4 | 3 |
Improvements
| Benchmark | Metric | Change |
|---|---|---|
stencil/dagger/N=256 (block 128)/alloc (neighbors Wrap) |
time | -63.9% |
linalg/dagger/N=256 (block 128)/matmul (A*A) |
time | -40.5% |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=1024 (block 512)/matvec (A*x) |
time | +160.9% |
linalg/dagger/N=256 (block 128)/matvec (A*x) |
time | +95.6% |
linalg/dagger/N=256 (block 128)/qr |
time | +85.4% |
stencil/dagger/N=256 (block 256)/multi-expr |
time | +82.2% |
linalg/dagger/N=256 (block 256)/lu |
time | +64.8% |
linalg/dagger/N=256 (block 256)/qr |
time | +58.3% |
stencil/dagger/N=1024 (block 512)/update (+) |
time | +51.3% |
array/dagger/N=1024 (block 512)/alloc (rand) |
time | +40.3% |
stencil/dagger/N=1024 (block 128)/multi-expr |
time | +36.2% |
array/dagger/N=1024 (block 128)/add (X + X) |
time | +36.2% |
array/dagger/N=256 (block 128)/broadcast (X .+ 1) |
time | +25.0% |
linalg/dagger/N=256 (block 128)/syrk (A'*A) |
time | -25.3% |
array/dagger/N=256 (block 128)/transpose (permutedims) |
time | -34.7% |
array/dagger/N=1024 (block 512)/broadcast (X .+ 1) |
time | -36.0% |
stencil/dagger/N=256 (block 128)/multi-expr |
time | -41.0% |
linalg/dagger/N=256 (block 128)/cholesky |
time | -42.5% |
linalg/dagger/N=256 (block 256)/matvec (A*x) |
time | -63.1% |
array/dagger/N=256 (block 128)/norm |
time | -63.4% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=1024 (block 512)/reduce (sum) |
time | +225.5% |
stencil/dagger/N=256 (block 128)/neighbors (Pad) |
time | +218.2% |
stencil/dagger/N=256 (block 256)/alloc (neighbors Wrap) |
time | +179.4% |
linalg/dagger/N=256 (block 128)/lu |
time | +156.8% |
stencil/dagger/N=1024 (block 128)/assign (const) |
time | +83.5% |
linalg/dagger/N=256 (block 256)/syrk (A'*A) |
time | +71.8% |
Distributed (4 processes × 1 thread) — 3 regressions, 0 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 0 | 1 |
| linalg | 0 | 0 | 0 | 0 |
| sparse | 3 | 0 | 0 | 0 |
| stencil | 0 | 0 | 0 | 0 |
Regressions
| Benchmark | Metric | Change |
|---|---|---|
sparse/dagger/N=1024 (block 64)/cg solve (laplacian) |
memory | +59.7% |
sparse/dagger/N=1024 (block 64)/cg solve (laplacian) |
allocs | +50.7% |
sparse/dagger/N=256 (block 16)/cg solve (laplacian) |
allocs | +25.7% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=1024 (block 512)/reduce (sum) |
time | +41.8% |
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 | 2 |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
stencil/dagger/N=1024 (block 512)/alloc (neighbors Wrap) |
time | +78.2% |
stencil/dagger/N=1024 (block 512)/neighbors (Reflect) |
time | +74.0% |
MPI (4 ranks × 1 thread) — 0 regressions, 0 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 1 | 0 |
| linalg | 0 | 0 | 0 | 2 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 0 | 1 | 0 |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
stencil/dagger/N=1024 (block 128)/neighbors (Wrap) |
time | -35.9% |
array/dagger/N=1024 (block 512)/broadcast (X .+ 1) |
time | -41.1% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=256 (block 128)/lu |
time | +444.6% |
linalg/dagger/N=1024 (block 512)/cholesky |
time | +80.1% |
MPI+Threads (2 ranks × 2 threads) — 0 regressions, 1 improvements
| Suite | Regressions | Improvements | Within noise | Inconclusive time |
|---|---|---|---|---|
| array | 0 | 0 | 9 | 0 |
| linalg | 0 | 1 | 5 | 0 |
| sparse | 0 | 0 | 0 | 0 |
| stencil | 0 | 0 | 6 | 1 |
Improvements
| Benchmark | Metric | Change |
|---|---|---|
linalg/dagger/N=1024 (block 512)/matvec (A*x) |
time | -77.7% |
Within noise
| Benchmark | Metric | Change |
|---|---|---|
array/dagger/N=256 (block 128)/broadcast (X .+ 1) |
time | +196.6% |
stencil/dagger/N=1024 (block 512)/assign (const) |
time | +158.0% |
array/dagger/N=256 (block 128)/map (sin.(X)) |
time | +157.2% |
linalg/dagger/N=256 (block 128)/qr |
time | +87.0% |
array/dagger/N=256 (block 256)/transpose (permutedims) |
time | +72.8% |
linalg/dagger/N=256 (block 256)/cholesky |
time | +63.3% |
stencil/dagger/N=256 (block 128)/neighbors (Reflect) |
time | +51.5% |
array/dagger/N=256 (block 256)/map (sin.(X)) |
time | +42.2% |
array/dagger/N=256 (block 128)/reduce (sum) |
time | +41.7% |
linalg/dagger/N=1024 (block 512)/cholesky |
time | +39.8% |
linalg/dagger/N=1024 (block 512)/matmul (A*A) |
time | -36.6% |
stencil/dagger/N=256 (block 256)/neighbors (Pad) |
time | -39.5% |
stencil/dagger/N=256 (block 128)/assign (const) |
time | -40.6% |
array/dagger/N=256 (block 128)/add (X + X) |
time | -44.0% |
array/dagger/N=256 (block 128)/alloc (rand) |
time | -44.3% |
stencil/dagger/N=256 (block 256)/neighbors (Reflect) |
time | -45.5% |
linalg/dagger/N=256 (block 256)/syrk (A'*A) |
time | -45.9% |
stencil/dagger/N=256 (block 256)/update (+) |
time | -45.9% |
array/dagger/N=256 (block 256)/add (X + X) |
time | -46.3% |
array/dagger/N=1024 (block 512)/reduce (sum) |
time | -54.9% |
Inconclusive timing changes
| Benchmark | Metric | Change |
|---|---|---|
stencil/dagger/N=256 (block 256)/alloc (neighbors Wrap) |
time | +54.6% |
Full results and plots (download the benchmark-results-* artifacts).
Such an argument is read-only and passed by value: its slot in another memory space is `move`'s copy of it (or the argument itself, in its own space), and nothing is ever copied into it or back out of it. Datadeps did not hold to that on the cross-space path: - `move_rewrap` let an isbits payload (e.g. a `Vector` of an isbits type declared `NoAliasing`) take the uninitialized-slot path, and `compute_remainder_for_arg!` then scheduled a full copy-to to fill it. The reader is not ordered after that copy -- nothing orders tasks on aliasing that describes no memory -- so it could read the buffer before it was filled. Summing such a `Vector` on another worker gave a wrong sum in 10 of 10 regions with 4-thread workers (0 of 10 now). - Types that do take `move`'s path still got that full copy-to, scheduled into an already-filled slot: a write into data that must not be written. The tests' `NoAliasVal` only worked because they defined a `move!` for it. Now `move_rewrap` (generic and MPI) never gives such an argument an uninitialized slot, and `compute_remainder_for_arg!` never schedules a copy for it in either direction. With no copies there is nothing written to record in `arg_history`/`arg_owner`. The aliasing `move_rewrap` now checks is the query `aliased_object!` was going to make anyway, passed through rather than repeated; `compute_remainder_for_arg!` checks the aliasing it already computes, after its same-space fast path. The tests' `move!` methods for these types now raise, so any copy into one fails the region. A new test sums a cross-space `Vector` of isbits values declared `NoAliasing`. These fail on master and on this PR's previous head: the copy is attempted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Datadeps frees only slots it allocated itself; user data, including an argument serving as its own slot, is never freed by it. `unkeyed_object!` recorded whatever `f` returned for freeing. `move` between two spaces normally copies, and `libc_backed` copies any `Array` it did not allocate, but it returns an already Libc-backed `Array` unchanged: if `move` were ever the identity between two memory spaces of one process, the "copy" would be the user's own object and `free_unkeyed_copies!` would free it. Record the slot only if `slot_holds_value` says its payload is not the argument's own. Only same-process values can be identical, so it compares only when both are local; under uniform (MPI) execution it is always `false`, since the decision must agree across ranks and two spaces of one rank are a host and a device, between which `move` always copies. This runs only when an unkeyed copy is made, never on the common path. Also restate why an argument in its own space is its own slot: it is read-only and passed by value, and the value is already there. The cached path (`aliased_object!` storing `f`'s result in `values`, then the region-end free loop) has the same theoretical hole; it is left for a separate change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lesson 100 described the copy-to race as an open gap; it is fixed now. Restate it around the rule the fix follows (the slot is complete when it is created, and nothing is copied into or out of it), and record why write access to such arguments is not rejected: aliasing is per dependency, and `Deps(X, InOut(:field))` on an isbits field is a documented usage whose aliasing is `NoAliasing`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since NoAliasing arguments are passed by value, an isbits `Vector` declared `NoAliasing` no longer gets an uninitialized (Libc-allocated) slot under MPI either, but `move`'s transferred copy. MPI's slot transfer returns a `Chunk`, which `libc_backed` passes through unchanged, so that copy is an ordinary GC-managed array with nothing to free eagerly, and the free test's "freeable while read" precondition does not hold there. Check only that nothing is left allocated under MPI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jpsamaroo
added a commit
that referenced
this pull request
Nov 28, 2026
… work The brief started with the reviewer's own title and a one-line intent, so a reader had to know the PR already. It now leads with the PR's title (linked) and a 3-4 sentence summary of what the PR changes and why, written by the reviewer in _meta.json (`summary`, required). Also: AGENTS.md's NoAliasing invariant now says field dependencies on a mutable object are memory inside it and may be written (the maintainer's decision on PR #834). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
`Deps(X, InOut(:value))` on an isbits field of a mutable `X` is a
documented usage, but its aliasing was that of the isbits *value*:
`NoAliasing`. So nothing ordered it against other uses of the field, and a
write from another memory space was never copied back -- `X.value` stayed
0 on master (for a plain struct the copy-to even threw, for want of a
`move!`). The field is memory inside `X`, and its dependency now says so.
- `field_aliasing`: for an isbits field of a mutable struct (stored
inline), an `ObjectAliasing` of `sizeof` the field at its `fieldoffset`.
It overlaps `X` as a whole, and is a whole-object unit, so a cross-space
use takes a full copy of just that field, and the write comes back the
same way. Any other field keeps aliasing what it refers to: writes into
that object are tracked, rebinding the field is not. An isbits field of
an immutable struct stays `NoAliasing`; it cannot be written.
- `move_field!`: copies one field, for every struct, from the generic
`move!` fallback (a `dep_mod::Symbol` method would be ambiguous with
every `move!` that specializes the values, `Chunk`s included). The
existing `RefValue` method now forwards to it.
- MPI copies a non-identity `dep_mod` as packed memory spans; the generic
`read_remainder!`/`write_remainder!` now copy a span lying inside a
mutable object's own storage directly, instead of failing to find "the
object holding" it (`find_object_holding_ptr` has no method for an
arbitrary struct).
The new shared test (test/field_deps_defs.jl) writes two fields of one
struct and a `Ref{Int}` in place, from another worker/rank, and with the
reader elsewhere. Every cross-space case errors on master; the MPI case
also errors without the span change. docs/src/datadeps.md now says what a
field dependency covers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An argument (or a field dependency) whose aliasing describes no memory is read-only and passed by value: Datadeps never copies anything into or out of its slots, so a task writing one would have its write silently lost. Raise an `ArgumentError` at planning instead, as Datadeps already does for write access to bare sparse arguments. This was held back until field dependencies had real aliasing: before the previous commit, the documented `Deps(X, InOut(:value))` on an isbits field of a mutable struct came out as `NoAliasing` and would have been rejected. Now only what truly has no writable memory is: a value declared `NoAliasing` (or a struct of nothing else), and an isbits field of an immutable struct. `String`, `Symbol` and `Type` arguments are not affected either way: `type_may_alias` is `false` for them, so they never reach dependency tracking, and a write dependency on one is ignored as before. The check sits where planning already computes the dependency's aliasing (`_populate_arg_deps!`, shared by both planners) and reuses that result: one `describes_memory` call per written dependency, nothing for reads, and the message is built out of line. The aliasing is rank-uniform under MPI, so every rank throws together. The new tests fail without the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Update lesson 100 now that isbits field dependencies of mutable structs have real aliasing: "describes no memory" has to be true of the dependency, and getting that wrong for fields is what lost remote field writes and made write rejection look unsafe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 29, 2026
jpsamaroo
added a commit
that referenced
this pull request
Nov 29, 2026
Reported by the #834 reviewer as a tool problem: REVIEW.md does not state the `_meta.json` `summary` length limit, so reviewers hit E001 by surprise Requested: state the limit where `summary` is described, ideally checked against the validator constants by a test so they cannot drift REVIEW.md step 2 asked for a summary of "3-4 sentences", while `submit` rejects one that is not a single paragraph of 120-900 characters, and a `title` or `intent` longer than one line of 240 characters; a reviewer learned the rules only from the E001 rejection. Step 2 now states all three limits where it describes `summary`. The 240 is a named constant (validate.META_LINE_MAX), like the summary's SUMMARY_WORK_MIN/MAX, and a new test checks that REVIEW.md quotes exactly those constants and that the minimum is the one enforced, so changing a limit without the text fails the suite. 97 tests pass on Python 3.14 and 3.11. Written by an AI agent on jpsamaroo's review feedback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
jpsamaroo
added a commit
to AnnaLena77/Dagger_AL.jl
that referenced
this pull request
Nov 29, 2026
…d its slot Review finding 1 on PR JuliaParallel#833 (blocker): Copies of NoAliasing arguments are freed at region end without waiting for the tasks reading them (use-after-free) Requested: Make the region-end free of each CopyKey copy wait for every task that used that slot, by porting PR JuliaParallel#834's per-slot user list (UnkeyedSlot / add_unkeyed_user! / free_unkeyed_copies!, branch jps/review/pr792 commit af59cd7) or an equivalent wait attached to the CopyKey free. Keep it rank-uniform under MPI. The region-end free loops take a buffer's syncdeps from dependency tracking, which orders nothing on bare NoAliasing (get_write_deps! returns at once). So the unsafe_free! of a CopyKey copy waited for nothing and ran while the copy's readers were still running. This ports JuliaParallel#834's per-slot user list onto this PR's CopyKey design, rather than adding a second free loop: - generate_slot! attributes each CopyKey copy made while building a slot to that slot (a leaf argument's slot, or a wrapper slot's children), by scanning the cache keys appended during the call. - add_reader!, which every task touching a slot passes through (writers and copy tasks included), records the task as a user of such a slot. - Both planners' existing free loops add the slot's users to a CopyKey copy's syncdeps (push_copy_users_syncdeps!). The hierarchical planner's shared-owner syncdep, the free-once check and the sorted order still apply. A CopyKey copy with no recorded slot is an error, not a free with no syncdeps. CopyKey ids, slots and users are all recorded in planning order, which is the same on every rank, so the free syncdeps are rank-uniform. The bookkeeping (UnkeyedSlots) is created lazily, on a region's first CopyKey copy. DataDepsState holds its (always local) cache store directly, so generate_slot! checks it without a MemPool lookup. The common path pays a length read and a short isa scan per slot, and a `nothing` check per reader. One region over plain Vectors (8 InOut and 7 two-In tasks; -t1, 15 warmup regions, minimum of 12, 3 fresh processes, Julia 1.12.6): 4600-4602 allocations / 175,440-175,632 bytes with this commit, 4695-4697 / 178,224-178,416 on the PR head. No increase. Verified: - The next commit's test fails in all 6 slow-read rounds (both planners) without this commit, and passes 12/12 with it. - --test datadeps (1555 pass, 2 broken) and --test allocations (25/25) pass, Julia 1.13.1, 3 workers. - The 2-rank MPI CPU suite (test/mpi/cpu.jl, including test/mpi/noaliasing_args.jl) passes: 1143 and 1146 per rank. - A 2-rank MPI probe with uniformity checks on (a NoAliasing isbits Vector built on rank 0, read by two slow tasks on rank 1, both planners, 3 rounds each) sees every copy allocated throughout its reads and freed after the region. Written by an AI agent on jpsamaroo's review feedback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
AnnaLena77
pushed a commit
to AnnaLena77/Dagger_AL.jl
that referenced
this pull request
Nov 29, 2026
…rank Datadeps frees the slot copies it makes at the end of a region, but `unsafe_free!` can only release a CPU `Array` eagerly when it is Libc-backed; anything else waits for GC. The generic slot transfer makes its copies freeable with `tochunk(libc_backed(move(...)))`. MPI's `move_rewrap` instead applied `libc_backed` to the `Chunk` returned by `mpi_endpoint_transfer`, and `libc_backed` passes a `Chunk` through unchanged. So no slot transferred over MPI was ever Libc-backed, the region's free released nothing, and every such copy stayed alive until a GC happened to collect it. Apply `libc_backed` inside the transfer instead, on the rank that holds the payload: after the receive and ingress move on the destination rank, and after a cross-space move on the owner when both spaces are on one rank. Within a single space `move` is the identity and the "copy" is the value itself, so it is left alone. Only rank-local storage changes: the Chunk's type and the messages exchanged are the same on every rank, so planning stays uniform. `libc_backed` is a no-op for anything but a CPU isbits `Array`, so device payloads are unaffected. Today this bites only slots that are transferred rather than allocated uninitialized (`slot_may_be_uninit`): ordinary dense isbits CPU slots already come from `alloc_libc_array`. Arguments that must be passed by value (NoAliasing, PR JuliaParallel#834) or types that decline uninitialized slots take the transfer path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AnnaLena77
pushed a commit
to AnnaLena77/Dagger_AL.jl
that referenced
this pull request
Nov 29, 2026
NoAliasing arguments are read-only and passed by value (In only; slots are made by move, never filled by a copy task), and Datadeps frees only the slots it allocated. Reviewers of PR JuliaParallel#834 and later changes need both to judge slot and free logic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
jpsamaroo
added a commit
to AnnaLena77/Dagger_AL.jl
that referenced
this pull request
Nov 29, 2026
Datadeps frees only slots it allocated itself; user data, including an argument serving as its own slot, is never freed by it. The aliased-object cache stored whatever a slot's copy function returned as a Datadeps copy, and the region-end free loop (flat and hierarchical) `unsafe_free!`s every such entry. Two paths hand back the user's own object instead of a copy: - The in-place slot of `generate_slot!` (`Returns(data)`), when another argument with the same aliasing was registered first in another memory space. `transpose(X)` of a device array `X` does exactly that: it has `X`'s aliasing but defaults to the host space. A host task reading `In(transpose(X))` followed by a device task writing `InOut(X)` freed `X` at region end (reproduced with CUDA: "Attempt to use a freed reference"). - A `move` that is the identity between two memory spaces of one process, which is the default `move` for a user-defined processor. `libc_backed` passes an already Libc-backed `Array` through unchanged, so Datadeps `Libc.free`d such an argument. Record a slot whose payload is the argument's own (`slot_holds_value`) as an original, which the free loops already skip. `y === x` is rank-uniform; payloads are compared only when both are local, and never under uniform execution, as in JuliaParallel#834's guard for unkeyed copies. The check runs only when a slot is created by `f`; a cross-worker copy returns after comparing the slot's owner with `myid()`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
Review finding F2 (should-fix) on PR #834: mixing a field dependency with its whole parent reached the indivisible-container owner assertion. Wrap inline field spans in FieldAliasing rather than returning the bare ObjectAliasing marker reserved for whole-object containers. Exercise both field/parent access orders across workers in the shared Distributed/MPI body, on both planners. Validation: the isolated cross-worker probe asserts on df62082; the fix passes 8/8 assertions across both planners. Deep-warmed Base.gc_num deltas (minimum of five runs after ten warmups and GC.gc) for 1,000 field alias queries remain 1,000 allocations / 32,000 bytes before and after. A one-element CombinedAliasing alternative cost 4,000 / 112,000, avoided by the immutable FieldAliasing wrapper. Written by an AI agent on jpsamaroo's review feedback.
Review finding F1 (blocker) on PR #834: fields declared as Any, abstract, Union, String or Symbol lost their storage identity and were rejected as NoAliasing, even in place. Describe every mutable field's own storage, retaining referent spans where present. Derive the field width from its enclosing layout, supporting abstract and union declarations. For partial object copies, omit reference slots from the byte buffer and serialize scalar field values separately. Keep array-reference bindings and synchronize their referents through the existing spans. Resolve nested field-owned spans generically. MPI now serializes full field values and uses the same field-aware remainder payload while dense/device arrays retain their existing staging path. Validation: the previous head rejects the Any-field cross-worker probe. The focused Any/Union/String/Symbol/Ref{Any} probe passes, including both parent/field access orders and an assertion that reference-slot byte payloads are zero. Shared tests cover Any, Real, Union{Nothing,Int}, String, Symbol and Ref{Any}: 234 Distributed assertions and 104 MPI assertions pass across both planners and remote workers/ranks. The field descriptor's warmed allocation measurement remains unchanged (1,000 allocations / 32,000 bytes for 1,000 queries); dense-array packing is unchanged. Written by an AI agent on jpsamaroo's review feedback.
Review finding F6 (should-fix) on PR #834: describes_memory still claimed that it only controls cache slot sharing, although it now also establishes the read-only by-value contract. Document write rejection, initialized move copies, skipped later copies, and cleanup/result lifetime. Retain the distinction between bare NoAliasing and empty CombinedAliasing dependency tracking. Verified against _populate_arg_deps!, move_rewrap, compute_remainder_for_arg! and free_unkeyed_copies!. Written by an AI agent on jpsamaroo's review feedback.
Review finding F4 (should-fix) on PR #834: freeing an unkeyed input copy when its reader returns it leaves a result backed by freed storage; remote fetch then serializes dangling memory and can kill the worker. Pass resolved reader results as ordinary inputs to the cleanup meta task. Skip eager release when a result retains the copy directly, through a view, or inside a container, leaving its finalizer responsible instead. Use storage identity rather than NoAliasing, which deliberately hides this memory. Bound recursive inspection to handle cycles conservatively and avoid scalar indexing of arbitrary non-bits arrays. Validation: the old path marks a returned cross-worker copy freed before fetch; the fix preserves direct, view and nested returns on both planners (12 checks). Cleanup plus result-lifetime shared tests pass 10 Distributed and 16 MPI assertions, confirming unused copies still release normally. Deep-warmed summed driver/worker Base.gc_num deltas (10 warmups, GC.gc, minimum of five regions) were 5,026 allocations /250,928 bytes before and 4,652 /237,920 after; measurements include the same worker-control RPCs. No threshold changes. Written by an AI agent on jpsamaroo's review feedback.
Review finding F5 (should-fix) on PR #834: every Datadeps cache created an empty unkeyed-copy vector even when the region made no private copy. Keep the store mutable and its copy vector absent until the first entry. Reload that field after slot construction, since constructing the slot can create the vector. Assert the concrete vector type on the free path once unkeyed slots prove that it exists. Update the cache construction check to require absence until the first actual copy. Validation: deeply warmed Base.gc_num deltas (10 warmups of 50 local regions, GC.gc, minimum of five batches) fell from 36,781 allocations / 2,030,528 bytes to 35,802 /1,955,776. Existing bounds are unchanged. Private-copy freeing and escaped-result regressions pass 10 Distributed and 16 MPI assertions on both planners after lazy initialization. Written by an AI agent on jpsamaroo's review feedback.
Review finding F7 (should-fix) on PR #834: the shared tests never reached unkeyed buffers created as children of a wrapper slot. Make a SubArray over a NoAliasing parent and send it to another worker or MPI rank. Check its selected data, hold the view in two readers, then inspect the parent buffer's allocation registry to prove cleanup waited for both readers and freed the nested copy. Share the fixture with the existing flat/hierarchical lifetime test instead of duplicating its checks. Validation: wrapper lifecycle checks pass 4 Distributed assertions. The MPI control-plus-wrapper checks pass 8 assertions across both planners, with the destination in another space. The readers also assert the view's value sum before retaining it. Written by an AI agent on jpsamaroo's review feedback.
Integrate the by-value NoAliasing and field-dependency fixes with master's CopyKey ownership tracking, wrapper reconstruction, dependency memoization and owner-local MPI Libc allocations. Private copies stay in the existing cache tables; their lazy per-slot user lists also supply resolved results to result-aware cleanup. This removes the duplicate private-copy vector. Preserve write rejection on a dependency-memo miss (a hit has already validated that same read/write dependency), complete move copies for read-only values, and the field-aware serialized remainder transport. Master's wrapper/whole-object source selection remains intact. Focused and full integration validation follows on this merged head. Written by an AI agent on jpsamaroo's review feedback.
A host-only NoAliasing declaration must still govern a complete device slot. Checking only the converted array descriptor instead compares unlike span sets or schedules an unordered copy-in. Reuse the source descriptor already cached during argument population, with the origin-space fallback for rebuilt handle wrappers. Add shared GPU and MPI×GPU read, write-rejection, no-copy-in and post-reader free checks. The strengthened OpenCL/pocl test fails both planners before the fix and passes all 11 assertions afterwards. With 10 warmups, GC and 5 runs of 1000 cached origin checks, replacing the general aliasing! lookup with the direct cache lookup reduces minimum allocations from 1000/32000 bytes to 0/0; the skipped-check control is also 0/0. Written by an AI agent on jpsamaroo's review feedback.
An immutable aggregate can expose a mutable child’s reference-valued field spans. Selecting remainder staging from only root mutability lets that child’s GC pointers enter the raw byte payload. Recurse through non-array field types, preserving ordinary direct-array staging. Five focused payload checks pass, including zeroed reference bytes and a serialization/scatter round trip preserving the destination’s other field. With 10 warmups, GC and 5 runs of 1000 trait calls, both old and new predicates allocate 0 objects/0 bytes for direct arrays and nested mutable field containers. Written by an AI agent on jpsamaroo's review feedback.
The helper now returns reader tasks for both cleanup ordering and result lifetime checks, rather than directly appending syncdeps. Match its docstring to that responsibility. Written by an AI agent on jpsamaroo's review feedback.
A Tuple or NamedTuple can describe exactly its mutable child’s field storage. Treating both as cache leaves lets one become the other’s slot, corrupting the argument-to-history mapping. Rebuild aggregates with the existing header/children protocol and copy their memory-bearing children in place for whole-object moves.
Field/whole overlap in both access orders passes 48 Distributed assertions across three placements and 24 MPI assertions across two ranks, for both planners. The previous failure was a missing child-history key; adding the wrapper protocol also exposed the required whole-copy method.
With the same test-only Tuple{Vector{Float64}} copy hook on both snapshots, 10 warmup batches plus GC and 5 samples of 10 regions measure driver+worker minimum allocations 78256→90249 and bytes 3832160→4391288. This is the cost of retaining separate aggregate headers while sharing child slots; ordinary scalar tuples bypass Datadeps slot processing.
Written by an AI agent on jpsamaroo's review feedback.
Ten zero-work tasks need not visit every eligible processor. The merged-master full Datadeps run passed 2297 assertions but hit the known baseline fixture failure when ThreadProc(2,2) was unused. Port the independently validated #841/#798 fixture: retain unpinned membership checks and exercise each eligible processor with one pinned task. Written by an AI agent on jpsamaroo's review feedback.
Unkeyed copies now use free_unkeyed_copy! so returned views and containers retain their storage. Keep existing exact free-task counts and syncdep assertions by recognizing that cleanup entry point alongside unsafe_free!. The full Datadeps run exposed two false counts of 3 rather than 6 while all data and lifetime checks passed. Written by an AI agent on jpsamaroo's review feedback.
A depth limit does not bound a shared DAG: cleanup revisited exponentially many paths and could stall the region indefinitely. Carry a 256-node work budget across children and returned values; conservatively leave storage to GC when it runs out. Count undefined array/struct slots too. Matching non-bits immutable payload/result types are retained without invoking potentially recursive ===. Shared DAG, cycle, sibling budget, undefined-slot, immutable comparison and existing escape/free checks pass: 17 Distributed and 42 MPI assertions across both planners. Profiles of the exact extracted helper use 10 warmups, GC and 5 samples. The 22-node DAG drops from minimum 8388606 allocations/268435392 bytes and 215.6 ms to 256/8192 and 7.3 μs; ordinary result tuples remain 6/192. Comparing two cloned immutable DAGs drops from 54.9 ms to 20 ns with zero allocations in both versions. Written by an AI agent on jpsamaroo's review feedback.
A pending DTask can still use and later return the copied input while its future exposes only pool IDs. Treat work, future, pool and channel handles as owning unknown storage; do not wait or load their contents during cleanup. Nonlocal chunks and foreign mutable result objects can also hide storage in private tables, so leave those copies to GC. Keep array identities, local completed chunks and ordinary Core/Base containers inspectable. The gated child, owning-reference/future and opaque-ID-holder regression fails 7 of 11 assertions before the fix and passes afterwards. Focused suites pass 28 CPU and 64 MPI checks, including existing escape/view and explicit-free controls. With 10 warmups, GC and 5 samples of 1000 checks, pending-DTask inspection drops from 1000 allocations/16000 bytes to 0/0; ordinary tuples remain 6000/192000. A fully pinned 10-region driver+worker control measures minima 47490/2454304 bytes before and 45291/2355736 after. Written by an AI agent on jpsamaroo's review feedback.
An immutable field cannot be rebound, but a memory-bearing value reached through it may still be written in place. Align the manual with field_aliasing and retain the In-only rule for isbits fields. Written by an AI agent on jpsamaroo's review feedback.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-ups to #792 ("Datadeps: give NoAliasing arguments their own slot"). The problems fixed here came from a structured review of #792 by the review system. #792 itself was correct; these are the gaps around it.
Why
When a Datadeps argument has to live in another memory space, Datadeps makes a copy of it there (a "slot") and normally shares that copy between arguments that use the same memory. It finds matches by looking up the argument's aliasing description in a cache. An argument whose aliasing describes no memory (
NoAliasing) has nothing to match on: every such description is equal, so distinct arguments used to collide and a task could silently get another argument's value. #792 fixed that by skipping the cache for bareNoAliasing. This PR finishes that job.It follows two rules the maintainer has stated for Datadeps:
move's copy of it, or the argument itself in its own space. It is never an uninitialized buffer that a later copy task fills, and nothing is copied back to it.Commits
test/noaliasing_defs.jl(the same pattern asstencil_defs.jlandsparse_defs.jl). It runs fromtest/datadeps.jl(threads and Distributed) and from the MPI suite, with both planners, both in place and across memory spaces. With datadeps: NoAliasing arguments no longer share one slot #792's guard removed, the cross-space cases fail (every task reads the first value). The MPI test's header no longer cites a private reference.describes_memory. datadeps: NoAliasing arguments no longer share one slot #792 recognized only bareNoAliasing, by a hard-codedisacheck. An emptyCombinedAliasing, which is what any struct gets when all its fields reportNoAliasing, has no identity either, and still collided. The new wrapped-value tests fail on master.describes_memory(ainfo)is a generic function, so a third-partyAbstractAliasingcan opt in. It returnsfalseforNoAliasingand for aCombinedAliasingmade only of such parts.Arrays and GPU arrays declaredNoAliasing. Putting them back into that loop would not have been enough: Datadeps tracks no dependencies for such aliasing, so the free would race the tasks reading the copy. (That is what happened to these copies before datadeps: NoAliasing arguments no longer share one slot #792.) Each such copy is now recorded and tied to its slot, every task that uses the slot is recorded, and both planners free the copy once all those tasks finish. The bookkeeping is allocated only in regions that make such a copy. The common path pays one emptyVectorper region and a couple of field reads.type_may_alias) is still on another branch. Commit 8 rewrites it.move_rewraplet an isbits payload, such as aVectorof an isbits type declaredNoAliasing, get an uninitialized slot, andcompute_remainder_for_arg!then scheduled a copy task to fill it. Because nothing orders tasks on such aliasing, the reader did not wait for that copy. Summing such aVectoron another worker gave a wrong sum in 10 of 10 regions with 4-thread workers, on master too. It now gives 0 wrong sums in 10. Types that takemove's path also got that copy task, writing into a slot that was already filled. The tests'NoAliasValonly worked because they defined amove!for it. Now such a slot is alwaysmove's copy, and no copy into or out of it is ever scheduled, so nothing is recorded as written. This adds no extra aliasing queries:move_rewrapreuses the queryaliased_object!makes anyway, andcompute_remainder_for_arg!reuses the one it already computes.libc_backedreturns an already Libc-backedArrayunchanged. So ifmovewere ever the identity between two spaces of one process, the "copy" would be the user's own object, and commit 4 would free it. A copy is now recorded for freeing only if its payload is not the argument's own. The comparison only runs when both values are in the same process, and never under MPI, where every rank must make the same decision.VectordeclaredNoAliasinggetsmove's copy under MPI too, instead of a Libc-allocated buffer. MPI's slot transfer wraps that copy in aChunk, andlibc_backedpasses aChunkthrough unchanged, so the copy is an ordinary GC-managed array with nothing to free eagerly. Under MPI, the free test now only checks that nothing is left allocated.Deps(X, InOut(:value))on an isbits field of a mutableXis documented, but its aliasing was the aliasing of the isbits value, which isNoAliasing. So nothing ordered other uses of the field after the write, and a write from another memory space never came back:X.valuestayed0on master, and for a plain struct the copy even threw for lack of amove!. Now:X:sizeofthe field, at itsfieldoffset. It overlapsXas a whole, and a cross-space use copies just that field, in both directions.NoAliasing, because it cannot be written.move_field!, reached from the genericmove!fallback. Amove!method ondep_mod::Symbolwould be ambiguous with everymove!that specializes the values. For MPI, which copies a field as packed memory spans, the span copy now handles spans that lie inside a mutable object's own storage.docs/src/datadeps.mdnow says what a field dependency covers.Out/InOuton a value declaredNoAliasing, or on an isbits field of an immutable struct, raises anArgumentErrorat planning time instead of losing the write. The check reuses the aliasing planning already computes, so it costs one call per written dependency and nothing for reads.String,SymbolandTypearguments are not affected. Datadeps never tracks dependencies for them (type_may_aliasisfalse), so a write dependency on one is ignored, as before.What about
UnknownAliasing?It still goes through the cache, on purpose.
UnknownAliasingmeans "may alias any memory", which is the opposite of describing none. Two arguments with unknown aliasing may be one object reached through two wrappers, and giving each its own copy would silently split that object. Distinct objects with unknown aliasing do still share one cache key. Fixing that needs a real identity, or refusing such arguments, not this bypass. Dagger's ownaliasingmethods throw instead of returningUnknownAliasing, so only a user-defined method can produce it.What else was checked
NoAliasing(_get_write_deps!,_get_read_deps!,gather_overlap_syncdeps!,assert_free_syncdeps!) still test bareNoAliasing. An emptyCombinedAliasingis tracked today, which keeps successive uses of one such argument in order, and switching those helpers todescribes_memorywould change that. A comment now says so.packchecks were left alone. These are theNoAliasing || UnknownAliasingchecks, which run only for non-identitydep_mods.Tests
julia --project=test test/runtests.jl --test datadeps: 1608 pass, 2 broken, 0 failjulia --project=test test/runtests.jl --test allocations: 24/24 passjulia --project=test/mpi/env test/mpi/run.jl 2 2 test/mpi/cpu.jl: 1173 and 1194 pass on the two ranks, 0 failjulia --project=test/mpi/env test/mpi/run.jl 4 2 test/mpi/cpu.jl: 1539-1554 pass per rank (some assertions only run on one rank), 0 failVectorof an isbits type declaredNoAliasing, summed with 4-thread workers) gives 0 wrong sums in 10 regions; master gives 10 in 10. The regression test intest/noaliasing_defs.jlmakes this deterministic: the test types'move!raises, so any copy into such an argument fails the region. That test fails on master and on this PR's previous head.CombinedAliasing) values: fail on master in every placementNoAliasingvalue or an immutable isbits field is rejected: fails without commit 11Refs #792. Closes #822.
🤖 Generated with Claude Code