Skip to content
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

Updated to get correct gradient when reference variable is initialized with pointer dereference #820

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kaushal-malpure
Copy link

@kaushal-malpure kaushal-malpure commented Mar 13, 2024

@parth-07
Referring to #734
According to my understanding when a reference variable is initialized with pointer dereference, the clad::gradient function creates a new adjoint variable for the given reference variable whereas it should share the same adjoint variable as the pointer. To solve this issue we can replace the reference variable with the original pointer. This might be a potential solution. I couldn't verify this because my system gives an error when I try to build the program.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment on lines +379 to +382
} else {
return CladFunction<DerivedFnType, ExtractFunctorTraits_t<F>, true>(
derivedFn /* will be replaced by gradient*/, code, f);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'else' after 'return' [llvm-else-after-return]

Suggested change
} else {
return CladFunction<DerivedFnType, ExtractFunctorTraits_t<F>, true>(
derivedFn /* will be replaced by gradient*/, code, f);
}
} return CladFunction<DerivedFnType, ExtractFunctorTraits_t<F>, true>(
derivedFn /* will be replaced by gradient*/, code, f);

@PetroZarytskyi
Copy link
Collaborator

Hi @kaushal-malpure. Thank you for your interest in Clad. I think the solution to this issue should not be in the Clad's front end (like the gradient function) but rather in the back end. Perhaps the changes should be introduced to ReverseModeVisitor.cpp (this is where the gradient code is generated). I would suggest getting familiar with how Clang AST is generated there. You can start with the main function Derive. And yes, you need to be able to build Clad. Being able to take a look at the gradient code you produce is crucial for understanding and testing your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants