-
Notifications
You must be signed in to change notification settings - Fork 148
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
Generate code for Enzyme autodiff for functions with Pointer/array arguments #466
Conversation
8111f03
to
96dbc31
Compare
@vgvassilev @parth-07 "cannot initialize a parameter of type 'double (double *)' with an lvalue of type 'double (double *)'" during compilation of the below code: #include "clad/Differentiator/Differentiator.h"
double f(double *arr) { return arr[0] * arr[1]; }
int main() {
auto f_grad=clad::gradient<clad::opts::use_enzyme>(f);
} Any idea how to resolve this? |
Are you able to print generated derived function? If yes, can you please paste that in a comment here? |
@parth-07 No, I am not able to print the generated function. The same error is thrown when I attempt to print it. |
Have you tried printing the derived function using the flag |
The error suggests that you are using an incorrect value category (https://en.cppreference.com/w/cpp/language/value_category) for the function argument of the call to |
Yes I tried that, the generated function does not contain the __enzyme_autodiff function call |
Okay let me try this out |
9062756
to
cecd694
Compare
This code runs on my machine, but here the tests throw the error |
d8d19ea
to
4b17356
Compare
Now I am getting the below error in the CI tests:
I am not getting this error on my machine. How do I resolve this @vgvassilev @parth-07? |
4b17356
to
adcb7ac
Compare
It seems to be a permission issue. Can you try to install it in a non-root directory? And also, check if we are missing the right permissions somewhere. |
adcb7ac
to
ab8b465
Compare
Currently I am installing Enzyme in the "CMAKE_INSTALL_PREFIX". I think in the CI machines this is in some root directory. Where do I install it, is the build_dir a good place? |
You can just specify a non-root directory for the |
Any non-root directory should work for the debugging purpose right now. We would like things to work as expected when the user is installing in root locations as well. Thus the main goal is to find the underlying issue that's causing the CMake configuration to fail. |
ab8b465
to
56c835a
Compare
Its mentioned in the Enzyme website that Enzyme has been tested against LLVM 7,8,9,10,11,12. I personally tested it against LLVM 13 and 14 and it works. Maybe the lower versions of LLVM/clang are causing a problem? As I have seen, most failures in the CI are because the Enzyme build has failed. |
Can you test enzyme integration with Clad when lower versions of LLVM are used in your local system? If you are getting the same/similar errors in the local system as well, then it will be easier to debug. |
d8b51ce
to
59a8160
Compare
3ee6a23
to
96187a6
Compare
3b85706
to
3b0e400
Compare
3b0e400
to
95df090
Compare
99db221
to
d93e774
Compare
d93e774
to
d8bc2f3
Compare
3823f51
to
97c6593
Compare
a174e7c
to
f48f95e
Compare
…guments For functions of type double myfunction(double* arr){...}; OR double myfunction(double arr[3]){...}; we generate derivative code of type: void d_myfunction(double* arr, clad::array_ref<double> _d_arr){ double* d_arr = _d_arr.ptr(); __enzyme_autodiff_myfunction(myfunction, arr, d_arr); } Further on enzyme will handle the function differentiation This Commit also Downloads and Installs Enzyme in the Clad Directory, if the flag "-DENABLE_ENZYME_BACKEND=On" is passed to cmake during project configuration. This commit also contains tests for the above feature in test/Gradient/Enzyme.C This commit also adds the enzyme pass to the llvm optimisation pipeline so that it can run at the right moment.
f48f95e
to
3598e48
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work @Nirhar!
The codecov coverage reports are mostly due to code using the new pass manager. Unfortunately enzyme has not yet moved to the new pass manager. It's registration happens via the old way. However, I'd like to keep the new way around and they move we will do little work to reuse the already put in place infrastructure.
For functions of type
double myfunction(double* arr){...};
OR
double myfunction(double arr[3]){...};
we generate derivative code of type:
Further on enzyme will handle the function differentiation
This Commit also Downloads and Installs Enzyme in the Clad Directory, if
the flag "-DENZYME=On" is passed to cmake during project configuration.
This Commit also contains tests for the above feature in test/Gradient/Enzyme.C