Repository navigation
Conversation
…ache `numeric_ldiv!` took its `LinearCache` from a `Dict` with `Any` values, so the `solve_into!` call after the lookup was a runtime dispatch. A `juliac --trim` build of generated code that inlines a numeric linear SCC then fails: `--trim=safe` reports the call as unresolved, and an `unsafe-warn` binary throws a `MethodError` on the first solve, for both `Float64` and `ForwardDiff.Dual` arguments. Assert the type a new cache infers to for the argument types, and key the cache by the type of `b` as well as `A` so the assertion always holds. License: AGPL-3.0-only Copyright: JuliaHub, Inc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…right-hand side `numeric_ldiv!` writes its solution into `b`, on the assumption that `b` belongs to its solve site alone. It does not: CSE merges the `b` buffers of two inline linear SCCs whose right-hand sides are equal, fills the merged buffer once, and passes it to both solves. The second solve then reads the first one's solution as its right-hand side, and both the RHS and its derivatives come back wrong without an error. Have `safe_ldiv`, the operation the generated code calls, solve a copy of `b`. That costs one allocation of the size of `b` per solve. `A` needs no copy: CSE shares it the same way, but `numeric_ldiv!` only copies it into the cache's own matrix and never writes to it. License: AGPL-3.0-only Copyright: JuliaHub, Inc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ambujone
marked this pull request as draft
December 1, 2026 05:16
Author
|
Moving this back to draft. While reviewing the neighbouring PRs I found two problems here:
I will rebase this onto #192 once it lands, or onto its branch if that is preferred, and derive the site id deterministically from the block instead of from a counter. I will also add the same inferred-type assertion #192 uses to the per-site cache entry. Until then, please review #192 first. |
…ar SCCs Builds on JuliaComputing#192. Key the task local LinearCache by array types, size, and a solve-site id, so inline SCCs of the same shape neither clobber each other's cache nor refactorize when A is unchanged (JuliaComputing#178). The cache entry keeps an A_prev copy and skips reassigning cache.A when A is identical to it. The site id is the SCC's index in the system, not a global counter, so compiling the same system twice gives isequal observed equations. The cache lookup keeps JuliaComputing#192's typed key and promote_op assertion, applied to the entry type, and safe_ldiv keeps its copy of b so numeric_ldiv! still overwrites b for the Enzyme rules, which now take the site id. License: Apache-2.0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ambujone
force-pushed
the
fix/inline-scc-per-site-cache
branch
from
December 1, 2026 05:34
09c32a2 to
350be5e
Compare
Author
|
Updated. This branch now sits on top of #192, so until #192 merges the diff includes its two commits. On top of that:
The full ModelingToolkitTearing suite, including |
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.
Fixes #178
Built on #192, so until #192 merges the diff includes its two commits. I'll rebase onto
mainafter it lands.The inline-SCC
LinearCacheis keyed by array types and size, so two inline SCCs of the same shape share one cache, overwrite each other's matrix and refactorize on every solve. This adds a site id, the SCC's index in the system, to the cache key. The id is passed throughsafe_ldiv,numeric_ldiv!,numeric_ldiv_again!,inline_linsolve_fell_backand the Enzyme rules. The lastAis stored next to the cache, so an unchanged (===)Ais not refactorized. Because the id is deterministic, compiling a system twice still givesisequalobserved equations. The cost is one cache plus one copy ofAper block per task, which I have not measured.Tests cover no clobbering between sites, zero allocations when
Ais unchanged, an@inferredlookup forFloat64,Dualand view arguments, repeated-compileisequal, and #192's shared-RHS testset. The ModelingToolkitTearing suite, includingenzyme.jl, passes locally on Julia 1.13.4.Prepared with Claude Code.