Fix revert mode for memref.alloca#2826
Conversation
| void mlir::enzyme::MGradientUtils::setInvertedPointer(Value val, Value toset) { | ||
| assert(getShadowType(val.getType()) == toset.getType()); | ||
| auto found = invertedPointers.lookupOrNull(val); | ||
| assert(found != nullptr); |
There was a problem hiding this comment.
why are you removing the assert here?
There was a problem hiding this comment.
are we expecting missing entries for val?
There was a problem hiding this comment.
I previously thought that a mutable block argument is mapped to a real value rather than a PlaceholderOp, so found.getDefiningOp<PlaceholderOp>() would return null. But I have now carefully checked that mutable values do not go through the addToDiffe → setDiffe path, we do not need to worry about that
|
|
||
| if (mode == DerivativeMode::ForwardMode || | ||
| mode == DerivativeMode::ForwardModeSplit) { | ||
| mode == DerivativeMode::ForwardModeSplit || isMutable) { |
There was a problem hiding this comment.
func.func @square(%x : memref<f64>){
%y = memref.load %x[] : f64
return %y
}
%out = enzyme.fwddiff dsquare(%x : memref<f64>, %dx : memref<f64>) {act = [enzyme_dup] ....}In this case, the user provides the inverted Pointer right? We should ensure that we arent creating a shadow
There was a problem hiding this comment.
i have add a guard in setDiffe when val is mutable or intertedPointers[val] is not a placeholderop, we skip instead of rewriting it.
scf.parallel + memref.store/memref.dimto replacelinalg.fillenzyme.placeholderwith real shadowThe key issue for memref.alloca is: the mutable type's enzyme.placeholder does not be subtitute by the real shadow in reverse mode.
The output before fix: