EnzymeAD / Enzyme

High-performance automatic differentiation of LLVM and MLIR.
https://enzyme.mit.edu
Other
1.27k stars 108 forks source link

Enzyme: Cannot cast __enzyme_autodiff primal argument 16 #1772

Open efeklisov opened 7 months ago

efeklisov commented 7 months ago

I'm getting a weird typecasting issue in Enzyme. What could be the source of it?

https://fwd.gymni.ch/vATLS0

wsmoses commented 7 months ago

Oh this might be clang splatting the args into two pieces. What happens if you change the function and enzyme call to pass everything by reference

On Thu, Feb 29, 2024 at 8:35 AM Egor Feklisov @.***> wrote:

I'm getting a weird typecasting issue in Enzyme. What could be the source of it?

https://fwd.gymni.ch/vATLS0

— Reply to this email directly, view it on GitHub https://github.com/EnzymeAD/Enzyme/issues/1772, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJTUXA2YMIAQEFSFAQ34EDYV5MDLAVCNFSM6AAAAABEAIOIOWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3DCNRVG44TOOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

efeklisov commented 7 months ago

I hope I understood you correctly, but I see a similar issue

https://fwd.gymni.ch/TFoPoL

wsmoses commented 7 months ago

C var-args passes things by value, so you need to & the args to make them pointers in that case: https://fwd.gymni.ch/zWsQwn

wsmoses commented 7 months ago

Hopefully that solve your issue, however keeping this open for now so we can make the nice c++ syntax happy with it [and obviate the need for the extra work]: https://fwd.gymni.ch/UDe5lg

@samuelpmishLLNL @samuelpmish

ipcamit commented 4 months ago

Sorry, I am having same issue, in a small example I was creating to ask unrelated question. Why is the minimal function below gives same error?

https://fwd.gymni.ch/NzHCYv

int __enzyme_const, __enzyme_dup;

void __enzyme_autodiffs(void (*) (double, double, double*), ...);

void math(double a, double b , double *result) {}

void grad(double a, double b, double *result, double *d_result) {

    double d_a = 0.0;
    double d_b = 0.0;
    __enzyme_autodiffs(math,
        __enzyme_dup, a, d_a,
        __enzyme_dup, b, d_b,
        __enzyme_dup, result, d_result);

}
samuelpmish commented 4 months ago

@ipcamit I think you're just using the wrong names for some of the enzyme stuff.

try:

see: https://fwd.gymni.ch/k3qaoa

ipcamit commented 4 months ago

This is embarrassing! I was using __enzyme_autodiff properly, and was trying to see if its name change will affect the compilation. But completely forgot about enzyme_dup, I was really sure that all things enzyme start like __enzyme...! Thank you for taking time to look into this.