Skip to content

Conversation

@sgasho
Copy link
Contributor

@sgasho sgasho commented Nov 24, 2025

related issue: #145899
related pr: #146623

This PR is a continuation of #146623

I refactored some code for #146623 and added the functions shown in #144197

r? @bjorn3
cc: @ZuseZ4

Zulip link: https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/libload.20.2F.20dlopen.20Enzyme.2Fautodiff/near/553647912

@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

cc @ZuseZ4

@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-review Status: Awaiting review from the assignee but also interested parties. 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 Nov 24, 2025
@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 24, 2025

That's exciting, and is gonna make some people on the infra team very happy. Just to be sure, are the tests still passing?

@rust-log-analyzer

This comment has been minimized.

let attr_name = "enzyme_type";
let c_attr_name = CString::new(attr_name).unwrap();

let enzyme_wrapper = EnzymeWrapper::get_instance().lock().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Maybe return a MutexGuard from EnzymeWrapper::get_instance()?

fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
fn enable_autodiff_settings(cgcx: &CodegenContext<LlvmCodegenBackend>, ad: &[config::AutoDiff]) {
use std::sync::Mutex;
let enzyme: &'static Mutex<llvm::EnzymeWrapper> = llvm::EnzymeWrapper::init(cgcx);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe return a MutexGuard from EnzymeWrapper::init()?

}

fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
fn enable_autodiff_settings(cgcx: &CodegenContext<LlvmCodegenBackend>, ad: &[config::AutoDiff]) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call this from LlvmCodegenBackend::init() instead? There you have access to the full Session.

@sgasho
Copy link
Contributor Author

sgasho commented Nov 24, 2025

(oops, sorry I should have run tests before opening this pr. It takes too much time running tests on my m1 mac so let me check them tomorrow, including ci failures..... 🙇)

@bjorn3
Copy link
Member

bjorn3 commented Nov 24, 2025

Don't worry. I don't run all tests either before opening a PR either, that indeed takes way too long. I mostly run ./x.py check or ./x.py test path/to/relevant/tests + if I remember ./x.py test src/tools/tidy.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 24, 2025

Oh sorry, I was only referring to all the autodiff tests mentioned here. I'm also not running all tests.
Also just building it on my laptop, but it needs a new LLVM version and that always takes a while.

@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 24, 2025

@sgasho It seems that all autodiff tests invoking enzyme fail, e.g:

thread 'rustc' (2936300) panicked at compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:211:35:
EnzymeWrapper not initialized
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::option::expect_failed
   3: rustc_codegen_llvm::typetree::add_tt
   4: rustc_codegen_llvm::intrinsic::codegen_autodiff
failures:
    [codegen] tests/codegen-llvm/autodiff/trait.rs
    [codegen] tests/codegen-llvm/autodiff/identical_fnc.rs
    [codegen] tests/codegen-llvm/autodiff/typetree.rs
    [codegen] tests/codegen-llvm/autodiff/generic.rs
    [codegen] tests/codegen-llvm/autodiff/abi_handling.rs#release
    [codegen] tests/codegen-llvm/autodiff/batched.rs
    [codegen] tests/codegen-llvm/autodiff/autodiffv2.rs

I still remember I had the same issue in my original PR, so that might be the reason.

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-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants