Open marcpabst opened 4 months ago
This one is a known bug (see cfg(broken)
): https://github.com/EnzymeAD/rustbook/blob/main/samples/tests/reverse/mod.rs#L139-L156
But you make a very good point that we shouldn't have it as an example in the book until it is fixed. @ZuseZ4 Do you know how hard this one is to fix?
Iirc pretty hard and only a very limited benefit. We would literally have to hardcode this case (two f32 getting passed as one f64 or i64, I don't remember which). So any case passing e.g. f32, i32, f32 would still not be handled. And in the same time that it takes to fix it (if I even manage to, there might be Enzyme core bugs that need to be updated too for it) I could help with getting more valuable features like MacOS support in, or work on the upstreaming. Here are more cases that fail and for each we would need an own fix, since it's a special case in rustc where rustc applies some optimization, changing the type: https://github.com/EnzymeAD/rust/issues/105 So I think it's better to just remove the Reverse mode docs and add some examples that work.
So just that I understand correctly: This is an issue with a specific combination of inputs due to how rustc
optimises certain things?
Is there a calling conv flag inside rust somewhere that can be used to enforce args not getting coalesed? Alternatively you could forcibly pass all args by reference and then shim
Yep, but it's one of the cases where a hack will take time and has it's own downsides, so I currently still lean towards a more proper fix, where I check on a more granular level what rustc does and only disable those that are too magic for enzyme to reasonably handle. Also I have it as a probably easy onboarding task in mind, where everyone can try to add rust handling for one more special case. Since rustc only has a limited number of these optimizations and doesn't change those much, it wouldn't become a never ending story.
This example, taken directly from the docs, either always returns 0 for the derivative (
debug
) or does not even compile (release
):Error in debug mode:
Stack trace in release mode: