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

Enzyme support example #29

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open

Conversation

nkoukpaizan
Copy link
Collaborator

This builds on earlier work from Asher and Slaven to add examples using the Enzyme automatic differentiation library.
There are two new tests compared to develop that should pass.

Building Enzyme from source is discussed in #23. I tested that approach as well as building LLVM and Enzyme through Spack, and both approaches work for this use-case.

@nkoukpaizan nkoukpaizan self-assigned this Oct 30, 2024
@pelesh pelesh requested review from alexander-novo and reid-g and removed request for stonecoldhughes November 4, 2024 15:36
@pelesh pelesh added the enhancement New feature or request label Nov 4, 2024
@pelesh
Copy link
Collaborator

pelesh commented Nov 4, 2024

CC @ashermancinelli

@ashermancinelli
Copy link

Very cool to see!

@nkoukpaizan nkoukpaizan force-pushed the nicholson/enzyme-support branch from 65523d2 to fd75087 Compare December 19, 2024 15:49
add_custom_command(
DEPENDS ${PHASE2}
OUTPUT ${PHASE3}
COMMAND ${GRIDKIT_OPT} ${PHASE2} -load-pass-plugin=${ENZYME_LLVM_PLUGIN_LIBRARY} -passes=enzyme -o ${PHASE3} -S
Copy link

@ashermancinelli ashermancinelli Dec 19, 2024

Choose a reason for hiding this comment

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

If you don't want such a manual pipeline, you can use the plugin registration hooks that the opt pass plugin api provides (like registerOptimizerLastEPCallback, for example). See the docs here. Sorry I left you with such cursed cmake! 😅 You could also load the plugin from the command line like this:

clang++ -fpass-plugin=LLVMEnzyme.so -mllvm '-passes=default<O1>,enzyme,default<O3>' -o ./a.out

Copy link
Collaborator

@pelesh pelesh Dec 19, 2024

Choose a reason for hiding this comment

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

So, in CMake configuration you would set something like -DCMAKE_CXX_FLAGS="-fpass-plugin=LLVMEnzyme.so" -mllvm '-passes=default<O1>,enzyme,default<O3>'? That instead of creating a custom command in CMake?

Choose a reason for hiding this comment

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

Exactly. Instead of dumping the IR between phases, you can first register the enzyme pass as a plugin and then use the -mllvm -passes= argument to build a custom phase ordering so enzyme is thrown in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants