Skip to content

SRA1 iip: scale k₁ in-place to drop per-step allocation - #4822

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:sde-sra1-inplace-k1
Oct 9, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:sde-sra1-inplace-k1

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

In SRA1Cache perform_step!, k₁ *= dt rebound a new Vector every step (same size as the state), costing ~96 B/step for diagonal and non-diagonal additive noise. Switching to @.. k₁ *= dt matches the existing in-place k₂ scale and removes that allocation without changing the arithmetic.

Regression test: @allocated(perform_step!) is 80 B on unfixed code (n=3) and 0 with the fix; IIP/OOP u_end agree to 2e-16. Same-seed u_end is bitwise identical before/after (perf-only change).

Results (amdci2, Julia 1.12.4, JULIA_NUM_THREADS=1, taskset -c 0)

before after
perform_step! @benchmark min 270 ns, 2 allocs / 96 B 160 ns, 0 allocs / 0 B
averaged step! B/step 96.0 0.0
u_end (seed=7, fixed dt) identical identical

Failing before / passing after: before.txt shows Evaluated: 80 == 0; after.txt both testsets Pass.

Test-group tails

Core (GROUP=Core, --check-bounds=auto, OPENBLAS_NUM_THREADS=1):

Test Summary:                | Pass  Total   Time
SRA1 iip k₁ scale allocation |    2      2  11.4s
     Testing StochasticDiffEqHighOrder tests passed

QA (GROUP=QA):

Test Summary:     | Pass  Total     Time
QA (Aqua and JET) |   21     21  1m35.5s
     Testing StochasticDiffEqHighOrder tests passed

Also: Runic + typos on touched files; regression test on Julia 1.10.12 Pass.

Not verified

  • Full umbrella StochasticDiffEq test suite / other SRA tableau paths beyond SRA1 iip.
  • GPU / JLArray / ForwardDiff AD through this step.
  • Timing under load beyond the single-core @benchmark minima above (shared machine).

Reviewer pushback

  • Whether @.. k₁ *= dt is preferred over @. k₁ *= dt / k₁ .*= dt given FastBroadcast usage elsewhere in this file.
  • Whether the alloc regression should also assert non-diagonal noise (master was 96 B/step there too; this PR’s test covers diagonal perform_step! only).

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

Independent review: pending

🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /home/crackauc/sandbox/goals/performance/jobs/pr-sde-sra1-alloc/log.txt on amdci2; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Made with Cursor

Risk assessment

  • Risk: low
  • Blast radius: One line in in-place SRA1Cache perform_step! (k₁ *= dt becomes @.. k₁ *= dt) in lib/StochasticDiffEqHighOrder, plus a new Core test file. cache.k₁ is its own zero(rate_prototype) buffer. Nothing aliases it, and nothing outside this step reads it (SDE dense output does not use it). It is overwritten by f(k₁, uprev, p, t) at the start of every step, so scaling it in place cannot leak into later steps, FSAL, or interpolation. No public API change.
  • Evidence: Head 7b40fc8. CI: 135 pass, 4 fail. All 4 failures are pre-existing and identical to master: the downgrade jobs for DiffEqBase and OrdinaryDiffEqDifferentiation fail on master run 37820479420 (base 6072e89). SciMLSensitivity.jl/Core1 fails on the last 3 master IntegrationTest runs. GPU (julia 1) shows the same 3 QNDF dae_tests.jl:481 failures as master. StochasticDiffEqHighOrder Core passes on Julia lts/1/pre (so the @allocated == 0 test holds on all three), as do QA and all StochasticDiffEq umbrella groups. Locally (Julia 1.12, fresh env), the PR's test file gives Evaluated: 80 == 0 (1 pass / 1 fail) on master src and 2/2 on PR src. With seed 11, diagonal and non-diagonal (3x2) additive noise, adaptive and fixed dt=1/64, sol.t, sol.u, naccept and sol(0.37) are bitwise identical between master and PR. step! allocations drop by 80 B in every case.
  • Independent review: Claude Code (claude-opus-5-5) rated it low, high confidence: an in-place scale of a private stage buffer that is rewritten every step, with results verified bitwise identical to master for diagonal and non-diagonal noise in both adaptive and fixed-dt modes.
  • Merge: auto-merge candidate (non-blocking nits: the test comment says "96 B/step on master for n=4" but the test uses n=3, which measures 80 B; integ.t = mod(integ.t, 9.0) does nothing because perform_step! never advances t; and the IIP/OOP rtol = 2e-16 check is tight enough that it could break if the two paths ever fuse differently)

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Claude Code 2.1.285 · model: claude-opus-5-5
Conversation: local session 3c311569-dda6-4687-bc9f-65febb212c33 (local transcript)

`k₁ *= dt` rebound a new Vector every SRA1Cache step; `@.. k₁ *= dt`
matches the existing k₂ path and removes the 96 B/step alloc.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.10.01-14929f9
Agent-Model: unknown (Cursor auto)
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-sde-sra1-alloc/log.txt on amdci2
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 9, 2026 06:27
@ChrisRackauckas
ChrisRackauckas merged commit 72ee57d into SciML:master Oct 9, 2026
138 of 142 checks passed
ChrisRackauckas referenced this pull request Oct 14, 2026
…inaryDiffEqBDF, OrdinaryDiffEqExplicitRK, OrdinaryDiffEqFIRK, OrdinaryDiffEqFeagin, OrdinaryDiffEqHighOrderRK, OrdinaryDiffEqPDIRK, OrdinaryDiffEqRKN, OrdinaryDiffEqSDIRK, StochasticDiffEqHighOrder, StochasticDiffEqLowOrder, and StochasticDiffEqMilstein for release (#4871)

Agent-Harness: Devin CLI 3000.11.3
Agent-Model: Fusion (Claude Opus 5.5 Medium + SWE-2 Medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/flash-hour.json

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants