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

Add support for call expressions in vector forward mode AD #638

Merged
merged 1 commit into from
Dec 3, 2023

Conversation

vaithak
Copy link
Collaborator

@vaithak vaithak commented Oct 8, 2023

Two main changes in this PR:

  • Renamed ForwardModeVisitor to a more apt name PushForwardModeVisitor.
  • Made changes to make the VisitCallExpr of BaseForwardModeVistor and the PushForwardModeVisitor class generic enough to add support for vector mode with very little code repetition,
    • This led to the following inheritance structure,
                                      BaseForwardModeVisitor
                                    /                        \
                                   /                          \
            VectorForwardModeVisitor                          PushForwardModeVisitor
                        |               
                        |                         
          VectorPushForwardModeVisitor
      

Also added appropriate tests for the new functionality.

Edited: Modified the inheritance diagram as per updated changes.

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

There were too many comments to post at once. Showing the first 10 out of 19. Check the log or trigger a new build to see more.

include/clad/Differentiator/VectorPushForwardModeVisitor.h Outdated Show resolved Hide resolved
include/clad/Differentiator/VectorPushForwardModeVisitor.h Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
@vaithak vaithak force-pushed the vec-mode-call-expr branch from d96c3d6 to e04b101 Compare October 10, 2023 06:18
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

lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/PushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/VectorPushForwardModeVisitor.cpp Outdated Show resolved Hide resolved
@vaithak vaithak force-pushed the vec-mode-call-expr branch from e04b101 to 3c154c9 Compare October 10, 2023 09:23
@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Merging #638 (c0db619) into master (0ab0c6e) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #638      +/-   ##
==========================================
+ Coverage   94.30%   94.36%   +0.06%     
==========================================
  Files          45       48       +3     
  Lines        7003     7063      +60     
==========================================
+ Hits         6604     6665      +61     
+ Misses        399      398       -1     
Files Coverage Δ
...clude/clad/Differentiator/BaseForwardModeVisitor.h 100.00% <ø> (ø)
include/clad/Differentiator/DerivativeBuilder.h 100.00% <ø> (ø)
...clude/clad/Differentiator/PushForwardModeVisitor.h 100.00% <100.00%> (ø)
...clad/Differentiator/VectorPushForwardModeVisitor.h 100.00% <100.00%> (ø)
lib/Differentiator/BaseForwardModeVisitor.cpp 98.84% <100.00%> (+0.11%) ⬆️
lib/Differentiator/DerivativeBuilder.cpp 100.00% <100.00%> (ø)
lib/Differentiator/PushForwardModeVisitor.cpp 100.00% <100.00%> (ø)
lib/Differentiator/VectorForwardModeVisitor.cpp 100.00% <100.00%> (ø)
...ib/Differentiator/VectorPushForwardModeVisitor.cpp 100.00% <100.00%> (ø)
Files Coverage Δ
...clude/clad/Differentiator/BaseForwardModeVisitor.h 100.00% <ø> (ø)
include/clad/Differentiator/DerivativeBuilder.h 100.00% <ø> (ø)
...clude/clad/Differentiator/PushForwardModeVisitor.h 100.00% <100.00%> (ø)
...clad/Differentiator/VectorPushForwardModeVisitor.h 100.00% <100.00%> (ø)
lib/Differentiator/BaseForwardModeVisitor.cpp 98.84% <100.00%> (+0.11%) ⬆️
lib/Differentiator/DerivativeBuilder.cpp 100.00% <100.00%> (ø)
lib/Differentiator/PushForwardModeVisitor.cpp 100.00% <100.00%> (ø)
lib/Differentiator/VectorForwardModeVisitor.cpp 100.00% <100.00%> (ø)
...ib/Differentiator/VectorPushForwardModeVisitor.cpp 100.00% <100.00%> (ø)

@vgvassilev vgvassilev requested a review from parth-07 October 25, 2023 10:20
@parth-07
Copy link
Collaborator

This change looks good overall. I would like to avoid diamond hierarchy if possible, but I am not sure if it would be. So many things can easily go wrong when diamon hierarchy is used.

@vgvassilev vgvassilev added this to the v1.3 milestone Nov 4, 2023
@vaithak vaithak force-pushed the vec-mode-call-expr branch 2 times, most recently from 4beb275 to 3d0d5e0 Compare November 4, 2023 20:52
@vaithak
Copy link
Collaborator Author

vaithak commented Nov 4, 2023

Fixed the inheritance structure to remove the diamond problem, now, the structure is pretty simple:

                                     BaseForwardModeVisitor
                                   /                        \
                                  /                          \
           VectorForwardModeVisitor                          PushForwardModeVisitor
                       |               
                       |                         
         VectorPushForwardModeVisitor

The common code in both PushForwardMode modes is pushed into BaseForwardMode class, with the differences shifted inside separate overridable methods.

Closed by mistake, reopened.

@vaithak vaithak closed this Nov 4, 2023
@vaithak vaithak reopened this Nov 4, 2023
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

include/clad/Differentiator/PushForwardModeVisitor.h Outdated Show resolved Hide resolved
include/clad/Differentiator/PushForwardModeVisitor.h Outdated Show resolved Hide resolved
include/clad/Differentiator/VectorForwardModeVisitor.h Outdated Show resolved Hide resolved
#include "VectorForwardModeVisitor.h"

namespace clad {
class VectorPushForwardModeVisitor : public VectorForwardModeVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'VectorPushForwardModeVisitor' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class VectorPushForwardModeVisitor : public VectorForwardModeVisitor {
      ^

returnType, paramTypes, originalFnType->getExtProtoInfo());
llvm::SaveAndRestore<DeclContext*> saveContext(m_Sema.CurContext);
llvm::SaveAndRestore<Scope*> saveScope(m_CurScope);
auto* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
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 const_cast [cppcoreguidelines-pro-type-const-cast]

  auto* DC = const_cast<DeclContext*>(m_Function->getDeclContext());
             ^

@vaithak vaithak force-pushed the vec-mode-call-expr branch from 3d0d5e0 to 8ef4f4e Compare November 4, 2023 21:49
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

namespace clad {
/// A visitor for processing the function code in forward mode.
/// Used to compute derivatives by clad::differentiate.
class PushForwardModeVisitor : public BaseForwardModeVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'PushForwardModeVisitor' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class PushForwardModeVisitor : public BaseForwardModeVisitor {
      ^

@vaithak vaithak force-pushed the vec-mode-call-expr branch 2 times, most recently from 28b48c6 to 1241f64 Compare November 4, 2023 23:11
@vgvassilev
Copy link
Owner

@vaithak, can you rebase this PR on top of master?

@vaithak vaithak force-pushed the vec-mode-call-expr branch from 1241f64 to c0db619 Compare December 2, 2023 14:16
Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

LGTM!

@vgvassilev vgvassilev merged commit ec76b70 into vgvassilev:master Dec 3, 2023
75 checks passed
@vaithak vaithak deleted the vec-mode-call-expr branch March 13, 2024 13:23
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.

3 participants