Skip to content

[AutoDiff] Fix pullback subset thunk generation crash. #33969

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

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/SILOptimizer/Differentiation/Thunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ getOrCreateSubsetParametersThunkForLinearMap(
if (!paramInfo.isIndirectMutating())
continue;
auto inoutArg = *std::next(ai->getInoutArguments().begin(), inoutArgIdx++);
allResults.insert(allResults.begin() + paramIdx, inoutArg);
unsigned mappedParamIdx = mapOriginalParameterIndex(paramIdx);
allResults.insert(allResults.begin() + mappedParamIdx, inoutArg);
}
assert(allResults.size() == actualIndices.parameters->getNumIndices() &&
"Number of pullback results should match number of differentiability "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %target-swift-frontend -emit-sil %s
// REQUIRES: asserts

// TF-1315: Pullback subset thunk generation crash due to unmapped parameter
// index for `inout` differentiability parameters.

import _Differentiation

func foo(_ x: Int, _ y: Float, _ z: inout Float) {}

@derivative(of: foo, wrt: (y, z))
func vjpFoo(_ x: Int, _ y: Float, _ z: inout Float) -> (
value: Void, pullback: (inout Float) -> Float
) {
fatalError()
}

@differentiable
func TF_1315(_ x: Float) -> Float {
var x = x
// The call to `foo` below triggers pullback subset parameter thunk generation.
// `foo` original function type: `(Int, Float, inout Float) -> ()`
// Actual parameter indices: 1, 2
// Desired parameter indices: 2
foo(1, 2, &x)
return x
}