Skip to content

Make FBDF/DFBDF dense interpolation allocation-free - #4645

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:bdf-interp-alloc
Sep 28, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:bdf-interp-alloc

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Summary

lib/OrdinaryDiffEqBDF/src/bdf_interpolants.jl indexed the per-order tables _CHEB_NODES[n] and _BARY_WEIGHTS[n] with the runtime active order n = _bdf_active_order(k). Both tables are tuples of differently sized tuples, so the lookups were type-unstable and boxed the result: sol(out, t) on an in-place FBDF solution allocated 128 bytes per call.

The FBDF/DFBDF interpolation bodies now live in _fbdf_interp(!) kernels that take the order as a ::Val{n} parameter. The two _ode_interpolant(!) entry points dispatch to them through an unrolled branch over literal Val(1)–Val(6), so every kernel sees a statically known order and the table lookups constant-fold to concrete NTuple types. QNDF and Nordsieck interpolants only index homogeneous containers and are unchanged. Behavior is preserved: derivative orders without a kernel still throw DerivativeOrderNotPossibleError, and an active order above 6 still throws BoundsError (the tables have 6 entries).

Verification

  • Profile.Allocs on master attributes the allocations to bdf_interpolants.jl:386-387 (getindex on the two tuples), 95,936 B sampled per 1,000 calls — matching the prior audit.
  • New QA test in test/qa/allocation_tests.jl: @allocated sol(out, t) and @allocated sol(out, t, Val{1}) inside a function after warmup.
    • Before (master): fbdf_dense_interp_allocs() = (128, 384) → test fails.
    • After (this branch): fbdf_dense_interp_allocs() = (0, 0) → test passes.
  • Interpolated values are bitwise identical to master across a 21,669,840-value comparison spanning all FBDF orders, derivative orders Val{0}–Val{3}, idxs and nothing variants, and in-place/out-of-place forms — except 12 values (scalar-ODE Val{1} outputs on tiny dt ≈ 1e-12 first steps). Those differ at ulp-amplified level because the order-unrolled @muladd kernel changes FMA/summation order relative to the runtime-indexed loop; magnitudes are within normal floating-point reassociation noise.
  • Runic --check and typos clean on the changed files.
  • GROUP=Core and GROUP=QA for OrdinaryDiffEqBDF both pass locally (Pkg.test, Julia 1.12.4): all 14 Core testsets pass, and QA passes with the new allocation test among the 5 runtime-allocation passes.

Benchmarks

1,000 sol(out, t) calls on the in-place FBDF ROBER problem (reltol = abstol = 1e-8, dense = true), JULIA_NUM_THREADS=1 taskset -c 4, Julia 1.12.4, 3 repetitions (minimum over 7 samples each):

min ns (rep1/2/3) bytes allocs
master 286,139 / 286,309 / 290,049 127,936 2,000
this branch 162,360 / 170,819 / 171,469 0 0

@allocated sol(out, 1.0): 128 B → 0 B; @allocated sol(out, 1.0, Val{1}): 384 B → 0 B. Profile.Allocs on this branch records zero allocations from the interpolation path.

What was not verified

  • GPU (GROUP=GPU) tests — no GPU runner available locally; the new dispatch path uses only static Val branches and a throw, so it should remain GPUCompiler-safe.
  • The else fallback (n > 6) is unreachable in practice because the tables cap the active order at 6.

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

  • Independent review: Claude Code (Opus 5.5): MERGE, low risk, high confidence; 21.7M-value master comparison, alloc and perf claims reproduced; nits applied in 87b4637
  • Changes are confined to OrdinaryDiffEqBDF dense interpolation dispatch; kernel math is unchanged apart from compile-time order unrolling (values verified bitwise except the 12 scalar-ODE Val{1} reassociation cases noted above).
  • New test fails on master and passes with the fix.

🤖 Generated with Devin (model: swe-2-high), orchestrated by Claude Code (claude-opus-5-5[1m]) session https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Risk assessment

  • Risk: medium
  • Blast radius: FBDF/DFBDF dense interpolation, including derivatives and indexed outputs. No public signatures change, dependency internals are newly accessed, or tests are weakened; _ode_interpolant(!) are declared public extension points. The description discloses floating-point differences in 12 scalar derivative values; no breaking SemVer change identified.
  • Evidence: Head has 134 passing checks and five failures. Four match failures on recent master: GPU / Tests - GPU (Julia 1)—QNDF gpu_mismatch (head, master); downgrade-sublibraries / test (lib/DiffEqBase)—despecialized callback assertions (head, master); downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation)—missing diag(::ScalarOperator) (head, master); SciMLSensitivity.jl/Core1/1—Mooncake Any constructor error (head, master). These are pre-existing. SciMLSensitivity.jl/Core5/1 fails hybrid_de.jl:64, 15.393055f0 < 1.0, on head, but passes on preceding master and recent master: regression under the stipulated merge bar, with causation unresolved. BDF Core, QA, GPU, and downgrade checks pass. No review comments exist.
  • Independent review: Codex CLI 0.156.1 (Mac) / gpt-6-astra rated it medium, high confidence: the focused dispatch change preserves the kernel expressions, but Core5 fails where master passes, preventing a no-regressions verdict.
  • Merge: needs human review (resolve the Core5 regression; the PR description does not disclose the failing CI checks).

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Codex CLI 0.156.1 (Mac) / gpt-6-astra; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL)

ChrisRackauckas and others added 2 commits September 26, 2026 16:50
_CHEB_NODES and _BARY_WEIGHTS are tuples of differently sized tuples, so
indexing them with the runtime active order in the _ode_interpolant(!)
methods was type-unstable and boxed the lookup result. sol(out, t) on an
in-place FBDF ROBER solution allocated 128 bytes per call.

The interpolant bodies now live in _fbdf_interp(!) kernels dispatched on
a literal Val(1)..Val(6) through an unrolled branch, giving each kernel a
statically known order so the table lookups constant-fold. QNDF and
Nordsieck interpolants index homogeneous containers and are unchanged.
Derivative orders above 3 still throw DerivativeOrderNotPossibleError and
active orders above 6 BoundsError, matching the previous behavior.

Measured on ROBER with FBDF, 1,000 sol(out, t) calls (single thread):
128 B -> 0 B per call and ~286 us -> ~165 us minimum. Interpolated values
are bitwise identical to master at all 1,000 sample points.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: devin 3000.11.1
Agent-Model: swe-2-high
Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/pr-bdf/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-bdf/log.txt)
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: devin 3000.11.1
Agent-Model: swe-2-high
Agent-Session: local Devin session in /home/crackauc/sandbox/goals/performance/jobs/pr-bdf/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-bdf/log.txt)
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 28, 2026 11:56
@ChrisRackauckas
ChrisRackauckas merged commit 643b1bb into SciML:master Sep 28, 2026
137 of 142 checks passed
ChrisRackauckas referenced this pull request Sep 29, 2026
* Bump DiffEqBase to 7.21.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqBDF to 2.4.12

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSDIRK to 2.9.7

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqRosenbrock to 2.7.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqLowOrderRK to 2.2.6

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqTsit5 to 2.1.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqVerner to 2.4.2

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSymplecticRK to 2.2.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.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