-
Notifications
You must be signed in to change notification settings - Fork 13.8k
libload / dlopen Enzyme/autodiff #146623
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: master
Are you sure you want to change the base?
libload / dlopen Enzyme/autodiff #146623
Conversation
This comment has been minimized.
This comment has been minimized.
|
||
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")?; |
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.
You could do something like
rust/compiler/rustc_interface/src/util.rs
Lines 371 to 381 in 8a1b399
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() | |
}) |
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.
Do you know a good way of getting the sysroot in rustc_codegen_llvm, where I do all the loading?
I tried to use a cell / static in my last commit to pass it from the frontend to the backend, but (presumably due to using different threads?) the CELL with the path to Enzyme ends up uninitialized in the thread trying to load it.
Since most of these functions are generic over backends, I also don't want to pass the Session object or Enzyme path to the llvm backend as fnc argument if it can be avoided.
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.
also @Kobzol since you might know.
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.
I think that adding the sysroot e.g. to CodegenContext
should be fine. Btw, note that statics don't work like you are using them, it seems like you expect a static with the same name to be "shared" across all usages of that name? https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d187e01b5231eaa65e9eaf64732545c0 Or maybe it's just some leftovers from debugging.
This comment has been minimized.
This comment has been minimized.
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 |
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. |
Yeah, if having |
☔ The latest upstream changes (presumably #146685) made this pull request unmergeable. Please resolve the merge conflicts. |
83a5a89
to
f1b0c51
Compare
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.