-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions #78908
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
[AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions #78908
Conversation
|
Tagging @asl |
196d2d4 to
c75bc66
Compare
c75bc66 to
bb90693
Compare
|
Tagging @JaapWijnen @rxwei |
|
@swift-ci please test |
bb90693 to
ffa5f81
Compare
|
@swift-ci please test |
ffa5f81 to
6bb9def
Compare
|
@swift-ci please test |
6bb9def to
0b9bf45
Compare
|
@swift-ci please test |
|
Would be glad to see feedback from everyone interested |
|
Would be glad to see feedback from everyone interested |
4 similar comments
|
Would be glad to see feedback from everyone interested |
|
Would be glad to see feedback from everyone interested |
|
Would be glad to see feedback from everyone interested |
|
Would be glad to see feedback from everyone interested |
|
@lorentey will you please take a look on stdlib changes? |
|
@jckarter Can you take a look into sil linker part? Thanks! |
|
@kovdan01 Will you please update the description? To summarize what is done, what is the issue, etc. |
Sure, I've updated the PR description. |
3 similar comments
stephentyrone
left a comment
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.
Stdlib and test changes are fine. Compiler changes all look reasonable, and do not effect code that isn't using differentiable Swift, so I'm OK with taking this.
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`.
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 #78908, but they only handled `@_alwaysEmitIntoClient` without `@_transparent`. <!-- If this pull request is targeting a release branch, please fill out the following form: https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1 Otherwise, replace this comment with a description of your changes and rationale. Provide links to external references/discussions if appropriate. If this pull request resolves any GitHub issues, link them like so: Resolves <link to issue>, resolves <link to another issue>. For more information about linking a pull request to an issue, see: https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue --> <!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci Thank you for your contribution to Swift! -->
…tions (swiftlang#78908) Consider an `@_alwaysEmitIntoClient` function and a custom derivative defined for it. Previously, such a combination resulted different errors under different circumstances. Sometimes, there were linker errors due to missing derivative function symbol - these occurred when we tried to find the derivative in a module, while it should have been emitted into client's code (and it did not happen). Sometimes, there were SIL verification failures like this: ``` SIL verification failed: internal/private function cannot be serialized or serializable: !F->isAnySerialized() || embedded ``` Linkage and serialization options for the derivative were not handled properly, and, instead of PublicNonABI linkage, we had Private one which is unsupported for serialization - but we need to serialize `@_alwaysEmitIntoClient` functions so the client's code is able to see them. This patch resolves the issue and adds proper handling of custom derivatives of `@_alwaysEmitIntoClient` functions. Note that either both the function and its custom derivative or none of them should have `@_alwaysEmitIntoClient` attribute, mismatch in this attribute is not supported. The following cases are handled (assume that in each case client's code uses the derivative). 1. Both the function and its derivative are defined in a single file in one module. 2. Both the function and its derivative are defined in different files which are compiled to a single module. 3. The function is defined in one module, its derivative is defined in another module. 4. The function and the derivative are defined as members of a protocol extension in two separate modules - one for the function and one for the derivative. A struct conforming the protocol is defined in the third module. 5. The function and the derivative are defined as members of a struct extension in two separate modules - one for the function and one for the derivative. The changes allow to define derivatives for methods of `SIMD`. Fixes swiftlang#54445
…tions (swiftlang#78908) Consider an `@_alwaysEmitIntoClient` function and a custom derivative defined for it. Previously, such a combination resulted different errors under different circumstances. Sometimes, there were linker errors due to missing derivative function symbol - these occurred when we tried to find the derivative in a module, while it should have been emitted into client's code (and it did not happen). Sometimes, there were SIL verification failures like this: ``` SIL verification failed: internal/private function cannot be serialized or serializable: !F->isAnySerialized() || embedded ``` Linkage and serialization options for the derivative were not handled properly, and, instead of PublicNonABI linkage, we had Private one which is unsupported for serialization - but we need to serialize `@_alwaysEmitIntoClient` functions so the client's code is able to see them. This patch resolves the issue and adds proper handling of custom derivatives of `@_alwaysEmitIntoClient` functions. Note that either both the function and its custom derivative or none of them should have `@_alwaysEmitIntoClient` attribute, mismatch in this attribute is not supported. The following cases are handled (assume that in each case client's code uses the derivative). 1. Both the function and its derivative are defined in a single file in one module. 2. Both the function and its derivative are defined in different files which are compiled to a single module. 3. The function is defined in one module, its derivative is defined in another module. 4. The function and the derivative are defined as members of a protocol extension in two separate modules - one for the function and one for the derivative. A struct conforming the protocol is defined in the third module. 5. The function and the derivative are defined as members of a struct extension in two separate modules - one for the function and one for the derivative. The changes allow to define derivatives for methods of `SIMD`. Fixes swiftlang#54445
Consider an
@_alwaysEmitIntoClientfunction and a custom derivative definedfor it. Previously, such a combination resulted different errors under different
circumstances.
Sometimes, there were linker errors due to missing derivative function symbol -
these occurred when we tried to find the derivative in a module, while it
should have been emitted into client's code (and it did not happen).
Sometimes, there were SIL verification failures like this:
Linkage and serialization options for the derivative were not handled properly,
and, instead of PublicNonABI linkage, we had Private one which is unsupported
for serialization - but we need to serialize
@_alwaysEmitIntoClientfunctionsso the client's code is able to see them.
This patch resolves the issue and adds proper handling of custom derivatives
of
@_alwaysEmitIntoClientfunctions. Note that either both the function andits custom derivative or none of them should have
@_alwaysEmitIntoClientattribute, mismatch in this attribute is not supported.
The following cases are handled (assume that in each case client's code uses
the derivative).
Both the function and its derivative are defined in a single file in
one module.
Both the function and its derivative are defined in different files which
are compiled to a single module.
The function is defined in one module, its derivative is defined in another
module.
The function and the derivative are defined as members of a protocol
extension in two separate modules - one for the function and one for the
derivative. A struct conforming the protocol is defined in the third
module.
The function and the derivative are defined as members of a struct
extension in two separate modules - one for the function and one for the
derivative.
The changes allow to define derivatives for methods of
SIMD.Fixes #54445