-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: develop
Are you sure you want to change the base?
Conversation
Very cool to see! |
65523d2
to
fd75087
Compare
add_custom_command( | ||
DEPENDS ${PHASE2} | ||
OUTPUT ${PHASE3} | ||
COMMAND ${GRIDKIT_OPT} ${PHASE2} -load-pass-plugin=${ENZYME_LLVM_PLUGIN_LIBRARY} -passes=enzyme -o ${PHASE3} -S |
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.
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
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.
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?
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.
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.
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.