clad icon indicating copy to clipboard operation
clad copied to clipboard

Add declarations for variables reused in the reverse pass

Open PetroZarytskyi opened this issue 6 months ago • 3 comments

The problem this PR attempts to fix is described in #659 (which in turn caused #681). Also, this PR introduces placeholders to DelayedGlobalStoreAndRef to rewrite expressions after they are added to the current block if there is no point in storing them. This is done to avoid cloning while handling multiplication differentiation.

PetroZarytskyi avatar Dec 22 '23 15:12 PetroZarytskyi

@PetroZarytskyi Can you please describe the solution in the commit message / pull request description?

parth-07 avatar Dec 30 '23 13:12 parth-07

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (d8ef790) 94.54% compared to head (1661a22) 94.64%. Report is 2 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #688      +/-   ##
==========================================
+ Coverage   94.54%   94.64%   +0.09%     
==========================================
  Files          49       49              
  Lines        7189     7281      +92     
==========================================
+ Hits         6797     6891      +94     
+ Misses        392      390       -2     
Files Coverage Δ
include/clad/Differentiator/ErrorEstimator.h 100.00% <ø> (ø)
...e/clad/Differentiator/MultiplexExternalRMVSource.h 100.00% <ø> (ø)
include/clad/Differentiator/VisitorBase.h 100.00% <ø> (ø)
lib/Differentiator/CladUtils.cpp 97.08% <100.00%> (ø)
lib/Differentiator/ErrorEstimator.cpp 98.51% <100.00%> (+<0.01%) :arrow_up:
lib/Differentiator/MultiplexExternalRMVSource.cpp 90.81% <100.00%> (+0.29%) :arrow_up:
lib/Differentiator/VisitorBase.cpp 98.05% <100.00%> (+<0.01%) :arrow_up:
include/clad/Differentiator/ExternalRMVSource.h 23.07% <0.00%> (-0.61%) :arrow_down:
lib/Differentiator/ReverseModeVisitor.cpp 96.35% <99.60%> (+0.26%) :arrow_up:
include/clad/Differentiator/ReverseModeVisitor.h 95.74% <83.33%> (-1.93%) :arrow_down:
... and 1 more

... and 1 file with indirect coverage changes

Files Coverage Δ
include/clad/Differentiator/ErrorEstimator.h 100.00% <ø> (ø)
...e/clad/Differentiator/MultiplexExternalRMVSource.h 100.00% <ø> (ø)
include/clad/Differentiator/VisitorBase.h 100.00% <ø> (ø)
lib/Differentiator/CladUtils.cpp 97.08% <100.00%> (ø)
lib/Differentiator/ErrorEstimator.cpp 98.51% <100.00%> (+<0.01%) :arrow_up:
lib/Differentiator/MultiplexExternalRMVSource.cpp 90.81% <100.00%> (+0.29%) :arrow_up:
lib/Differentiator/VisitorBase.cpp 98.05% <100.00%> (+<0.01%) :arrow_up:
include/clad/Differentiator/ExternalRMVSource.h 23.07% <0.00%> (-0.61%) :arrow_down:
lib/Differentiator/ReverseModeVisitor.cpp 96.35% <99.60%> (+0.26%) :arrow_up:
include/clad/Differentiator/ReverseModeVisitor.h 95.74% <83.33%> (-1.93%) :arrow_down:
... and 1 more

... and 1 file with indirect coverage changes

codecov[bot] avatar Jan 15 '24 10:01 codecov[bot]

The produced gradient of the below code has compile-time error in the local variable redeclaration part.

double fn(double u, double v) {
    double r;
    {
        double res;
        double v_copy = v;
        double &v_ref = v_copy;
        res = v_ref;
        r = res;
    }
    return r;
}

The local variable redeclaration in the reverse sweep is as follows:

double &v_ref = v_copy;
double v_copy = _t3;
double res = _t2;

v_ref should be declared after v_copy.

parth-07 avatar Jan 20 '24 13:01 parth-07

@PetroZarytskyi, is that PR superseded by #738? Can we close it?

vgvassilev avatar Feb 08 '24 11:02 vgvassilev

@PetroZarytskyi, is that PR superseded by #738? Can we close it?

I think the solution implemented in #738 is better. We should probably close this PR.

PetroZarytskyi avatar Feb 12 '24 21:02 PetroZarytskyi