Skip to content

Conversation

ZuseZ4
Copy link
Member

@ZuseZ4 ZuseZ4 commented Sep 16, 2025

A draft @davidlattimore and I developed at RustChina Unconf.

Closes #143295

r? @bjorn3 Does that generally look like what you had in mind?

I'll update the compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs to also go through libloading, and load the right path rather than hardcoding it. So far it passes some tests, I assume the other ones only fail due to enzyme_ffi not being updated yet.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 16, 2025
@rust-log-analyzer

This comment has been minimized.

@@ -665,6 +665,22 @@ pub(crate) unsafe fn llvm_optimize(

let llvm_plugins = config.llvm_plugins.join(",");

fn call_dynamic() -> Result<*const c_void, Box<dyn std::error::Error>> {
unsafe {
let lib = libloading::Library::new("/home/manuel/prog/rust/build/x86_64-unknown-linux-gnu/enzyme/lib/libEnzyme-21.so")?;
Copy link
Member

Choose a reason for hiding this comment

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

You could do something like

let target = host_tuple();
let sysroot = sysroot
.all_paths()
.map(|sysroot| {
filesearch::make_target_lib_path(sysroot, target).with_file_name("codegen-backends")
})
.find(|f| {
info!("codegen backend candidate: {}", f.display());
f.exists()
})

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@Kobzol
Copy link
Member

Kobzol commented Sep 16, 2025

Sounds exciting! With this, will we still have to compile LLVM in some "special" way, so that it has support for Enzyme? Or is having the libEnzyme.so file on disk enough?

@ZuseZ4
Copy link
Member Author

ZuseZ4 commented Sep 17, 2025

That's not an issue anymore, I had removed all extra handling multiple months ago, in my previous push to get it on nightly. The only thing left would now be to add Enzyme as a downloadable rustup component. Would you be able to help with that and take over once I cleaned up and landed this PR @Kobzol? I don't know much about distributions and would like to avoid to have this laying around too many extra months.

@Kobzol
Copy link
Member

Kobzol commented Sep 17, 2025

Yeah, if having libEnzyme.so on disk is enough, then I can help getting that into rustup. There are still some questions to resolve, but we can leave that for a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enzyme should be loaded on-demand at runtime
5 participants