Repository navigation
Support generic callback event storage - #4398
ChrisRackauckas merged 2 commits into
Conversation
Add a map!-based findall_events! fallback for non-Array storage such as GPU arrays, make the shared helper public, document it, and bump DiffEqBase for the new public API. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.150.1 Agent-Model: unknown Agent-Session: local session ID 01a0441e-3d2f-7170-ab6e-58ef72975a9f
9463a94 to
e919d5b
Compare
Drop the Array/SubArray loop specialization. With a non-capturing two-argument is_event_occurrence, map! matches the inbounds loop at callback-relevant lengths, so one generic method is enough. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Grok <[email protected]> Agent-Harness: Grok 1.0.5 (5115b46bc9) Agent-Model: grok-4.6 Agent-Session: local session ID 01a045f9-5360-7622-b38d-e4d084141432
|
| n | loop | map! closure | map! named | @. named |
@. with && |
|---|---|---|---|---|---|
| 1 | 39 ns | 40 ns | 40 ns | 40 ns | 40 ns |
| 8 | 50 ns | 50 ns | 50 ns | 50 ns | 50 ns |
| 64 | 60 ns | 60 ns | 70 ns | 60 ns | 119 ns |
| 1024 | 440 ns | 490 ns | 500 ns | 430 ns | 1550 ns |
| 65536 | 26.9 µs | 29.0 µs | 29.2 µs | 27.1 µs | 413 µs |
At callback-relevant lengths (n is callback.len, typically tiny) the loop, map! of a closure, and map! of a named function are the same ~40–70 ns. At 64k elements map! is about 8% slower; that size is not the VCC path. Inline @. next = prev != 0 && prev * next <= 0 is the one to avoid: short-circuit && does not fuse in broadcast (15× at 64k). @. next = is_event_occurrence(prev, next) matches the loop.
Closure
Follow-up 085a21e87 drops the anonymous (next, prev) -> … and the Array/SubArray method. findall_events! is now one method:
function findall_events!(next_sign, prev_sign)
map!(is_event_occurrence, next_sign, prev_sign, next_sign)
return any(isone, next_sign)
endusing a two-argument is_event_occurrence(prev, next) = prev != 0 && prev * next <= 0. Argument order matches the existing four-argument scalar method (prev, then next), so map! reads prev_sign then next_sign into dest next_sign. The four-argument method is unchanged: it still gates on affect! / affect_neg! for scalar ContinuousCallback.
The Union{Array, SubArray} method was also a GPU footgun for non-contiguous views (SubArray of a CuArray would have hit the scalar loop). Contiguous 1-D CUDA views are still CuArray via derive, so they already missed that method; always using map! makes that dispatch accidental rather than load-bearing.
Verification after the follow-up:
GROUP=Core Callbacks | Pass 35 Total 35
GROUP=QA Aqua | Pass 9 Total 9
CUDA execution was not run here (no device). Downstream remains SciML/DiffEqGPU.jl#503.
🤖 Generated with Grok 1.0.5 (model: grok-4.6; session: local session ID 01a045f9-5360-7622-b38d-e4d084141432).
- Fix definite assignment in ROCK stages (#4321) - Correct NonlinearSolve downgrade dependency floors (#4394) - Fix ensemble work-precision error storage (#4390) - Add explicit benchmark tag semantics (#4402) - fix: require cache-aware nonlinear solver in PDIRK (#4406) - fix: accept SciML caches in nlsolve! (#4407) - Support generic callback event storage (#4398) - test: account for Hairer4 BLAS variation (#4410) - Fix Rosenbrock interpolation after callback truncation (#4411) - Fix weak Platen methods for scalar Wiener processes (#4413) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
What changed and why
findall_events!now uses a singlemap!method for all callback sign storage, including GPU-backed arrays. It calls the two-argumentis_event_occurrencerather than a per-call closure. The CPUArray/SubArrayloop specialization was dropped after a microbenchmark showedmap!of that named function matches the@inboundsloop at callback-relevant lengths. The helper is now public and documented, and DiffEqBase is bumped from 7.18.2 to 7.19.0 because this adds public API.This is the prerequisite for fixing vector continuous callbacks in DiffEqGPU's
EnsembleGPUArraypath.Verification
Failing before the implementation, using the added generic-array regression test on clean
upstream/master:Passing after the implementation:
After the follow-up that always uses
map!(is_event_occurrence, …)(head085a21e87), the same Core/QA commands completed locally:After rebasing over upstream
masterata27ee037e, these exact commands completed locally on the previous head:CI failure classification
All 14 failed checks on head
e919d5b34reproduce on clean upstream or are unchanged pre-existing failures outside this PR's DiffEqBase callback-event diff. No CI failure is branch-introduced, so this PR adds no unrelated fix.StochasticDiffEqImplicitcache atnlsolve!. Clean master has the identical downgrade failure in job 98649264888. The focused prerequisite accepts the shared SciML cache contract: ChrisRackauckas-Claude@d7dad13TauLeapingstill defines the legacy stochasticalg_cachesignature while currentOrdinaryDiffEqCorecalls the generic signature. Both definitions are identical on the PR base and current master; the legacy method entered with cea8ebb. This needs a separate Stochastic fix.1.4306299457644833e-4and5.135110298093437e-5against1e-5. The existing focused test setup fix is ChrisRackauckas-Claude@04240ce.Base.ImmutableDict{DataType,Any}typeassert failures in InterfaceI, InterfaceII, and Initialization. The owning-package fix is JuliaSymbolics/SymbolicUtils.jl#1033. InterfaceII also encounters the Stochastic cache failure above.EnzymeRuntimeActivityErroratscimlstructures_interface.jl:154in job 98638298114. The focused SciMLSensitivity prerequisite is ChrisRackauckas-Claude/SciMLSensitivity.jl@aaf9812.Current upstream master is one unrelated DiffEqDevTools commit ahead (
468bea34e); rebasing solely for that commit would invalidate this audited CI run and trigger the full matrix again.Not verified locally
No CUDA device is available on this host, so the downstream CUDA callback path remains for DiffEqGPU CI to verify after this prerequisite is available. The unrelated failure families above were classified from their complete logs and matching clean-master runs; their separate focused fixes were not combined with this PR.
Links
🤖 Generated with Codex CLI 0.150.1 (model: unknown; session: local session ID 01a0441e-3d2f-7170-ab6e-58ef72975a9f).
Follow-up
085a21e87generated with Grok 1.0.5 (model: grok-4.6; session: local session ID 01a045f9-5360-7622-b38d-e4d084141432).