Skip to content
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
14 changes: 14 additions & 0 deletions lib/SIL/IR/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(
// are also set to IsSerialized.
Worklist.push_back(F);
}

if (F->markedAsAlwaysEmitIntoClient()) {
// For @_alwaysEmitIntoClient functions, we need to lookup its
// differentiability witness and, if present, ask SILLoader to obtain its
// definition. Otherwise, a linker error would occur due to undefined
// reference to these symbols.
for (SILDifferentiabilityWitness *witness :
F->getModule().lookUpDifferentiabilityWitnessesForFunction(
F->getName())) {
F->getModule().getSILLoader()->lookupDifferentiabilityWitness(
witness->getKey());
}
}

return;
}

Expand Down
24 changes: 24 additions & 0 deletions stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,27 @@ where
return (Self(repeating: value), { v in Self(repeating: v) })
}
}

%for (Scalar, bits) in [('Float',32), ('Double',64)]:
% for n in vectorscalarCounts:
extension SIMD${n} where Scalar == ${Scalar} {
@inlinable
@_alwaysEmitIntoClient
@derivative(of: init(repeating:))
static func _vjpInit(repeating value: Scalar)
-> (value: Self, pullback: (TangentVector) -> Scalar.TangentVector)
{
return (Self(repeating: value), { v in v.sum() })
}

@inlinable
@_alwaysEmitIntoClient
@derivative(of: init(repeating:))
static func _jvpInit(repeating value: Scalar)
-> (value: Self, differential: (Scalar.TangentVector) -> TangentVector)
{
return (Self(repeating: value), { v in Self(repeating: v) })
}
}
% end
%end
3 changes: 0 additions & 3 deletions stdlib/public/core/SIMDFloatConcreteOperations.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ extension SIMD${n} where Scalar == ${Scalar} {
_storage = ${Scalar}.SIMD${storageN}Storage(_builtin)
}

/* Breaks differentiation testing, commented out while we figure out
what to do about that.
@_alwaysEmitIntoClient @_transparent
public init(repeating scalar: ${Scalar}) {
let asVector = Builtin.insertelement_${Builtin}_FPIEEE${bits}_Int32(
Expand All @@ -52,7 +50,6 @@ extension SIMD${n} where Scalar == ${Scalar} {
))
%end
}
*/

% if n >= 4:
@_alwaysEmitIntoClient @_transparent
Expand Down
4 changes: 0 additions & 4 deletions test/stdlib/SIMDFloatInitializers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
// RUN: %target-swift-frontend -primary-file %t/SIMDFloatInitializers.swift -S | %FileCheck %t/SIMDFloatInitializers.swift --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECKOnone-%target-cpu
// RUN: %target-swift-frontend -primary-file %t/SIMDFloatInitializers.swift -S -O | %FileCheck %t/SIMDFloatInitializers.swift --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECKO-%target-cpu

// Disable this test for now because aEIC/transparent functions still are not
// correctly differentiable, and so these inits are suppressed in the stdlib.
// REQUIRES: differentiable-aEIC-transparent

import Swift

%for bits in [16,32,64]:
Expand Down