Skip to content

Commit f5f7dd8

Browse files
authored
[AutoDiff] Revamp array literal initialization differentiation. (#28320)
Array literal initialization requires special reverse-mode differentiation support because it is not a regular function application in SIL. Instead, it is lowered as an `array.uninitialized_intrinsic` application and `store`/`copy_addr` instructions that set individual array elements: ``` %result = apply %array.uninitialized_intrinsic : $(Array<T>, RawPointer) (%array, %ptr) = destructure_tuple %result %elt0 = pointer_to_address %ptr to $*T // element address %index_1 = integer_literal $Builtin.Word, 1 %elt1 = index_addr %elt0, %index_1 // element address ... ``` Previously, array literal initialization differentiation was handled as a special case in `PullbackEmitter::visitApplyInst`. `PullbackEmitter::visitArrayInitialization` visited active intrinsic applications, found all `store` and `copy_addr` instructions writing to array element addresses, and accumulated destination adjoints into source adjoints. This worked in cases when element values were computed before intrinsic applications, but not when element values were computed after intrinsic applications but before `store`/`copy_addr` instructions. Now, array literal initialization differentiation is handled as a special case in `PullbackEmitter` for `store` and `copy_addr` instructions. For each special `store` and `copy_addr` instruction, array element adjoints are accumulated into source adjoints. Activity analysis now marks element result addresses (`pointer_to_address` and `index_addr` instructions) of `array.uninitialized_intrinsic` applications as active. Add array literal initialization tests. Add negative tests for the following issues: - TF-975: multiple array literals. - TF-977: array literals with `tuple_element_addr` elements. - TF-978: apply with array literal address as indirect result. Resolves TF-952.
1 parent 9c929d4 commit f5f7dd8

File tree

4 files changed

+400
-180
lines changed

4 files changed

+400
-180
lines changed

0 commit comments

Comments
 (0)