Skip to content

Commit

Permalink
Reverse the order of the reverse sweep declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Jan 20, 2024
1 parent fb30527 commit 9bdc01c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
}

void ReverseModeVisitor::EmitReverseSweepDeclarations(bool endCurBlock) {
for (auto& pair : m_Locals.back()) {
clang::VarDecl* VDForw = pair.first;
clang::VarDecl* VDRev = pair.second;
for (auto iter = m_Locals.back().rbegin(), e = m_Locals.back().rend();
iter != e; ++iter) {
clang::VarDecl* VDForw = iter->first;
clang::VarDecl* VDRev = iter->second;

clang::QualType type = VDRev->getType();
clang::Expr* ref = BuildDeclRef(VDForw);
Expand Down
4 changes: 2 additions & 2 deletions test/CUDA/GradientCuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ auto gauss_g = clad::gradient(gauss, "p");
//CHECK-NEXT: double t = 0;
//CHECK-NEXT: _t0 = 0;
//CHECK-NEXT: {
//CHECK-NEXT: int i;
//CHECK-NEXT: for (i = 0; i < dim; i++) {
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: for (; i < dim; i++) {
//CHECK-NEXT: _t0++;
//CHECK-NEXT: clad::push(_t1, t);
//CHECK-NEXT: t += (x[i] - p[i]) * (x[i] - p[i]);
Expand Down
8 changes: 4 additions & 4 deletions test/Gradient/Loops.C
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ double f6 (double i, double j) {
// CHECK-NEXT: b += j;
// CHECK-NEXT: clad::push(_t2, a);
// CHECK-NEXT: a += b + c + i;
// CHECK-NEXT: clad::push(_t3, b);
// CHECK-NEXT: clad::push(_t4, c);
// CHECK-NEXT: clad::push(_t3, c);
// CHECK-NEXT: clad::push(_t4, b);
// CHECK-NEXT: }
// CHECK-NEXT: _t5 = counter;
// CHECK-NEXT: }
Expand All @@ -579,8 +579,8 @@ double f6 (double i, double j) {
// CHECK-NEXT: int counter = _t5;
// CHECK-NEXT: for (; _t0; _t0--) {
// CHECK-NEXT: --counter;
// CHECK-NEXT: double c = clad::pop(_t4);
// CHECK-NEXT: double b = clad::pop(_t3);
// CHECK-NEXT: double b = clad::pop(_t4);
// CHECK-NEXT: double c = clad::pop(_t3);
// CHECK-NEXT: {
// CHECK-NEXT: a = clad::pop(_t2);
// CHECK-NEXT: double _r_d1 = _d_a;
Expand Down

0 comments on commit 9bdc01c

Please sign in to comment.