Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix ownership issues with sequences of partial_apply's in AutoDiff closure specialization pass #80662

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 2 commits into from
Apr 15, 2025

Conversation

asl
Copy link
Contributor

@asl asl commented Apr 9, 2025

Each partial_apply consumes its arguments, therefore we should never release intermediate ones in the sequence of closures.

Fixes #78847

AutoDiff closure specialization pass: each partial_apply consumes its
arguments, therefore we should never release intermediate ones in
the sequence of closures.

Fixes #78847
@asl asl requested a review from eeckstein as a code owner April 9, 2025 01:03
@asl asl changed the title Fix ownership issues with sequences of partial_apply's in Fix ownership issues with sequences of partial_apply's in AutoDiff closure specialization pass Apr 9, 2025
@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

I also added end-to-end swift test to test the pass, apparently there are no tests for this.

@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

@swift-ci please test

@asl asl requested a review from jkshtj April 9, 2025 01:05
@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

The explanation of wrong behavior is in #78847 (comment)

@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

Reenabling it back also gives huge performance boost. We are having (on benchmark from #80665)

Before:

Benchmark_O-arm64-apple-macosx13.0 AutoDiffBuildingSimulator.Reverse
  # TEST                              SAMPLES      MIN   MEDIAN      MAX
 53 AutoDiffBuildingSimulator.Reverse         1   17.174   17.174   17.174

After:

Benchmark_O-arm64-apple-macosx13.0 AutoDiffBuildingSimulator.Reverse
  # TEST                              SAMPLES      MIN   MEDIAN      MAX
 53 AutoDiffBuildingSimulator.Reverse         1    4.670    4.670    4.670

@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

Tagging @JaapWijnen

@JaapWijnen
Copy link
Contributor

Nice! Also the performance boost. Is this boost related to the loss in performance we saw in January @asl ? Or separate and thus an improvement on top of the performance we had in early January?

@asl
Copy link
Contributor Author

asl commented Apr 9, 2025

@JaapWijnen Correct. This brings the performance back to January figures

@eeckstein Here is what happened:

@jkshtj
Copy link
Contributor

jkshtj commented Apr 9, 2025

Looks good from what I can tell. Thanks for fixing!

@asl asl force-pushed the autodiff-closure-spec-ossa-fix branch from acb54c2 to a2c214c Compare April 10, 2025 22:42
@asl
Copy link
Contributor Author

asl commented Apr 10, 2025

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Apr 15, 2025

@swift-ci please smoke test

@asl asl enabled auto-merge (squash) April 15, 2025 09:34
@asl asl merged commit 87ca0f8 into main Apr 15, 2025
5 checks passed
@asl asl deleted the autodiff-closure-spec-ossa-fix branch April 15, 2025 14:14
clackary pushed a commit to clackary/swift that referenced this pull request May 1, 2025
Fix ownership issues with sequences of partial_apply's in AutoDiff closure specialization pass (swiftlang#80662)

Each partial_apply consumes its arguments, therefore we should never release intermediate ones in the sequence of closures.

Fixes swiftlang#78847

(cherry picked from commit 87ca0f8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The AutodiffClosureSpecialization pass creates SIL with invalid ownership when enabling OSSA modules
3 participants