-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
feat: dlopen Enzyme #149271
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
base: main
Are you sure you want to change the base?
feat: dlopen Enzyme #149271
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -528,31 +528,37 @@ fn thin_lto( | |
| } | ||
| } | ||
|
|
||
| fn enable_autodiff_settings(ad: &[config::AutoDiff]) { | ||
| #[cfg(feature = "llvm_enzyme")] | ||
| pub(crate) fn enable_autodiff_settings( | ||
| sysroot: &rustc_session::config::Sysroot, | ||
| ad: &[config::AutoDiff], | ||
| ) { | ||
| let mut enzyme = llvm::EnzymeWrapper::get_or_init(sysroot); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can use |
||
|
|
||
| for val in ad { | ||
| // We intentionally don't use a wildcard, to not forget handling anything new. | ||
| match val { | ||
| config::AutoDiff::PrintPerf => { | ||
| llvm::set_print_perf(true); | ||
| enzyme.set_print_perf(true); | ||
| } | ||
| config::AutoDiff::PrintAA => { | ||
| llvm::set_print_activity(true); | ||
| enzyme.set_print_activity(true); | ||
| } | ||
| config::AutoDiff::PrintTA => { | ||
| llvm::set_print_type(true); | ||
| enzyme.set_print_type(true); | ||
| } | ||
| config::AutoDiff::PrintTAFn(fun) => { | ||
| llvm::set_print_type(true); // Enable general type printing | ||
| llvm::set_print_type_fun(&fun); // Set specific function to analyze | ||
| enzyme.set_print_type(true); // Enable general type printing | ||
| enzyme.set_print_type_fun(&fun); // Set specific function to analyze | ||
| } | ||
| config::AutoDiff::Inline => { | ||
| llvm::set_inline(true); | ||
| enzyme.set_inline(true); | ||
| } | ||
| config::AutoDiff::LooseTypes => { | ||
| llvm::set_loose_types(true); | ||
| enzyme.set_loose_types(true); | ||
| } | ||
| config::AutoDiff::PrintSteps => { | ||
| llvm::set_print(true); | ||
| enzyme.set_print(true); | ||
| } | ||
| // We handle this in the PassWrapper.cpp | ||
| config::AutoDiff::PrintPasses => {} | ||
|
|
@@ -571,9 +577,9 @@ fn enable_autodiff_settings(ad: &[config::AutoDiff]) { | |
| } | ||
| } | ||
| // This helps with handling enums for now. | ||
| llvm::set_strict_aliasing(false); | ||
| enzyme.set_strict_aliasing(false); | ||
| // FIXME(ZuseZ4): Test this, since it was added a long time ago. | ||
| llvm::set_rust_rules(true); | ||
| enzyme.set_rust_rules(true); | ||
| } | ||
|
|
||
| pub(crate) fn run_pass_manager( | ||
|
|
@@ -608,10 +614,6 @@ pub(crate) fn run_pass_manager( | |
| if enable_ad { write::AutodiffStage::DuringAD } else { write::AutodiffStage::PostAD } | ||
| }; | ||
|
|
||
| if enable_ad { | ||
| enable_autodiff_settings(&config.autodiff); | ||
| } | ||
|
|
||
| unsafe { | ||
| write::llvm_optimize(cgcx, dcx, module, None, config, opt_level, opt_stage, stage); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -726,6 +726,13 @@ pub(crate) unsafe fn llvm_optimize( | |
|
|
||
| let llvm_plugins = config.llvm_plugins.join(","); | ||
|
|
||
| let enzyme_fn = if consider_ad { | ||
| let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| wrapper.registerEnzymeAndPassPipeline | ||
| } else { | ||
| std::ptr::null() | ||
| }; | ||
|
|
||
| let result = unsafe { | ||
| llvm::LLVMRustOptimize( | ||
| module.module_llvm.llmod(), | ||
|
|
@@ -745,7 +752,7 @@ pub(crate) unsafe fn llvm_optimize( | |
| vectorize_loop, | ||
| config.no_builtins, | ||
| config.emit_lifetime_markers, | ||
| run_enzyme, | ||
| enzyme_fn, | ||
| print_before_enzyme, | ||
| print_after_enzyme, | ||
| print_passes, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -240,6 +240,18 @@ impl CodegenBackend for LlvmCodegenBackend { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| fn init(&self, sess: &Session) { | ||||||||||||||||||||||||
| llvm_util::init(sess); // Make sure llvm is inited | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[cfg(feature = "llvm_enzyme")] | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| use rustc_session::config::AutoDiff; | ||||||||||||||||||||||||
| if sess.opts.unstable_opts.autodiff.contains(&AutoDiff::Enable) { | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| use crate::back::lto::enable_autodiff_settings; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| enable_autodiff_settings(&sess.opts.sysroot, &sess.opts.unstable_opts.autodiff); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+247
to
+253
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| fn provide(&self, providers: &mut Providers) { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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.
nit: missing trailing newline