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 Varied analysis to the reverse mode #1084

Merged
merged 16 commits into from
Oct 15, 2024
Merged

Conversation

ovdiiuv
Copy link
Collaborator

@ovdiiuv ovdiiuv commented Sep 6, 2024

This PR adds Varied analysis support in the reverse mode, fixes wrong jacobian results and updates tests.

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.34%. Comparing base (b414202) to head (970cc3d).
Report is 22 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1084      +/-   ##
==========================================
+ Coverage   94.25%   94.34%   +0.08%     
==========================================
  Files          55       50       -5     
  Lines        8445     8326     -119     
==========================================
- Hits         7960     7855     -105     
+ Misses        485      471      -14     
Files with missing lines Coverage Δ
include/clad/Differentiator/CladConfig.h 100.00% <ø> (ø)
include/clad/Differentiator/DiffPlanner.h 68.18% <100.00%> (-1.39%) ⬇️
lib/Differentiator/ActivityAnalyzer.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ActivityAnalyzer.h 100.00% <100.00%> (ø)
lib/Differentiator/DiffPlanner.cpp 98.56% <100.00%> (-0.22%) ⬇️
lib/Differentiator/ReverseModeVisitor.cpp 95.44% <100.00%> (-2.41%) ⬇️
tools/ClangPlugin.cpp 96.14% <100.00%> (+0.55%) ⬆️
tools/ClangPlugin.h 93.05% <100.00%> (+1.08%) ⬆️

... and 37 files with indirect coverage changes

Files with missing lines Coverage Δ
include/clad/Differentiator/CladConfig.h 100.00% <ø> (ø)
include/clad/Differentiator/DiffPlanner.h 68.18% <100.00%> (-1.39%) ⬇️
lib/Differentiator/ActivityAnalyzer.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ActivityAnalyzer.h 100.00% <100.00%> (ø)
lib/Differentiator/DiffPlanner.cpp 98.56% <100.00%> (-0.22%) ⬇️
lib/Differentiator/ReverseModeVisitor.cpp 95.44% <100.00%> (-2.41%) ⬇️
tools/ClangPlugin.cpp 96.14% <100.00%> (+0.55%) ⬆️
tools/ClangPlugin.h 93.05% <100.00%> (+1.08%) ⬆️

... and 37 files with indirect coverage 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 29. Check the log or trigger a new build to see more.

include/clad/Differentiator/DiffPlanner.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
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 16. Check the log or trigger a new build to see more.

lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
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 18. Check the log or trigger a new build to see more.

lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
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/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
@ovdiiuv ovdiiuv force-pushed the activity branch 2 times, most recently from 65075a3 to df82648 Compare September 6, 2024 20:38
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/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
@ovdiiuv ovdiiuv force-pushed the activity branch 2 times, most recently from f5236aa to c2ca79b Compare September 6, 2024 22:19
@ovdiiuv ovdiiuv requested a review from vgvassilev September 7, 2024 10:27
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.

Here is a partial review. Please address the clang-tidy complaints as most of them are good. I'd also rely on @PetroZarytskyi here for a review.

lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@PetroZarytskyi PetroZarytskyi left a comment

Choose a reason for hiding this comment

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

Thank you for your work. I didn't mention pullbacks and call exprs because we already made huge progress there yesterday. Overall, the PR looks awesome. Its simplicity makes me feel that TBR was overcomplicated. I think we made the right decision to start with a simplified implementation.

lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Show resolved Hide resolved
test/Analyses/ActivityReverse.cpp Outdated Show resolved Hide resolved
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/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
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/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
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.

Please check the resolved conversations as some are not really resolved by adding the requested change.

lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
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/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
test/Jacobian/FunctionCalls.C Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/CMakeLists.txt Outdated Show resolved Hide resolved
lib/Differentiator/DiffPlanner.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
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 26. Check the log or trigger a new build to see more.

include/clad/Differentiator/DiffPlanner.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
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/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved

bool VariedAnalyzer::VisitDeclStmt(DeclStmt* DS) {
for (Decl* D : DS->decls()) {
if (!isa<VarDecl>(D))
Copy link
Owner

Choose a reason for hiding this comment

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

A test here could be class C{} c; that produces a DeclStmt whose Stmt is not a VarDecl.

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/DiffPlanner.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
test/Jacobian/FunctionCalls.C Outdated Show resolved Hide resolved
test/Gradient/FunctionCalls.C Outdated Show resolved Hide resolved
@@ -441,14 +441,14 @@ double do_nothing(double* u, double* v, double* w) {
return u[0];
}

// CHECK: void do_nothing_pullback(double *u, double *v, double *w, double _d_y, double *_d_u, double *_d_v, double *_d_w);
Copy link
Owner

Choose a reason for hiding this comment

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

Why this change was needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We used to remove non varied parameters from the adjoint, but it'd crash cms example, so I removed it for now.

Copy link
Owner

Choose a reason for hiding this comment

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

I am not sure I follow, Does not that change the pullback signatures randomly? @PetroZarytskyi.

lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.cpp Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Outdated Show resolved Hide resolved
bool m_Varied = false;
bool m_Marking = false;

std::set<const clang::VarDecl*>& m_VariedDecls;
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
std::set<const clang::VarDecl*>& m_VariedDecls;
VarsData& m_VariedDecls;

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/ActivityAnalyzer.h Show resolved Hide resolved
lib/Differentiator/ActivityAnalyzer.h Show resolved Hide resolved
@PetroZarytskyi
Copy link
Collaborator

LGTM

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.

We are almost there. Please add tests on the missing branches.

@@ -441,14 +441,14 @@ double do_nothing(double* u, double* v, double* w) {
return u[0];
}

// CHECK: void do_nothing_pullback(double *u, double *v, double *w, double _d_y, double *_d_u, double *_d_v, double *_d_w);
Copy link
Owner

Choose a reason for hiding this comment

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

I am not sure I follow, Does not that change the pullback signatures randomly? @PetroZarytskyi.


bool VariedAnalyzer::VisitDeclStmt(DeclStmt* DS) {
for (Decl* D : DS->decls()) {
if (Expr* init = cast<VarDecl>(D)->getInit()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Here we will crash if D is not a VarDecl.

@ovdiiuv ovdiiuv force-pushed the activity branch 2 times, most recently from 47ec589 to 03255f3 Compare October 14, 2024 20:03
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

enable_va_in_req =
clad::HasOption(bitmasked_opts_value, clad::opts::enable_va);
disable_va_in_req =
clad::HasOption(bitmasked_opts_value, clad::opts::disable_va);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no member named 'disable_va' in 'clad::opts'; did you mean 'disable_aa'? [clang-diagnostic-error]

Suggested change
clad::HasOption(bitmasked_opts_value, clad::opts::disable_va);
clad::HasOption(bitmasked_opts_value, clad::opts::disable_aa);
Additional context

include/clad/Differentiator/CladConfig.h:32: 'disable_aa' declared here

  disable_aa = 1 << (ORDER_BITS + 6),
  ^

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 2d08ce1 into vgvassilev:master Oct 15, 2024
90 checks passed
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