Skip to content

[AutoDiff] Define derivative for concrete SIMD.init(repeating:) #81864

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

Conversation

kovdan01
Copy link
Contributor

The PR #81766 introduced some concrete SIMD operations, but init(repeating:) was temporarily disabled due to differentiation testing break. See:

stephentyrone@7a00619

This PR contains two changes:

  1. Define custom derivatives for concrete init(repeating:) so we do not fall into non-differentiability error diagnostic.

  2. Add a fix to SIL linker so differentiability witness lookup is done when the original function has both @_alwaysEmitIntoClient and @_transparent. Similar changes were introduced previously in [AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions #78908, but they only handled @_alwaysEmitIntoClient without @_transparent.

@kovdan01 kovdan01 requested a review from asl May 30, 2025 09:03
@kovdan01 kovdan01 marked this pull request as ready for review May 30, 2025 09:04
@kovdan01 kovdan01 requested review from a team and jckarter as code owners May 30, 2025 09:04
@kovdan01 kovdan01 requested a review from stephentyrone May 30, 2025 09:05
@kovdan01
Copy link
Contributor Author

Tagging @JaapWijnen

@kovdan01
Copy link
Contributor Author

@swift-ci please test

The PR swiftlang#81766 introduced some concrete SIMD operations, but
`init(repeating:)` was temporarily disabled due to differentiation
testing break. See:

stephentyrone@7a00619

This PR contains two changes:

1. Define custom derivatives for concrete `init(repeating:)` so we do
   not fall into non-differentiability error diagnostic.

2. Add a fix to SIL linker so differentiability witness lookup is done
   when the original function has both `@_alwaysEmitIntoClient` and
   `@_transparent`. Similar changes were introduced previously in
   swiftlang#78908, but they only handled `@_alwaysEmitIntoClient` without
   `@_transparent`.
@kovdan01 kovdan01 force-pushed the autodiff-simd-concrete-float-init branch from 3089b0f to 25f789e Compare May 30, 2025 11:52
@kovdan01
Copy link
Contributor Author

@swift-ci please test

@@ -455,3 +455,34 @@ where
return (Self(repeating: value), { v in Self(repeating: v) })
}
}

%for (Scalar, bits) in [('Float16',16), ('Float',32), ('Double',64)]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the Float16 piece here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 591e19c, thanks

% if bits == 16:
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
@available(SwiftStdlib 5.3, *)
% end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And remove this and the trailing if block as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 591e19c, thanks

@kovdan01
Copy link
Contributor Author

@swift-ci please test

@stephentyrone stephentyrone enabled auto-merge (squash) May 31, 2025 00:56
@stephentyrone stephentyrone merged commit bcc7ed9 into swiftlang:main May 31, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants