Skip to content
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

Unexpected Crash using Forward #174

Open
g-bauer opened this issue Aug 21, 2024 · 4 comments
Open

Unexpected Crash using Forward #174

g-bauer opened this issue Aug 21, 2024 · 4 comments

Comments

@g-bauer
Copy link

g-bauer commented Aug 21, 2024

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.
@ZuseZ4
Copy link
Member

ZuseZ4 commented Aug 21, 2024

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
Copy link
Author

g-bauer commented Aug 21, 2024

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
Copy link
Author

g-bauer commented Aug 29, 2024

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
Copy link
Member

ZuseZ4 commented Aug 29, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants