Skip to content

Commit 59e5db4

Browse files
Update docs/DifferentiableProgrammingImplementation.md
Co-authored-by: Saleem Abdulrasool <[email protected]>
1 parent ef9fb88 commit 59e5db4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/DifferentiableProgrammingImplementation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ bb0(%x):
468468

469469
### Visiting the original function to create a JVP
470470

471-
In the Swift compiler, we have a class called [`JVPEmitter`](https://github.com/apple/swift/blob/main/lib/SILOptimizer/Mandatory/Differentiation.cpp) which subclasses [`TypeSubstCloner`](https://github.com/apple/swift/blob/master/include/swift/SIL/TypeSubstCloner.h). This uses the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) to visit the original function and generate the JVP function. Taking a look at the `JVPEmitter` class, there are methods like `visitApplyInst`, `visitStructExtractInst`, etc. Each of these methods visit an instruction that is important in the generation of the JVP and differential, and emits a newly mapped version. We handle each type of instruction differently, explained below.
471+
In the Swift compiler, we have a class called [`JVPCloner`](https://github.com/apple/swift/blob/main/include/swift/SILOptimizer/Differentiation/JVPCloner.h) which subclasses [`TypeSubstCloner`](https://github.com/apple/swift/blob/master/include/swift/SIL/TypeSubstCloner.h). This uses the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) to visit the original function and generate the JVP function. Taking a look at the `JVPCloner` class, there are methods like `visitApplyInst`, `visitStructExtractInst`, etc. Each of these methods visit an instruction that is important in the generation of the JVP and differential, and emits a newly mapped version. We handle each type of instruction differently, explained below.
472472

473473
One important note is that in the JVP, we visit every single instruction in the original function - sometimes it’s an exact copy, and other times there is some special logic we wrote to handle it differently (e.g. like control-flow discussed below). This is so that the JVP function behaves just like the original function. With this, if the original function has a print statement, the JVP will as well. However, when we consider the differential, we will only transform SIL instructions from the original that we deem to be fit (so no print statement in the differential!). These instructions are those that should be differentiated, which uses the activity analysis calculated earlier to determine which SIL instructions are important in computing the tangent values of a function.
474474

0 commit comments

Comments
 (0)