Repository navigation
Conversation
A Const argument that a custom EnzymeRules derivative rule reads (or writes) but the primal never touches was being dropped from a differentiated function's signature and replaced with jl_nothing, causing a segfault, whenever the call crossed a real (non-inlined) function boundary. The write-only/no-capture attributes trusted by shouldDisableNoWrite are inferred from the callee's primal semantics alone and cannot see that a custom rule reachable from within an otherwise-resolved callee may need the argument's real value. shouldDisableNoWrite (Utils.h) now also disables the no-write shortcut for any resolved callee with a body Enzyme will still analyze (not just truly opaque external declarations), covering DifferentialUseAnalysis.cpp, EnzymeLogic.cpp, and AdjointGenerator.h, which all share this predicate. Since the argument is now known to potentially be read/written despite carrying stale readnone/readonly/writeonly attributes copied from the primal, also drop those specific attributes (not enzyme_inactive or nocapture) wherever they get copied onto a Const argument: in FunctionUtils.cpp's CloneFunctionWithReturns, and in the two call-site attribute-copy loops in AdjointGenerator.h. Reported in EnzymeAD/Enzyme.jl#3570.
Member
|
Alternative EnzymeAD/Enzyme.jl#3610 |
Author
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.
Summary
A
Constargument that a customEnzymeRulesderivative rule reads or writes, but that the primal never touches, was being dropped from a differentiated function's signature and replaced withjl_nothingwhenever the call crossed a non-inlined function. Reported in EnzymeAD/Enzyme.jl#3570.shouldDisableNoWrite(Utils.h) trusted write-only/no-capture attribute inference for any call to a resolved callee, as long as neither the call nor the callee carried an explicit custom-rule marker. That inference is computed from the callee's own primal semantics but a custom derivative rule actually needs the argument.shouldDisableNoWritenow also disables the no-write shortcut for any resolved callee with a body Enzyme will still analyze. Since a Const argument is potentially be read/written,readnone/readonly/writeonlyattributes are also dropped wherever they get copied onto a Const argument. But only where the argument is actually passed to a callshouldDisableNoWritedisables trust for.Tests
ForwardMode/callee_const_arg.ll— a Const pointer argument of a resolved, non-custom-rule callee must not be pruned toundefbyshouldDisableNoWrite's strategy.ReverseMode/custom_const_state.ll— a Const pointer argument read and written by a combined!enzyme_augment/!enzyme_gradientcustom rule must reach the generated call as a real pointer, and the generated derivative's definition and call site must not keep a stalereadnone/readonly/writeonlyclaim. Covers all three attributes as separate variants, with the attribute asserted directly as a parameter attribute (not inferred from a whole-call attribute) so each variant exercises both copy sites independent of pass ordering.See EnzymeAD/Enzyme.jl#3570.