Repository navigation
Raw transport of structs that hold bit arrays - #817
Open
AnnaLena77 wants to merge 16 commits into
Open
AnnaLena77 wants to merge 16 commits into
AnnaLena77 wants to merge 16 commits into
Conversation
A struct with an array travelled through MPI.isend(serialize): Serialization copies the
array into a fresh buffer, the receiver reads that into another fresh buffer and
deserializes it into a third. Fresh memory is expensive on the Opterons, so a 40 MB
struct of three arrays moved at ~80 MB/s. Dagger already had a raw-buffer path
(inplace_mpi_parts / alloc / build), but only for dense arrays and for types that
define the three hooks by hand.
Types that define nothing now get it automatically when they qualify: a concrete
struct with at least one plain Array of bits, directly or inside an immutable struct
field. The arrays travel as raw buffers and every other field (bits, String, Dict,
Vector{Any}, ...) in the header, which is serialized as before, so such a field costs
what it did. Rebuilt like Serialization does (jl_new_structv, no constructor call), so
a type with an inner constructor round-trips unchanged. A value in which one array is
reachable twice opts out, so the sharing survives. Everything else is untouched; a
more specific method (DenseArray, SparseMatrixCSC, user hooks) still wins.
our cluster (Open MPI), a struct of three arrays made on rank 0 and consumed on rank 1 (the
time includes making it), median of 5, serialize -> automatic raw buffers:
two nodes 0.4 MB 6.6 -> 3.1 ms 4 MB 53.4 -> 19.5 ms 40 MB 580 -> 210 ms
one node 0.4 MB 5.0 -> 8.6 ms* 4 MB 37.3 -> 13.4 ms 40 MB 580 -> 174 ms
(* noise: 0.4 MB runs are dominated by task latency; min 3.4 -> 5.4 ms)
Equal to defining the three hooks by hand (172 / 208 ms at 40 MB). Laptop, MPICH:
40 MB 119 -> 84 ms.
Test (test/mpi/struct_transport.jl, 2 and 3 ranks, MPICH 5.0.2 and Open MPI 5.0.10): the
decomposition, an eligible struct, a struct with a String and a Dict, a nested struct, a
shared array (sharing must survive), an inner constructor with an invariant; a struct
without arrays stays on the old path.
The automatic decomposition of structs that hold bit arrays has to leave a value to
serialize whenever taking it apart would not rebuild the same value, or would send
the wrong bytes. A value now travels through serialize, as before the automatic path,
when:
- it is an array wrapper (SubArray, ReshapedArray, PermutedDimsArray, ...), at the top
level or as a field. Its array field is the whole parent it views, so a 256 x 256
block view of a 2048 x 2048 matrix travelled as all 32 MB of the parent.
copyto!(::DArray, ::Matrix) copies from one view per block, so the bytes grew with
blocks x matrix size; 2 ranks, 256^2 blocks (laptop, MPICH), darray_copyto! from a
matrix: 1024^2 0.15 s -> 0.023 s, 2048^2 2.1-2.9 s -> 0.056-0.105 s. At 8192^2 a
single copyto! took longer than a 15-minute benchmark case.
- a field is undefined (an inner constructor that leaves one unset): reading it field
by field threw UndefRefError in the sender, which under MPI is a hang.
- the type or a nested struct has its own Serialization.serialize method (Thunk,
WeakChunk, user types): taking it apart would bypass it. This is decided at run time,
once per type, because a generated function may not use reflection.
- an array holds elements with padding between their fields: the MPI datatype of such
a struct carries the packed bytes only, so the receiver's buffer did not match
("expected 24 bytes, got 15") and the task hung.
- an array in the header shares memory with a raw part (a view or reshape of it), in
addition to the shared-field case: the raw path would rebuild independent arrays.
Types with their own hooks (Array, SparseMatrixCSC) are unchanged.
Tests (test/mpi/struct_transport.jl, 2 and 3 ranks): wrappers are not decomposed and a
struct holding a view sends only its own array raw (fails without the wrapper rule); an
undefined field, a type with its own serialize, padded elements, an empty array, a
Union field, tuples and named tuples, and 300 random nested tuples of arrays, strings
and integers that must round-trip with the same type and contents. The undefined-field
and padded-element cases hang the job without the opt-outs.
AnnaLena77
force-pushed
the
pr/m3-raw-transport
branch
from
November 28, 2026 11:07
2833f56 to
91b36fa
Compare
Direct field checks miss raw arrays referenced through Dict, Ref, non-isbits arrays, SimpleVector, or cycles. Trace the serialized header graph with an identity visited set and fall back when it reaches a raw part. Handle host Memory storage and conservatively reject unsupported non-isbits backends. Scalar metadata and scalar-entry Dicts retain their allocation-free path. The focused pre-fix round-trip probe loses nested and cyclic identities; fixed probes preserve them. The full two-rank, two-default/one-interactive thread struct transport suite passes 658 assertions per rank, including cross-rank header sharing and 300 randomized nested values. After ten warmups and GC, minimum of five 5000-call allocation measurements remains zero bytes and allocations before/after for plain and scalar-Dict headers. Final minima are 0.139/0.256 ms versus 0.182/0.150 ms on the base; these small metadata probes do not measure end-to-end transport throughput. Written by an AI agent on jpsamaroo's review feedback.
A type first transferred with default serialization remained eligible forever after a package defined custom serialization. Track the method world while holding the eligibility lock and re-evaluate cached answers when methods change. The late-method probe fails before this repair and passes afterwards; the final two-rank transport suite passes 658 assertions per rank. Written by an AI agent on jpsamaroo's review feedback.
Eligibility queried at AbstractSerializer misses custom methods specialized on the IOBuffer-backed Serializer that MPI uses. Query that concrete dispatch so these types retain their own wire representation. The concrete-serializer probe fails before the repair and passes afterwards, alongside the 658-assertion two-rank suite. Written by an AI agent on jpsamaroo's review feedback.
Automatic reconstruction bypasses deserialize methods even when serialize is generic. Require generic deserializer dispatch for every decomposed type as well, so a custom receive-side transformation is preserved. The deserialize-only probe fails before this check and passes afterwards; the final two-rank suite passes 658 assertions on each rank. Written by an AI agent on jpsamaroo's review feedback.
mightalias reports no memory overlap for the same empty array. Check object identity too, and inspect immutable array-header fields before treating their bits elements as scalar data; unsupported mutable handles keep ordinary serialization. Independent pre-fix controls lose aliases for direct, Ref and custom-wrapper sharing. Focused two-rank tests now pass 14 assertions per rank, including push! propagation across ranks, empty ordinary-view serialization controls, disjoint wrapper/view eligibility and a wrapper whose scalar indexing throws. Written by an AI agent on jpsamaroo's review feedback.
A full identity visited set costs 208 bytes and 5 allocations for each independent one-parent wrapper header. Check direct scalar/host-bits fields without a visited set, while retaining full graph memoization for complex headers. After ten warmups and GC, minimum of five 5000-call samples returns this wrapper path to zero bytes/allocations; plain and scalar-Dict headers remain zero, and two-array tuples retain their pre-existing 48 bytes per call. Final two-rank empty-sharing/control tests pass 14 assertions per rank. Written by an AI agent on jpsamaroo's review feedback.
A header codec can recover an array from a registry rather than a field, including for isbits header keys. Splitting that header from a raw array loses sharing that ordinary Serialization preserves. Require standard codecs before atomic/header graph shortcuts and raw-array decomposition; cache reflected eligibility with method-world invalidation. Recheck nested bits metadata and scalar Dict types before skipping their graph walks. Two-rank, 2-default+1-interactive full transport suite passes 695 assertions per rank (658 existing, 14 empty-sharing, 23 custom-header). Registry tests cover concrete/Any/Ref/Dict and nested isbits headers, late definitions, and actual cross-rank identity. Independent pre-fix control demonstrated ordinary sharing=true and split sharing=false. After ten 5000-call warmups and GC, minimum of five GC-delta runs: scalar, Symbol/Int Dict and flat-wrapper cases remain 0 bytes/0 allocations; two-array results retain the prior 240000 bytes/5000 allocations per 5000 calls. These are focused mechanism probes, not a whole-workload benchmark. Written by an AI agent on jpsamaroo's review feedback.
Packages may validly define custom codecs with @eval Serialization, so module ownership alone does not establish that field traversal describes that codec. Require the standard generic codec's source file as well. Keep custom methods in an ordinary stream regardless of their module. The independent exact-head registry control failed sharing before this follow-up. Two-rank2default+1interactive controls now pass25 custom-header and14 empty-sharing assertions per rank, including the module-evaluated codec. The preceding head passed the full695-assertion transport suite per rank; this focused follow-up verifies the additional eligibility boundary. The origin reflection is cached and changes no warmed traversal logic. Written by an AI agent on jpsamaroo's review feedback.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #817 +/- ##
==========================================
+ Coverage 64.35% 70.37% +6.02%
==========================================
Files 126 126
Lines 20191 20442 +251
==========================================
+ Hits 12993 14387 +1394
+ Misses 7198 6055 -1143 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Review finding F1 (blocker) on PR JuliaParallel#817: restore Julia 1.14 beta2 eligibility. Use the runtime's Core.Typeof key when reflecting deserialize dispatch. For type-valued headers, distinguish the exact serializer key from the runtime type passed to deserialization. Keep custom-codec origin checks and method-world invalidation; add registered type-header roundtrip and late custom-serializer fallback tests. A native beta2 negative reproduces the original Type{T} lookup failure. Exact beta2 local raw controls pass 677 assertions; full two-rank Julia 1.13.4 transport tests pass 702 assertions per rank, including the five new registered assertions. The same full suite also passes 702 assertions per rank on beta2. After ten 5000-call warmups and GC, five before/after GC-delta samples are identical in all five controlled Julia 1.13.4 cases. Minima, including escaped results and counter overhead: scalar, Dict and type-valued headers 160032 bytes/5001 allocations; flat wrapper 2400064/50001; two-array tuple 240032/5001. These are raw-decomposition controls, not whole-workload benchmarks. Written by an AI agent on jpsamaroo's review feedback.
Address the independent review's sharing blocker on PR JuliaParallel#817. The standard DataType codec serializes type parameters, whose custom codecs can reach a raw buffer through a registry. This metadata also accompanies the outer value and container headers, including empty dictionaries. Keep those values in one ordinary stream unless all serialized metadata is safe. Validate nominal type parameters before atomic shortcuts, retain fallback for functions/whole definitions/unsupported type representations, and key codec checks by both serializer and deserializer dispatch inputs. Memoize atomic metadata per method world, with conservative recursion fallback; inspect actual Type dictionary slots while preserving scalar fast paths. Add direct/nested/type-dictionary/empty-declared-type/outer-type sharing regressions, late-codec invalidation and actual cross-rank validation. Exact published-source negative: ordinary sharing=true, split sharing=false. Final full MPI suites pass 718 assertions per rank on Julia 1.13.4 and 1.14-beta2 (2 ranks, 2 default plus 1 interactive thread). The beta2 run using the registered barrier/exit protocol records worker exits 0/0 and no signal; earlier extra-Timer/accelerator-switch harness shutdown faults are retained in the review receipts, without a universal clean-teardown claim. Minimum Julia 1.10.11 standalone eligibility/reconstruction checks pass. After ten 5000-call warmups and GC, all five before/after GC samples match in six Julia 1.13.4 cases. Minima include escaped results/counter overhead: scalar, Dict, type-header and type-Dict 160032 bytes/5001 allocations; flat wrapper 2400064/50001; two-array tuple 240032/5001. At metadata DAG depth 18, instrumentation visits 19 distinct types cold and none warm for a 243-byte serialized type. These are mechanism probes, not whole-workload benchmarks or a hosted-CI pass claim. Written by an AI agent on jpsamaroo's review feedback.
The MPI test launcher kept only the parent's executable, so registered raw transport tests ran without instrumentation and contributed no coverage. Reuse the reviewed JuliaParallel#850 fix: preserve enabled user/all/path coverage flags, and process/upload one existing latest-Julia two-rank cell with the same settings already used by ordinary jobs. Leave thresholds and permissions unchanged, and keep the other MPI cells uninstrumented. On Julia 1.13.4, the unchanged registered raw-transport subtree passes 718 assertions per rank in each of three two-rank controls (4308 total, zero failures/errors). The original launcher drops requested coverage; the fix produces both ranks' sidecars and actual CoverageTools hits; disabled coverage still produces none. All source files remain unchanged and all processes are reaped. This is local functional/collection validation; the new hosted upload and Codecov verdict remain pending. Written by an AI agent on jpsamaroo's review feedback.
jpsamaroo
added a commit
to AnnaLena77/Dagger_AL.jl
that referenced
this pull request
Dec 2, 2026
The combined summary used always(), so obsolete PR runs could keep a queued summary eligible after cancellation and hold the per-ref concurrency slot. This delayed replacement runs for JuliaParallel#817 and JuliaParallel#819 until the old runs were force-cancelled. Use GitHub's documented !cancelled() status condition. It still permits the summary after ordinary upstream benchmark failures without keeping the job eligible when the workflow is cancelled. Keep the PR event filter and all concurrency, permissions, benchmark jobs and reporting steps unchanged. Validation: all nine existing benchmark report/comment Node tests pass in a credential-free, network-isolated sandbox; parsed YAML differs only at the summary job predicate; git diff --check passes. No new hosted cancellation experiment is claimed, and actionlint is unavailable. Written by an AI agent on jpsamaroo's review feedback.
Review finding F1 on PR JuliaParallel#817 (blocker): raw decomposition creates tuple containers which ordinary payload serialization never visits. A custom codec for one of those containers can change the payload or raise an exception only on the optimized transport path. Use the existing world-aware codec checks for the field-values tuple, shape aggregate, each dimensions tuple, and outer descriptor, including their exact type metadata. Fall back to the ordinary stream when any codec is custom. Generate fixed-index dimensions checks so mixed ranks retain their concrete tuple types instead of boxing in a runtime loop. Register independent field, descriptor, type-metadata and shape codec regressions, retain ordinary dimensions-codec exceptions, and check that unrelated eligible payloads still use raw transport. Record the invariant. Slurm job 101 on Helios, Julia 1.13.2, CPU-only 2 CPUs/4 GiB: the exact new registered regression passes 19/19 against the extracted complete raw implementation; the original source fails with both field/descriptor codec errors. Return-type inference is unchanged for both fixtures. After 10 x 1000 warmup calls and GC, all five paired 1000-call allocation samples are flat: scalar two-array fixture 5001 allocations/192032 bytes, String/Dict header fixture 1001 allocations/48032 bytes, base and head. These are isolated raw-helper measurements, not a full MPI suite. Written by an AI agent on jpsamaroo's review feedback.
…ssons Retain both the existing nonconcrete-field MPI suite and the raw-transport suite at the shared include site. Keep master AGENTS.md content verbatim, retain its MPI coverage lesson once, and append the transport-specific lessons as 125-127 without changing their words. Independent Astra review cleared the resolved tree. The exact raw source slice and registered regression tested in Slurm job 101 are unchanged; master's other source and test changes are inherited through this merge. 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.
Wire format change: all ranks of a job must run the same version of Dagger. For a struct that holds plain arrays of bits the bytes on the wire differ from before (a descriptor of type and header, followed by one raw buffer per array instead of one serialized blob). A job that mixes this version with an older one will not decode these values.
Category 2 (adapted internal functionality), MPI struct transport: Structs that hold plain arrays of bits now travel between ranks as raw buffers instead of through
serialize. Users define nothing; types with their owninplace_mpi_partshooks, dense arrays and sparse matrices keep their existing paths.Decisions for the maintainer, first
Arrayof bits, directly or inside an immutable struct field, tuples and named tuples included. The other fields go in the header, serialized as before. It is rebuilt likeSerializationdoes (jl_new_structv, no constructor call).serializeas before when: memory is reachable twice (a shared field, or an array next to a view or reshape of it), a field is undefined, the type or a nested struct has its ownSerialization.serializemethod (Thunk,WeakChunk, user types), an array holds elements with padding between fields, or the value is an array wrapper (SubArray,ReshapedArray, ...; its array field is the whole parent, so a block view of a 2048 x 2048 matrix travelled as all 32 MB). The undefined-field and padded-element cases hang the job without the opt-outs: the first throws in the sender, the second fails the size check in the receiver ("expected 24 bytes, got 15"). The first version of this branch had neither opt-out.Arrayof padded structs sent as a task argument has the same padding mismatch on upstream master (the dense-array path only checksisbitstype). This branch does not touch it.Effect (our fork, not re-measured on upstream)
copyto!(::DArray, ::Matrix): 1024^2 0.15 to 0.023 s, 2048^2 2.1-2.9 to 0.056-0.105 s.Testing (macOS arm64, Julia 1.13, MPICH)
test/mpi/struct_transport.jlat 2 and 3 ranks x 2 threads: 647 passed each, 0 failed. It covers the decomposition, nested structs, a String and a Dict, inner constructors, shared arrays, wrappers, undefined fields, own serialize, padded elements, empty arrays, Union fields, tuples and named tuples, and 300 random nested tuples of arrays, strings and integers that must round-trip with the same type and contents (locally through parts/alloc/build, and five of them between ranks).test/mpi/cpu.jlfull suite at 2 ranks x 2 threads: 1785 and 1788 passed (per rank), 0 failed.datadeps/other non-MPI suites (this branch only changessrc/memory-spaces.jlhooks used by MPI sends).AI disclosure: I prepared this change with the help of Claude (Anthropic) and reviewed it myself.
🤖 Generated with Claude Code