Skip to content

Unexpected Crash using Forward #174

@g-bauer

Description

@g-bauer

I encountered unexpected behavior with a function and I am unsure what the issue is (compiled via cargo +enzyme run --release)

// this crashes
#[autodiff(df2f, Forward, Const, Dual, Dual)]
pub fn _f2(x: &[f64], y: f64) -> f64 {
    let xy: Vec<_> = x.iter().map(|xi| xi / y).collect();
    xy.iter().sum()
}

// this works
#[autodiff(df4f, Forward, Const, Dual, Dual)]
pub fn _f4(x: &[f64], y: f64) -> f64 {
    x.iter().fold(0.0, |acc, xi| acc + xi / y)
}

Error message:

source_id: DefId(0:13 ~ enzyme_playground[95ff]::_f2)
rustc: /code/rust/src/llvm-project/llvm/lib/IR/Instructions.cpp:686: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const llvm::Twine&): Assertion `(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"' failed.

Activity

ZuseZ4

ZuseZ4 commented on Aug 21, 2024

@ZuseZ4
Collaborator

Ok, if you have two functions with the same signature and only one crashes, I tend to blame it on Enzyme core.
Can you try my new debug docs here and let me know if they are unclear and you run into issues? If all goes well it should give you a minimal llvm-ir reproducer which we can then post in the Enzyme core repo for Billy to fix. Afterwards I'll update the enzyme submodule and it should work.

g-bauer

g-bauer commented on Aug 21, 2024

@g-bauer
Author

Proper example to reproduce the issue:

#![feature(autodiff)]
#[autodiff(df2f, Forward, Const, Dual, Dual)]
#[no_mangle]
pub fn _f2(x: &[f64], y: f64) -> f64 {
    let xy: Vec<_> = x.iter().map(|xi| xi / y).collect();
    xy.iter().sum()
}

fn main() {
    df2f(&[1.0], 1.0, 1.0);
}

Here is the link to the Enzyme Explorer after following your instructions in the debug docs.

g-bauer

g-bauer commented on Aug 29, 2024

@g-bauer
Author

Is there anything I have to consider when re-building the compiler? I pulled the latest changes and recompiled but I end up with the same error.

ZuseZ4

ZuseZ4 commented on Aug 29, 2024

@ZuseZ4
Collaborator

Uhm, not really. You can try rm -rf build/x86_64-unknown-linux-gnu/enzyme (adjusted for your arch) and then rebuild to be really sure, but it shouldn't be needed.
Can you afterwards redo the automated minimization and check if the two reduced .ll files are the same? Maybe you're unlucky and ran into a slightly similar error case that's not covered by the last patch. Billy also mentioned we might need more than one round of fixes here.

ZuseZ4

ZuseZ4 commented on Feb 6, 2025

@ZuseZ4
Collaborator

@g-bauer It's been a while, but with a minor fix in rust-lang#136419, the autodiff implementation in upstream rustc can now handle both of your functions, so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @g-bauer@ZuseZ4

        Issue actions

          Unexpected Crash using `Forward` · Issue #174 · EnzymeAD/rust