-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Enable variable debugging support for pullback functions. #36071
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
TODO: Add SIL tests. |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design LGTM
59659cf
to
8ac319a
Compare
@swift-ci please test and merge |
- Properly clone and use debug scopes for all instructions in pullback functions. - Emit `debug_value` instructions for adjoint values. - Add debug locations and variable info to adjoint buffer allocations. - Add `TangentBuilder` (a `SILBuilder` subclass) to unify and simplify special emitter utilities for tangent vector code generation. More simplifications to come. Pullback variable inspection example: ```console (lldb) n Process 50984 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = step over frame #0: 0x0000000100003497 main`pullback of foo(x=0) at main.swift:12:11 9 import _Differentiation 10 11 func foo(_ x: Float) -> Float { -> 12 let y = sin(x) 13 let z = cos(y) 14 let k = tanh(z) + cos(y) 15 return k Target 0: (main) stopped. (lldb) fr v (Float) x = 0 (Float) k = 1 (Float) z = 0.495846391 (Float) y = -0.689988375 ``` Resolves rdar://68616528 / SR-13535.
8ac319a
to
e3b480b
Compare
@swift-ci please test and merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, couple of minor comments inline. The most interesting is probably the one about the test.
@@ -269,6 +272,10 @@ class ADContext { | |||
Diag<T...> diag, U &&... args); | |||
}; | |||
|
|||
raw_ostream &getADDebugStream(); | |||
SILLocation getValidLocation(SILValue v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more descriptive name than get_Valid_Location() we could use here? Or perhaps add a Doxygen comment explaining what this function does?
@@ -0,0 +1,202 @@ | |||
//===--- TangentBuilder.cpp - Tangent SIL builder ------------*- C++ -*----===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: A C++ marker is only needed for .h files, where it's ambiguous whether it contains C or C++ code. A .cpp
file always contains C++ code.
@@ -69,6 +69,7 @@ func foo(_ x: Float) -> Float { | |||
// CHECK-SIL-LABEL: sil private [ossa] @fooTJpSpSr : $@convention(thin) (Float, @owned _AD__foo_bb0__PB__src_0_wrt_0) -> Float { | |||
// CHECK-SIL: bb0([[DY:%.*]] : $Float, [[PB_STRUCT:%.*]] : @owned $_AD__foo_bb0__PB__src_0_wrt_0): | |||
// CHECK-SIL: [[ADD_PB:%.*]] = destructure_struct [[PB_STRUCT]] : $_AD__foo_bb0__PB__src_0_wrt_0 | |||
// CHECK-SIL: debug_value [[DY]] : $Float, let, name "y" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to compile with -Xllvm -sil-print-debuginfo
and check that we also attach the correct scope, particularly if this was by cloning another function. You could check that the scope chain points back to this function and not to the original function that was cloned here (all assuming this code is result of a clone action of course :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, this would allow you to check that the right location is attached, too.
debug_value
instructions for adjoint values.TangentBuilder
(aSILBuilder
subclass) to unify and simplify special emitter utilities for tangent vector code generation. More simplifications to come.Pullback variable inspection example:
Resolves rdar://68616528 / SR-13535.