-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DNM] remaining work for SIL COW representation #31730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@dan-zheng Can you please help me fixing a small issue with AutoDiff?
The reason is that the SIL code for Array literals looks a bit different. After storing all elements, a new runtime function is called. For details see: af196a1 I think it's a simple fix to handle this runtime function, but I'm not really understanding the code. |
I can help take a look today, thanks for the context! I wonder what is the urgency of this PR? I can try to share an update before EOD today. Edit: I took a look and think I understand what AutoDiff changes are necessary to support the new |
Thanks, it's not urgent |
63f564e
to
d26a144
Compare
@dan-zheng I rebased this PR. |
@dan-zheng Any progress on this? |
I will try to finish fixing the AutoDiff tests by tomorrow and share an update. Sorry for the delay! (It would be ideal to keep the AutoDiff tests passing because users depend on the tested behavior.) |
ok, thanks! BTW, I just rebased the PR. |
@dan-zheng Is there any update? |
Yes, the AutoDiff fixes have been done in eeckstein#3 for a few days. Sorry for not clarifying that explicitly, feel free to merge or cherry-pick it. |
Update differentiation to handle `array.finalize_intrinsic` applications. `VJPEmitter::visitApplyInst` does standard cloning for these applications. `PullbackEmitter::visitApplyInst` treats the intrinsic like an identity function, accumulating result's adjoint into argument's adjoint. This fixes array literal initialization differentiation.
For COW support in SIL it's required to "finalize" array literals. _finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored. This runtime function marks the array literal as finished. %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count) %mutable_array = tuple_extract %uninitialized_result_tuple, 0 %elem_base_address = tuple_extract %uninitialized_result_tuple, 1 ... store %elem_0 to %elem_addr_0 store %elem_1 to %elem_addr_1 ... %final_array = apply %_finalizeUninitializedArray(%mutable_array) In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
…e Array types. Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice. The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array. The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation". The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state. All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer flags indicates if the buffer is mutable or not. Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
@dan-zheng Thanks! |
The second part of #31728
Still work in progress. Not to be merged yet.