Enzyme icon indicating copy to clipboard operation
Enzyme copied to clipboard

Enzyme: Cannot cast __enzyme_autodiff primal argument 16

Open efeklisov opened this issue 11 months ago • 7 comments

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

https://fwd.gymni.ch/vATLS0

efeklisov avatar Feb 29 '24 16:02 efeklisov

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: @.***>

wsmoses avatar Feb 29 '24 16:02 wsmoses

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

https://fwd.gymni.ch/TFoPoL

efeklisov avatar Feb 29 '24 17:02 efeklisov

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 avatar Feb 29 '24 20:02 wsmoses

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

wsmoses avatar Feb 29 '24 20:02 wsmoses

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);

}

ipcamit avatar May 28 '24 20:05 ipcamit

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

try:

  • __enzyme_autodiff rather than __enzyme_autodiffs
  • enzyme_const instead of __enzyme_const
  • enzyme_dup instead of __enzyme_dup

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

samuelpmish avatar May 29 '24 20:05 samuelpmish

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.

ipcamit avatar May 29 '24 20:05 ipcamit