Skip to content
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

Allow LLVM plugins in swift driver #38017

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

wsmoses
Copy link

@wsmoses wsmoses commented Jun 21, 2021

This PR enables the Swift Driver to load LLVM plugins, such as the Enzyme high-performance automatic differentiation toolkit (https://github.com/wsmoses/Enzyme).

@wsmoses
Copy link
Author

wsmoses commented Jun 25, 2021

@rxwei @dan-zheng

@wsmoses
Copy link
Author

wsmoses commented Dec 8, 2022

ping

@wsmoses
Copy link
Author

wsmoses commented Jul 14, 2023

@lhames any hopes of this getting reviewed/merged?

@lhames
Copy link
Contributor

lhames commented Jul 14, 2023

@wsmoses I'm not the right person to review this, but I'll ask around for you.

Could you elaborate on what you want to do with the plugin?

Whatever the motivation, the plugin machinery should probably be added to the new Swift driver, as the C++ swift driver is in maintenance mode.

@wsmoses
Copy link
Author

wsmoses commented Jul 14, 2023

Sure, the goal here is to enable usage of Enzyme -- a tool for performing automatic differentiation of LLVM (and present incubator project, which at one point we should talk with the community about transitioning).

It has been adopted in a variety of places including to much success in C++, Julia, etc. In addition to taking some of the autodiff burden off of swift, performing AD in the compiler enables significant performance gains (https://dl.acm.org/doi/abs/10.1145/3458817.3476165).

Some folks have experimented using it within swift (https://medium.com/passivelogic/using-enzyme-autodiff-with-swift-afa1bc2dc102) and found a 477x improvement over native swift autodiff (admittedly for a very small test code).

Doing so required some makefile hacking from the LLVM output, and adding plugin support would be nice to enable Enzyme to work with swift more nicely.

That said the Rust compiler as an example has chosen to include Enzyme directly as an llvm subproject (rust-lang/compiler-team#611), so that may also be a good option as well, if the Swift compiler devs would be receptive.

@lhames
Copy link
Contributor

lhames commented Jul 15, 2023

Sounds very cool.

@benlangmuir Just pointed out that an LLVM plugin would need to be loaded in the frontend process, not the driver, so making this accessible with a swift driver argument would involve changes in both.

Your patch just includes the LLVM PluginLoader header though. How were you invoking the plugin loading? With a -Xllvm argument?

@tgymnich
Copy link

tgymnich commented Jul 15, 2023

Yes, this is how we ran our tests: swiftc -import-objc-header enzyme.h -Xllvm -load=/LLVMEnzyme-11.so -Xllvm -enzyme ad. Although those test included some more changes to swift: main...EnzymeAD:swift:main

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.

3 participants