mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[AutoDiff] Enable variable debugging support for pullback functions.
- 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.
This commit is contained in:
@@ -95,6 +95,17 @@ FuncDecl *ADContext::getPlusEqualDecl() const {
|
||||
return cachedPlusEqualFn;
|
||||
}
|
||||
|
||||
AccessorDecl *ADContext::getAdditiveArithmeticZeroGetter() const {
|
||||
if (cachedZeroGetter)
|
||||
return cachedZeroGetter;
|
||||
auto zeroDeclLookup = getAdditiveArithmeticProtocol()
|
||||
->lookupDirect(getASTContext().Id_zero);
|
||||
auto *zeroDecl = cast<VarDecl>(zeroDeclLookup.front());
|
||||
assert(zeroDecl->isProtocolRequirement());
|
||||
cachedZeroGetter = zeroDecl->getOpaqueAccessor(AccessorKind::Get);
|
||||
return cachedZeroGetter;
|
||||
}
|
||||
|
||||
void ADContext::cleanUp() {
|
||||
// Delete all references to generated functions.
|
||||
for (auto fnRef : generatedFunctionReferences) {
|
||||
|
||||
Reference in New Issue
Block a user