Skip to content

Keep adaptive Tsit5 dense-output state out of registers; skip qold^0 pow in I controller - #566

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:tsit5-kernel-registers
Oct 2, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:tsit5-kernel-registers

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Ignore this draft until reviewed by @ChrisRackauckas.

What changed and why

SciMLBenchmarks' Lorenz work-precision benchmark measures GPUTsit5IController at 1.4–2x the per-trajectory kernel time of GRADSOLVE's cuda_tsit5, even though both take the same step sequence. I compiled both kernels for sm_70 (V100) and compared them. Two causes are contained in DiffEqGPU:

  1. Dense-output state is loop-carried in endpoint-only solves. After the step loop, ode_asolve_kernel interpolates us[end] = integ(tspan[2]) if integ.t > tspan[2], and then unconditionally writes us[2] = integ.u. With saveat === nothing and save_everystep = false the output has two rows, so us[end] is us[2] and the interpolated value is always overwritten. The compiler can't prove that, so k1–k6, uprev, tprev and dt stay live across every step. The interpolation now runs only on the path where its result is kept. This takes the Float64 kernel from 186 to 102 registers.
  2. The I controller evaluates qold^0 on every step attempt. beta2 = 0 for GPUTsit5IController, but q11 / qold^beta2 still emits a second __internal_accurate_pow call (about 139 SASS instructions, 82 of them FP64). _qold_factor returns one(qold) for the I controller. pow(x, 0) == 1 for every x, NaN included, so the result is unchanged.

Both changes leave the output unchanged. Endpoint and saveat outputs of vectorized_asolve on the KA CPU backend are bitwise identical between master and this branch in all 24 cases I compared: Lorenz, 64 trajectories, both algorithms, Float32 and Float64, rtol 1e-6 and 1e-9, tf of 1 and 7.

PTX / ptxas evidence (sm_70, no GPU)

The kernel is ode_asolve_kernel as vectorized_asolve launches it on CUDABackend(prefer_blocks = true), running the benchmark's @muladd Lorenz RHS. I compiled it through GPUCompiler with PTXCompilerTarget(cap = v"7.0", ptx = v"7.8"), linked libdevice from CUDA 12.9, and ran ptxas -v -arch=sm_70 (CUDA 12.9). The "loop" figures count SASS instructions in the main step loop's body only. Called subroutines are excluded, so pow is listed separately.

Kernel Registers Spill st/ld pow calls per attempt Loop SASS Loop DFMA/DMUL/DADD/DSETP Loop IMAD (all variants) + MOV + FSEL
F64 I, master 186 0 / 0 2 647 166/47/24/26 163+47+38
F64 I, this PR 99 0 / 0 1 548 159/46/23/24 124+17+37
F64 PI, master 188 0 / 0 2 703 173/48/26/29 176+51+42
F64 PI, this PR 108 0 / 0 2 657 173/48/26/29 156+25+42
F32 I, master 94 0 / 0 inline 459 FFMA 166 25+58+16
F32 I, this PR 53 0 / 0 inline 417 FFMA 161 23+28+17
F32 PI, master 95 0 / 0 inline 555 FFMA 190 22+69+20
F32 PI, this PR 54 0 / 0 inline 528 FFMA 190 19+44+20
GRADSOLVE F64 (reference) 74 0 / 0 1 378 138/45/11/12 65+11+10
GRADSOLVE F32 (reference) 40 0 / 0 inline 327 FFMA 146 0+27+3

For the F64 I controller, the loop body plus its pow bodies goes from 925 (647 + 2 × 139) to 683 (548 + 135) SASS instructions per attempt (GRADSOLVE: 378 + 128 = 506). FP64-pipe operations go from 427 to 334 (GRADSOLVE: 290). Every variant has a 32-byte stack frame that only the exception-reporting path uses. There is no ld.local anywhere, the loop has no st.local, and the tableau is constant-folded into cmem[2], so the integrator is not in local memory, either before or after this change.

Register-limited occupancy ceilings, calculated with NVIDIA's cuda_occupancy.h for sm_70 (which accounts for the four register-file partitions), scanning block sizes 32–1024: F64 I goes from 8 to 16 resident warps per SM, F64 PI from 8 to 16, F32 I from 20 to 36, and F32 PI from 20 to 36. The figures are the same at 128 threads per block. GRADSOLVE is at 24 (F64) and 48 (F32). These are calculated ceilings, not measured achieved occupancy.

GPU speed is unverified

This machine has no NVIDIA GPU. The numbers above are static compiler output, not timings. The expected effect is a large part of the gap for the F64 I controller and a smaller effect for the PI controller, which still needs two pow calls per step. Someone needs to rerun benchmarks/DiffEqGPU/lorenz_workprecision.jmd on a GPU to confirm it.

Verification

  • CPU, OpenCL and Enzyme groups on Julia 1.10.12 (LTS) and 1.12.7 (logs summarized below)
  • Runic --check on the changed files: clean. typos: clean.
  • The new test checks that _qold_factor for the I controller is === to qold^zero(T) for finite, floatmax, Inf and NaN inputs, which is the property that makes skipping pow exact. This is a performance change, not a bug fix, so there is no failing-before test. The register counts are the discriminating evidence, and CI cannot check them without a GPU.
Group Julia 1.10.12 (LTS) Julia 1.12.7
CPU 767 passed, 0 failed 767 passed, 0 failed
OpenCL (pocl) 474 passed, 0 failed 474 passed, 0 failed
Enzyme 34 passed, 0 failed 34 passed, 0 failed
QA 100 passed, 0 failed not run

Each run ended with Testing DiffEqGPU tests passed.

Not run: the CUDA group, GPU timing, and the pre Julia channel.

What remains of the gap (not in this PR)

These are listed roughly by estimated size. They all change rounding or behaviour, so they belong in separate PRs:

  • The PI controller computes EEst^beta1 and qold^beta2 with two accurate pow calls per attempt. Sharing a log between them, or computing the factor in Float32 (GRADSOLVE's -DCHEAP_CTRL), would remove most of the rest of the PI gap, but both change the step sizes at the roundoff level.
  • The controller has 2–3 more IEEE divisions per attempt than GRADSOLVE (q11 / gamma, q / gamma, dt / q), and Julia's NaN-propagating max/min add DSETP.NAN + FSEL pairs.
  • dt < 1e-14 && error("dt<dtmin") costs one compare per attempt plus the exception path (vprintf, trap). It is minor.
  • Problems are read from an array-of-structs ImmutableODEProblem array, and results are written to (2, N) matrices of SVectors, where GRADSOLVE uses coalesced structure-of-arrays I/O. This happens only once per trajectory, and there are no global loads or stores inside the step loop, so it is a few percent at most.

Risk assessment

  • Risk: low. Confidence: high. The change is 11 lines of source in the endpoint write-back of ode_asolve_kernel and the I-controller history factor. The other saving branches keep their interpolation, and PI controller arithmetic is unchanged.
  • Evidence: outputs are bitwise identical to master in the 24 endpoint/saveat cases above. An independent review (Codex, gpt-6-astra) also found 256 more base/head comparisons that matched exactly, covering callbacks, termination, multiple tstops, prefilled buffers and a callback-forced overshoot through the edited branch. The same review reproduced the CPU/OpenCL/Enzyme/QA results and the register and loop counts.
  • CUDA execution and speed are unverified. No NVIDIA GPU was available for the author or the reviewer.

🤖 Generated with Claude Code (model: claude-opus-5-5[1m])

https://claude.ai/code/session_01SJfy3ez7u4CqvAerKrT5np

Endpoint-only adaptive solves (`saveat === nothing`, `save_everystep = false`)
write `us[2] = integ.u` after the step loop. The overshoot interpolation
`us[end] = integ(tspan[2])` before it targets the same element (the output has
two rows), so its result was always overwritten, but it kept k1-k6, uprev and
tprev live across every step. Only run it when its result is kept.

The I controller has beta2 = 0, so `qold^beta2` is exactly one. Skip that
`pow` call instead of evaluating it on every step attempt.

Both changes are output-neutral. For the Lorenz ensemble compiled for sm_70
the GPUTsit5IController Float64 kernel goes from 186 to 99 registers and from
two `__internal_accurate_pow` calls per attempt to one.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.280
Agent-Model: claude-opus-5-5[1m]
Agent-Session: https://claude.ai/code/session_01SJfy3ez7u4CqvAerKrT5np
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 2, 2026 18:59
@ChrisRackauckas
ChrisRackauckas merged commit 805d50a into SciML:master Oct 2, 2026
27 of 31 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/DiffEqGPU.jl that referenced this pull request Oct 2, 2026
…l-host-fastpath

Picks up SciML#566 (dense-output state out of registers) and SciML#568, whose
Annotation-typed backend parameter in the _kernel_transfer Enzyme rule
supersedes this branch's unannotated-parameter variant; the file is
identical to master after resolution.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <noreply@cognition.ai>
Agent-Harness: Devin CLI 3000.11.3
Agent-Model: swe-2-high
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/DiffEqGPU.jl/jobs/560-devin/log.txt on amdci2.julia.csail.mit.edu
ChrisRackauckas referenced this pull request Oct 14, 2026
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