-
Notifications
You must be signed in to change notification settings - Fork 122
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
Crash due to the usage of pointers in reverse mode #195
Comments
Hi, I am a beginner in open source and would like to contribute to this issue. From what I can gather, an error is being generated because of the use of pointers. Please correct me if I am wrong. |
Yes, as it says in the title, the error is indeed being generated by the use of pointers, a concept that is not fully supported by Clad. You could start by going through the source code and dumping the generated AST of the derivative function. You can also use any debugger you like to check out the control flow of the code to get a better understanding of how things are done in Clad. This may also be helpful in narrowing down where the error is. |
The address operator is supposed be a non-differentiable operator right? How exactly is it handled in the existing codebase? How much of support already exists for pointers in the codebase? Are there any existing examples that use pointers and work correctly? |
Yes! Mathematically, the address-of operator is a non-differentiable operator. However, it does impact the primal function, and thus the derived function as well. The important thing to keep in mind to correctly produce the derived function is: the control flow of derivative computation should follow the control flow of primal computation in reverse, and use the same values as were used by the corresponding primal computation. Correctly setting pointer variables and derivative of pointer variables is a way to keep the control flow consistent. Please keep in mind that derivative of pointer variable is a very misleading term, because pointer variables do not represent a mathematical object, and thus cannot have derivatives. But nonetheless, it is still a common term in AD literature. You can understand derivative of a pointer variable as a variable that helps to keep the control flow consistent and facilitate using the same values in the reverse pass computation as were used by the corresponding forward pass computation.
Currently, Reverse Mode AD does not support pointers. We have plans to add pointer support in the near future.
Forward Mode AD (
We currently do not have a definite Reverse Mode AD differentiation model that supports pointers. For seeing the differentiation of code that uses pointers using the Reverse Mode AD, you can checkout other C/C++ based AD tools. |
The code snippets shown here don't compile when I use clad(with clang) in debug mode. It throws the following error:
However when non debug mode of clad is used then the error doesn't come and it compiles, however this leads to segmentation fault during runtime as mentioned in the issue. |
Clang debug build contains various assertions for ensuring consistency of the AST. These assertions are not present in release builds. |
double f5(double a) { |
This commit adds support for pointer operation in reverse mode. The technique is maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes vgvassilev#195, vgvassilev#197
This commit adds support for pointer operation in reverse mode. The technique is to maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes vgvassilev#195, Fixes vgvassilev#197
This commit adds support for pointer operation in reverse mode. The technique is to maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes vgvassilev#195, Fixes vgvassilev#197
This commit adds support for pointer operation in reverse mode. The technique is to maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes vgvassilev#195, Fixes vgvassilev#197
This commit adds support for pointer operation in reverse mode. The technique is to maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes vgvassilev#195, Fixes vgvassilev#197
This commit adds support for pointer operation in reverse mode. The technique is to maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes vgvassilev#195, Fixes vgvassilev#197
This commit adds support for pointer operation in reverse mode. The technique is to maintain a corresponding derivative pointer variable, which gets updated (and stored/restored) in the exact same way as the primal pointer variable in both forward and reverse passes. Added a workaround (with a FIXME comment) in the UsefulToStoreGlobal method to essentially bypass TBR analysis results for pointer expr. Fixes #195, Fixes #197
Minimum reproducible example:
Another example is simply
calling
clad::gradient
on the above results in the following error,stack trace
The text was updated successfully, but these errors were encountered: