Skip to content

Fix LinearScan Windows unwind crash in Dual ODE RHS - #111

Closed
ChrisRackauckas-Claude wants to merge 4 commits into
SciML:mainfrom
ChrisRackauckas-Claude:fix-580-linear-scan-unwind
Closed

ChrisRackauckas-Claude wants to merge 4 commits into
SciML:mainfrom
ChrisRackauckas-Claude:fix-580-linear-scan-unwind

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Please ignore this PR until it is reviewed by @ChrisRackauckas.

Fixes the kernel, does not stop using KIND_LINEAR_SCAN.

What changed and why

SciML/DataInterpolations.jl#580 is a Windows EXCEPTION_ACCESS_VIOLATION in ntdll!RtlVirtualUnwind2, isolated to KIND_LINEAR_SCAN (not KIND_BRACKET_GALLOP), more likely under @profview, hidden by print statements. It shows up when DataInterpolations evaluates short non-uniform interpolants from an OrdinaryDiffEq Dual RHS.

The linear-scan walk was:

@inbounds if Base.Order.lt(order, x, v[i])
    while i > lo
        i -= 1
        !Base.Order.lt(order, x, v[i]) && return i
    end

@inbounds if covering cond && return / cond && continue is a known-bad Windows unwind CFG. The kernels are now a straight if/return loop, @inbounds only on the loads, and @noinline so the walk is not inlined into a Dual Jacobian (or into the enum dispatcher that also contains SIMD llvmcall).

The SIMD scalar backward walks had the same && return shape and were rewritten the same way.

Search results are unchanged. Auto still picks KIND_LINEAR_SCAN for non-uniform length(v) ≤ 16.

A previous DataInterpolations PR remapped LINEAR_SCAN → BRACKET_GALLOP. That was the wrong fix and is closed: SciML/DataInterpolations.jl#582

Verification

Julia 1.12.6:

GROUP=Core  Pkg.test()  → 172223 pass
GROUP=QA    Pkg.test()  → qa.jl 21 pass, static_analysis_tests.jl 34 pass
runic -c on the touched .jl files: clean
typos on the diff: clean

Existing LinearScan / SIMDLinearScan / enum-dispatch tests are the correctness check (they already compared against Base.searchsortedlast/searchsortedfirst). New Dual-query test covers the ODE-Jacobian shape (Float64 knots, Dual query, Int hint).

What I did not verify

  • The Windows AV itself. This machine is Linux. I cannot show fail-before / pass-after of the crash. The Dual-query test passes on the old kernel too; it does not discriminate the unwind bug.
  • GPU, Downstream.

Judgment call

@noinline on just these two kernels. The FFF design wants kernels inlined; this is an explicit exception so the walk is not pasted into a Dual RHS. If someone can confirm the CFG rewrite alone is enough on Windows, the @noinline can be dropped.

The ±1 walk used `@inbounds if` around `cond && return` / `cond && continue`.
That control-flow shape produced invalid Windows unwind information
(ntdll!RtlVirtualUnwind2 ACCESS_VIOLATION) when DataInterpolations
evaluated KIND_LINEAR_SCAN from an OrdinaryDiffEq Dual Jacobian.

Rewrite the walk as a straight if/return loop, @inbounds only the loads,
and mark the kernels @noinline so they are not inlined into the Dual RHS.
Search results are unchanged.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
A search-only microbench hid the call. On get_idx + slope (the
DataInterpolations path) @noinline is 7.62 vs 3.57 ns Float64 lerp
and blocks Dual fusion. The CFG rewrite is the unwind fix; the
kernels stay @inline like the other strategy kernels.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

@noinline was a real hit. The earlier search-only microbench hid it because the enum dispatcher already had a call. On a fused lerp (DataInterpolations get_idx + slope), chained good hint, n=8, ns/call:

impl search F64 lerp F64 search Dual lerp Dual
orig heuristic 2.40 3.58 4.48 8.84
clean @inline 2.41 3.57 2.91 4.70
clean @noinline 3.69 7.62 4.44 8.80

@noinline is ~2× on Float64 lerp. Forced @inline matches orig on Float64 and is faster on Dual (heuristic does not inline the Dual method). Dropped @noinline; the kernels are @inline like the other strategy kernels. The unwind fix is the CFG rewrite only.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Agreed — this is not a real change. LLVM for the moved-@inbounds kernel is the same shape as the original (11 loads, 15 branches). Closing.

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