EnzymeAD / EnzymeAD/Enzyme

How to pass pointer to class member function to enzyme?

Open
#635 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
LLVM
Stars
1.7k
Forks
188
Avg merge
2d 4h
Merged PRs (30d)
22

Description

Consider following pointer to class member function
```C++
class MyFunctions{
...
void add_mul_const(double * a, double * b, double * out);
};

void __enzyme_autodiff(
void (MyFunctions::* )(double * , double * , double *),
int , double *, double *,
int, double *, double *,
int, double *, double *);

int main(){
...
void (MyFunctions::* f)(double * , double * , double *) = &MyFunctions::add_mul_const;
// FWD
(mf.*f)(a,b,out);

//Derivative
//__enzyme_autodiff(mf.*f, enzyme_dup, a, da, enzyme_dup, b, db, enzyme_dup, out, dout); ?
// __enzyme_autodiff(f, enzyme_dup, a, da, enzyme_dup, b, db, enzyme_dup, out, dout); ?

}
```

What will be correct format to pass pointer to class member function to Enzyme? Both of my attempts yielded errors
```
warning: Cannot cast __enzyme_autodiff primal argument 1, found i64 0, type i64 - to arg 0 %class.MyFunctions* [-Wpass-failed=enzyme]
int main(){
^
error: :0:0: EnzymeFailure when replacing __enzyme_autodiff calls in main
1 warning and 1 error generated.
```
and

```
error: reference to non-static member function must be called
__enzyme_autodiff(mf.*f, enzyme_const, a, enzyme_dup, b, db, enzyme_dup, out, dout);

```

Also is there anyway I can calculate derivative functions of these memeber functions without having to instantiate the class first?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.