Replace local global shadows once a shadow global exists #3924
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 293 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.340
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #3924"
general
weight: 0.35
wsmoses
<!-- claude-projects-attribution: {"github_login":"vchuravy"} -->
_Requested by Valentin · project thread_
Stacked on #3920 (the revert of #3883). This implements the resolution suggested in https://github.com/EnzymeAD/Enzyme/pull/3883#issuecomment-7128648122.
What
invertPointerMkeeps giving a global withoutenzyme_shadowa zeroed local alloca as its shadow when no call in the function may touch it.EnzymeLogicnow records each such alloca and the memset that zeroes it, keyed by the global and vector lane. When a shadow global is later created for that global (ininvertPointerMorGetOrCreateShadowConstant), every recorded local shadow is replaced by it and its zeroing memset is erased. The alloca itself is left for later cleanup, since its function may still be being differentiated.Why
A function differentiated as a callee only checks its own calls. In the restored
global-activity-callee-global-shadow.ll,@fstores to@gand calls@leaf, which reads it.@diffeleafis created first, with a local shadow for@g(it makes no calls), and@diffefthen creates@g_shadowand reads the adjoint from it, so the gradient was 0. Now@diffeleafaccumulates into@g_shadow. Found differentiating MITgcm with LLVM flang and full LTO under-enzyme-global-activity.Behaviour change
Derivatives of one global now share one shadow, also across calls.
threadlocal_address.llused a local shadow of@counterin the combined reverse and forward derivatives and a shadow global in split reverse; they now share@counter_shadow, so the forward call read the adjoint the reverse call left behind (3, 7, 24 instead of 3, 3, 3). The test now declares@counter_shadowand resets it between calls.Testing
test/Enzymeandtest/Integrationfail on the same set as main locally (the Integration tests don't run in that environment, pluscache_for_reverse_arg.ll, which also fails on main there).tutorial_tracer_adjsens(LLVM df0a91f6, full LTO, global activity), with the #3883 guard replaced by this change: the Enzyme gradient matches TAF at all 5 grdchk points (relative difference at most 2.5e-13), bit-identical to the run with the guard.---
_Generated by Claude Code_