Repository navigation
Fix Float32 trust-region arithmetic in GPU kernels - #1267
Merged
ChrisRackauckas merged 1 commit intoSep 13, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.153.4 Agent-Model: gpt-6-astra Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
ChrisRackauckas
marked this pull request as ready for review
September 13, 2026 09:36
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 13, 2026
- Fix Float32 trust-region arithmetic in GPU kernels (#1267) 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) <noreply@anthropic.com>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/DiffEqGPU.jl
that referenced
this pull request
Sep 13, 2026
…on fix The released 2.14.5 carries the Float32 trust-region objective correction (SciML/NonlinearSolve.jl#1267) that Metal and oneAPI codegen tests need. Raise the compat floor so CI resolves the fixed release. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: swe-2-max Agent-Session: local session ID: atom-voice
ChrisRackauckas
added a commit
to SciML/DiffEqGPU.jl
that referenced
this pull request
Sep 13, 2026
* fix: restore Enzyme gradients through kernel ensembles
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* docs: clarify Enzyme feature coverage and event-time limitation
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* fix: preserve Enzyme gradients for multi-component kernel problems
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* Isolate Enzyme tests from OpenCL compiler dependencies
Keep all backend tests enabled and add a standalone structured CUDA
allocation regression for the unresolved upstream shadow rule failure.
CPU Enzyme: 6/6; QA: 27/27; JET: 75/75. Full OpenCL passes with
the SimpleNonlinearSolve override correction. CUDA needs hardware.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* Validate CUDA gradients with the structured allocation dependency fix
Temporarily pin the CUDA-only isolated test environment to the prepared
CUDACore 6.2.2 backport. Replace with an upstream release before merge.
Local dependency resolution and extension loading passed; the allocation
regression stopped at CUDA driver not functional. GPU CI remains required.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* Restrict Enzyme tests to CUDA and Const-mark scalar kernel args
GPU Enzyme rejects Active scalars; keep dt/abstol/reltol Const while
leaving problem arrays mutable for parameter sensitivities. Drop the
CPU Enzyme CI group and restore a non-Enzyme default test target so
OpenCL and other backends no longer resolve Enzyme's GPUCompiler.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Pass AbstractFloat kernel scalars as length-1 device arrays
Enzyme marks float dt/tolerances Active because they affect the loss;
GPU KernelAbstractions rejects Active by-value args but accepts Duplicated
arrays. Keep ForwardDiff Duals as scalars so OpenCL Dual ensembles still
compile.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Use 0-d device arrays for Enzyme-safe scalar kernel args
Length checks in the kernel made dt/tolerance loads type-unstable and
broke OpenCL IR. Specialize on Number / 0-d / other arrays instead.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Limit KernelODEProblem layout to CUDA backends
OpenCL Julia 1.12 aborts SPIR-V compilation with the Enzyme numeric-first
record. Keep ImmutableODEProblem on non-CUDA backends; CUDA still uses
KernelODEProblem for Enzyme type retention.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Type-stabilize CUDA KernelODEProblem selection for Enzyme
Runtime string checks made _adapt_kernel_problem return a Union, which
Enzyme rejects. Select the record via Val{occursin(...)} on the backend
type so CUDA stays KernelODEProblem and other backends stay concrete.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Generate concrete KernelODEProblem adaptation per backend
Val(Bool) dispatch still formed a Union for Enzyme. Use @generated
methods so CUDA ImmutableODEProblem adaptation always returns
KernelODEProblem and other backends always return the adapted problem.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Specialize scalar packing helpers to avoid Enzyme Unions
Dispatch _pack_kernel_scalar on AbstractFloat vs other values so dt and
tolerance packing stay concrete under reverse-mode analysis.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Fix OpenCL/Metal regressions and Enzyme SVector copy reverse
Keep @const probs and scalar dt off CUDA; pack 0-d scalars and use
non-Const kernels only on CUDA. Add Enzyme reverse for StaticArray
Ptr/CuPtr unsafe_copyto! (EnzymeCUDAExt covers AbstractFloat only).
Co-authored-by: Cursor <cursoragent@cursor.com>
* Isolate Enzyme prep to CUDA; restore master OpenCL path
Use taped KernelODEProblem adapts only on CUDA, keep master's host
Vector + single adapt for OpenCL/Metal, extend unsafe_copyto! reverse
to KernelODEProblem, and make the docs example a forward CPU solve.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Fix Enzyme host shadows and restore master OpenCL kernel ABI
Store KernelODEProblem in CUDA host Refs so build_solution can be
shadowed, Val-dispatch GPU batch_solve paths, and launch non-CUDA
kernels with master's nsteps/scalar args to stop Julia 1.12 SPIR-V breaks.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Isolate CUDA AD kernels and fix KernelODEProblem adapt
Keep master's kernels.jl byte-compatible for OpenCL/Metal, move Enzyme
kernels to kernels_ad.jl, and adapt only numeric KernelODEProblem fields
so ODEFunction specialize stays stable for docs and forward CUDA solves.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Avoid Enzyme StepRangeLen and Val-dispatch ODE kernel launches
Skip unused timeseries construction on CUDA (Enzyme range reverse
FieldError) and launch Const vs AD kernels via Val so OpenCL/Metal do
not specialize the CUDA AD path.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Load AD kernels only via CUDAExt; inactive time-matrix fill
Keep Enzyme @kernel definitions out of the OpenCL/Metal image, and mark
_init_time_matrix! inactive so Float64 Enzyme ensembles avoid Active
GPU fill! arguments.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Define Enzyme AD kernels in CUDAExt without mutating DiffEqGPU
Base.include into DiffEqGPU broke incremental compilation. Keep master
Const kernels in-tree and register AD launches via extension methods so
OpenCL/Metal never load the Enzyme kernels.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Bisect OpenCL: restore master lowerlevel and CUDAExt
Isolate whether Enzyme solve.jl alone triggers the Julia 1.12 OpenCL
SPIR-V break; CUDA Enzyme launches temporarily match master again.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Remove broken DiffEqGPU._init_time_matrix! Enzyme inactive rule
Co-authored-by: Cursor <cursoragent@cursor.com>
* Isolate KernelODEProblem to CUDAExt for OpenCL Dual SPIR-V
OpenCL ForwardDiff was crashing with LLVM Broken module because an extra
AbstractODEProblem subtype lived in the DiffEqGPU image. Keep the master
EnsembleGPUKernel path as the default batch_solve_gpukernel and define
KernelODEProblem plus the Enzyme prep only when CUDA loads.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Publicize GPU callback types used by CUDAExt
Co-authored-by: Cursor <cursoragent@cursor.com>
* Keep Enzyme AD kernels and KernelODEProblem out of OpenCL image
Restore CUDA-only Val launches with extension-defined AD kernels, move
KernelODEProblem into CUDAExt, mark time-matrix init inactive for Float64
Enzyme, and stop publishing undocumented extension hooks.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Use one EnsembleGPUKernel path for all backends
Drop CUDA-only Val forks and CUDAExt Enzyme duplicates. Share
KernelODEProblem prep, non-Const kernels, and scalar packing everywhere
so Enzyme and Dual backends use the same launch stack.
Co-authored-by: Cursor <cursoragent@cursor.com>
* test: skip in-kernel init regression on strict-codegen backends
"Initialization preprocessing runs once" drives an in-kernel
NonlinearSolve dispatch for a plain OverrideInitData that SPIR-V/Metal
codegen cannot lower (runtime typejoin/apply_type). The capability gap
reproduces on master; the rest of the OpenCL suite, including
Dual-numbered kernels, passes.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: swe-2-max
Agent-Session: local session emphasized-tune (transcript: ~/.local/share/devin/cli/summaries/history_28aa6521a9f440d1.md)
* qa: allow JET 0.11-0.12 and fix newly flagged definite-assignment issues
The QA lane moved to Julia 1.13, where JET 0.10.15 floods the report
with false UndefVarError positives for properly imported names. JET
0.12 supports 1.13 and instead finds real latent issues:
- `LeftRootFind` was referenced unqualified in GPUContinuousCallback
kwargs but never imported into DiffEqGPU (verified: `DiffEqGPU.LeftRootFind`
is undefined on Julia 1.12 too, so those defaults would throw if hit).
- `kernel`/`t`/`cpu_sols`/`q11` were assigned inside narrower conditionals
than their use sites, so JET could not prove definite assignment.
`q11` is now computed unconditionally before the `iszero(EEst)` split
(it is only read when `EEst > 1`, which implies nonzero), `kernel`
selection is an if-expression that errors on unexpected algorithms,
and the CPU-offload task/channel pair is bound to a single
always-defined `cpu_work` named tuple.
Verified locally: `GROUP=QA` passes on Julia 1.12.7 and 1.13.0 with
JET 0.12.1 (Quality Assurance 21/21, JET static analysis 75/75), and
fixed-step/adaptive/cpu_offload/SDE solves still run correctly.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_381cdc5dd0594daf.md
* test: register array-level Enzyme copy rules for aggregate records
EnzymeCUDAExt only provides unsafe_copyto! augmented_primal/reverse for
the array-level signatures when the eltype is AbstractFloat/Complex, so
Enzyme must descend into the array methods for KernelODEProblem. On
Julia 1.13 + Enzyme 0.13.203 that descent reaches a
EnzymeNoDerivativeError inside the CuArray upload path
(`adapt(dev, adapted_probs)` in batch_solve_up_kernel), breaking the
CUDA ensemble-gradient tests. Add matching rules for
StridedCuArray/Array copies of the aggregate record eltypes at both
arities, mirroring the extension's own structure.
Cannot be exercised locally (no NVIDIA GPU); CI CUDA lane verifies.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_381cdc5dd0594daf.md
* test: end continuous-callback bounce problem past the final event
The ball-bounce callback test integrates u1' = u2, u2' = -10 from
u0 = (45, 0): u1 crosses zero at t = 3, 9, and exactly t = 15, which
was also tspan[2]. Whether a continuous callback fires when the event
lands exactly on the integration endpoint is convention-dependent:
OrdinaryDiffEq's CPU solve does not apply the bounce there, while the
GPU kernel path can, producing an endpoint difference of exactly one
bounce magnitude (~60 in u2). Which side the comparison lands on is a
ULP-level hairline that Julia 1.13 flips (kernel codegen changed; the
identical failure reproduces on master on Julia 1.13 + CPU backend,
with Vern7 flipped there and Tsit5 flipped on CUDA).
Extend tspan to 16 so all three crossings are strictly interior events,
which every backend resolves the same way. The assertions and
tolerances are unchanged.
Verified: full testset 16/16 on GROUP=CPU under Julia 1.13 (where the
Vern7 comparison previously failed locally) and Julia 1.12.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <noreply@cognition.ai>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_e9ba8699c66b48e4.md
* fix: load Enzyme transfer rules and preserve host solver behavior
Replace test-only CUDA copy rules with a package extension, preserve active
aggregate fields, restore CPU and initialization coverage, and restrict AD
storage workarounds to differentiation. Preserve remake-compatible solution
problems and correct output allocation at coincident fixed-grid stops.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* test: specify tighter tolerances for adaptive callback comparisons
Use reltol=1e-6 and abstol=1e-9 for both solvers, retaining the existing
assertion thresholds. All 16 callback checks pass on the CPU backend.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* test: resolve released dependencies for Enzyme coverage
Remove the temporary CUDACore fork pin and require the released
SimpleNonlinearSolve 2.14.4 initialization fix. Document that released CUDA
validation still depends on upstream compatibility and allocation support.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* test: run CUDA solver checks before the isolated Enzyme suite
Keep all tests while allowing callback results to appear before any
released-dependency failure in the separate Enzyme environment.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293
* build: require SimpleNonlinearSolve 2.14.5 for the Float32 trust-region fix
The released 2.14.5 carries the Float32 trust-region objective correction
(SciML/NonlinearSolve.jl#1267) that Metal and oneAPI codegen tests need.
Raise the compat floor so CI resolves the fixed release.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: swe-2-max
Agent-Session: local session ID: atom-voice
* test: move the isolated Enzyme environment to test/enzyme/Project.toml
Replace the generated temporary environment — driven by custom
[targets] entries plus extras/compat entries in the main project — with
a checked-in test/enzyme/Project.toml following the test/qa convention.
DiffEqGPU resolves through a [sources] path entry, so the subprocess
only needs to instantiate; no TOML generation or Pkg.develop.
GROUP=Enzyme passes locally on Julia 1.13.0: extension imports 8/8,
aggregate transfers 8/8, scalar storage 8/8, solver gradients 10/10.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: swe-2-max
Agent-Session: local session ID: atom-voice
* test: move all Enzyme tests into test/enzyme/ in SciMLTesting form
Relocate the four Enzyme test files from test/qa/ and
test/gpu_kernel_de/ into the group folder so every Enzyme test lives
under test/enzyme/ alongside its Project.toml, matching the
SciMLTesting group layout: test_groups.toml declares the group and its
Julia matrix, and the folder Project.toml declares the
project-specific deps.
The subprocess now calls SciMLTesting.activate_group_env instead of a
bare instantiate. The helper sandbox-copies the env so Pkg never
writes the committed Project.toml, develops the package under test,
and backports the [sources] path semantics on Julia < 1.11 — the lts
matrix leg ignores [sources], so without it the group would test the
registered DiffEqGPU release instead of the checkout.
GROUP=Enzyme passes on Julia 1.10.12 and 1.13.0: extension imports
8/8, aggregate transfers 8/8, scalar storage 8/8, solver gradients
10/10, and the status output confirms DiffEqGPU is developed from the
local path on both versions.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: swe-2-max
Agent-Session: local session ID: atom-voice
---------
Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin <noreply@cognition.ai>
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.
Ignore until reviewed by @ChrisRackauckas.
SimpleTrustRegionpromotes its first objective value to Float64 when solving a Float32 problem. That introduces double arithmetic into GPU kernels and prevents compilation on Metal and oneAPI devices without Float64 support. Compute the initial objective in the solution element type, matching subsequent objectives, and type the alternate radius-update threshold consistently.The existing CUDA kernel group now checks both radius-update rules for a correct Float32 solution and absence of double arithmetic/comparisons in generated LLVM. Its assertions are shared with the local OpenCL/POCL reproducer; no dependencies or test groups are added.
History tracing with
git log -Sand inspection of its parent identifies cb2d24a as the introduction of both literals. The parent had no trust-region implementation. This is source-history attribution, not a run of the 2024 dependency environment.Verification
Julia 1.13.0, OpenCL 0.10.11, GPUCompiler 2.6.0, pocl_jll 7.1.3+9. The same shared regression was run against a copy of the package with the two source expressions reverted, then against this fix:
The unfixed solve returns the correct result on POCL, which supports Float64; the generated-code assertion discriminates the unsupported arithmetic that fails on the other backends.
Across the Core summaries: 35,620 passed and four pre-existing broken tests; this PR adds no skips or broken tests.
Runic,
typosover added lines, andgit diff --checkpassed. CUDA, Metal, and oneAPI execution were not run locally because the required hardware/driver is unavailable. The newly added CUDA test will run in the existing CUDA CI group. No docstrings or public API were changed, so no docs build was run.Local OpenCL wrapper using the same committed test assertions
Run from the repository root in a local environment containing this checkout of SimpleNonlinearSolve, SciMLBase, StaticArrays, KernelAbstractions, OpenCL, pocl_jll, Test, and InteractiveUtils:
Links
🤖 Generated with Codex CLI 0.153.4 (model: gpt-6-astra; local session ID: 01a07fcc-1c4f-7ee3-9a1e-51eaab7df293).