Fix eraseFictiousPHIs crash due to incorrect Seen map pre-seeding in allocation handling#2781
Draft
Fix eraseFictiousPHIs crash due to incorrect Seen map pre-seeding in allocation handling#2781
Conversation
…ves.cpp Agent-Logs-Url: https://github.com/EnzymeAD/Enzyme/sessions/b64ff612-8636-4417-949e-562e0b7dc78c Co-authored-by: minansys <149007967+minansys@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix enzyme crash for fictitious PHIs in CUDA code
Fix eraseFictiousPHIs crash due to incorrect Seen map pre-seeding in allocation handling
Apr 9, 2026
Collaborator
|
The fix did not resolve the issue, need a test case and 2nd round fix |
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.
GradientUtils::eraseFictiousPHIs()crashes withassert(pp->getNumUses() == 0)when differentiating certain CUDA code. The crash was introduced by commitbe435edfwhich addedunnecessaryIntermediatesto theSeenmap initialization in the allocation handling path ofCallDerivatives.cpp.Root cause
When an allocation
&callappears in bothknownRecomputeHeuristicandunnecessaryIntermediates, the loop inhandleKnownCallDerivativespre-seedsSeen[{&call, Primal}] = false. The subsequentis_value_needed_in_reverse(gutils, &call, Mode, Seen, ...)call immediately short-circuits at the memoization check:This makes
primalNeededInReverse = falseeven when the allocation's result is genuinely needed in the reverse pass, so a fictitious PHI is emitted in place of a cached value. That PHI retains users in the generated reverse code, triggering the assertion ineraseFictiousPHIs.Fix
After building
Seen, erase&call's own entry before callingis_value_needed_in_reverse:Other pre-seeded entries (other unnecessary intermediates) still propagate correctly through the dependency chain and help the analysis determine
&call's neededness — only the self-seeding that short-circuits the query is removed.