Skip to content

Commit

Permalink
Update and enable tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Nov 17, 2023
1 parent 81a3faf commit ec8682f
Show file tree
Hide file tree
Showing 48 changed files with 2,171 additions and 2,654 deletions.
4 changes: 1 addition & 3 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,9 +2214,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
if (!RDelayed.isConstant) {
Expr* dr = nullptr;
if (dfdx()) {
StmtDiff LResult = GlobalStoreAndRef(LStored);
LStored = LResult.getExpr();
dr = BuildOp(BO_Mul, LResult.getExpr_dx(), dfdx());
dr = BuildOp(BO_Mul, Ldiff.getRevSweepAsExpr(), dfdx());
dr = StoreAndRef(dr, direction::reverse);
}
Rdiff = Visit(R, dr);
Expand Down
182 changes: 94 additions & 88 deletions test/Arrays/ArrayInputsReverseMode.C

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions test/Arrays/Arrays.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %cladclang %s -I%S/../../include -oArrays.out 2>&1 | FileCheck %s
// RUN: ./Arrays.out | FileCheck -check-prefix=CHECK-EXEC %s
// RUN: %cladclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oArrays.out
// RUN: ./Arrays.out | FileCheck -check-prefix=CHECK-EXEC %s

//CHECK-NOT: {{.*error|warning|note:.*}}

Expand Down Expand Up @@ -95,31 +97,25 @@ double const_dot_product(double x, double y, double z) {
//CHECK-NEXT: double _t0;
//CHECK-NEXT: double _t1;
//CHECK-NEXT: double _t2;
//CHECK-NEXT: double _t3;
//CHECK-NEXT: double _t4;
//CHECK-NEXT: double _t5;
//CHECK-NEXT: double vars[3] = {x, y, z};
//CHECK-NEXT: double consts[3] = {1, 2, 3};
//CHECK-NEXT: _t1 = vars[0];
//CHECK-NEXT: _t0 = consts[0];
//CHECK-NEXT: _t3 = vars[1];
//CHECK-NEXT: _t2 = consts[1];
//CHECK-NEXT: _t5 = vars[2];
//CHECK-NEXT: _t4 = consts[2];
//CHECK-NEXT: _t1 = consts[1];
//CHECK-NEXT: _t2 = consts[2];
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: {
//CHECK-NEXT: double _r0 = 1 * _t0;
//CHECK-NEXT: _d_vars[0] += _r0;
//CHECK-NEXT: double _r1 = _t1 * 1;
//CHECK-NEXT: double _r1 = vars[0] * 1;
//CHECK-NEXT: _d_consts[0] += _r1;
//CHECK-NEXT: double _r2 = 1 * _t2;
//CHECK-NEXT: double _r2 = 1 * _t1;
//CHECK-NEXT: _d_vars[1] += _r2;
//CHECK-NEXT: double _r3 = _t3 * 1;
//CHECK-NEXT: double _r3 = vars[1] * 1;
//CHECK-NEXT: _d_consts[1] += _r3;
//CHECK-NEXT: double _r4 = 1 * _t4;
//CHECK-NEXT: double _r4 = 1 * _t2;
//CHECK-NEXT: _d_vars[2] += _r4;
//CHECK-NEXT: double _r5 = _t5 * 1;
//CHECK-NEXT: double _r5 = vars[2] * 1;
//CHECK-NEXT: _d_consts[2] += _r5;
//CHECK-NEXT: }
//CHECK-NEXT: {
Expand Down
38 changes: 25 additions & 13 deletions test/ErrorEstimation/Assignments.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@ float func(float x, float y) {
}

//CHECK: void func_grad(float x, float y, clad::array_ref<float> _d_x, clad::array_ref<float> _d_y, double &_final_error) {
//CHECK-NEXT: float _t0;
//CHECK-NEXT: double _delta_x = 0;
//CHECK-NEXT: float _EERepl_x0 = x;
//CHECK-NEXT: float _EERepl_x1;
//CHECK-NEXT: float _t1;
//CHECK-NEXT: _t0 = x;
//CHECK-NEXT: x = x + y;
//CHECK-NEXT: _EERepl_x1 = x;
//CHECK-NEXT: _t1 = y;
//CHECK-NEXT: y = x;
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_y += 1;
//CHECK-NEXT: {
//CHECK-NEXT: y = _t1;
//CHECK-NEXT: float _r_d1 = * _d_y;
//CHECK-NEXT: * _d_x += _r_d1;
//CHECK-NEXT: * _d_y -= _r_d1;
//CHECK-NEXT: * _d_y;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: x = _t0;
//CHECK-NEXT: float _r_d0 = * _d_x;
//CHECK-NEXT: * _d_x += _r_d0;
//CHECK-NEXT: * _d_y += _r_d0;
Expand All @@ -48,31 +54,30 @@ float func2(float x, int y) {
}

//CHECK: void func2_grad(float x, int y, clad::array_ref<float> _d_x, clad::array_ref<int> _d_y, double &_final_error) {
//CHECK-NEXT: float _t0;
//CHECK-NEXT: double _delta_x = 0;
//CHECK-NEXT: float _EERepl_x0 = x;
//CHECK-NEXT: float _t0;
//CHECK-NEXT: int _t1;
//CHECK-NEXT: float _t1;
//CHECK-NEXT: float _t2;
//CHECK-NEXT: float _t3;
//CHECK-NEXT: float _EERepl_x1;
//CHECK-NEXT: _t1 = y;
//CHECK-NEXT: _t0 = x;
//CHECK-NEXT: _t3 = x;
//CHECK-NEXT: _t1 = x;
//CHECK-NEXT: _t2 = x;
//CHECK-NEXT: x = _t1 * _t0 + _t3 * _t2;
//CHECK-NEXT: x = y * _t1 + x * _t2;
//CHECK-NEXT: _EERepl_x1 = x;
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_x += 1;
//CHECK-NEXT: {
//CHECK-NEXT: x = _t0;
//CHECK-NEXT: float _r_d0 = * _d_x;
//CHECK-NEXT: float _r0 = _r_d0 * _t0;
//CHECK-NEXT: float _r0 = _r_d0 * _t1;
//CHECK-NEXT: * _d_y += _r0;
//CHECK-NEXT: float _r1 = _t1 * _r_d0;
//CHECK-NEXT: float _r1 = y * _r_d0;
//CHECK-NEXT: * _d_x += _r1;
//CHECK-NEXT: float _r2 = _r_d0 * _t2;
//CHECK-NEXT: * _d_x += _r2;
//CHECK-NEXT: float _r3 = _t3 * _r_d0;
//CHECK-NEXT: float _r3 = x * _r_d0;
//CHECK-NEXT: * _d_x += _r3;
//CHECK-NEXT: _delta_x += std::abs(_r_d0 * _EERepl_x1 * {{.+}});
//CHECK-NEXT: * _d_x -= _r_d0;
Expand All @@ -88,11 +93,14 @@ float func3(int x, int y) {
}

//CHECK: void func3_grad(int x, int y, clad::array_ref<int> _d_x, clad::array_ref<int> _d_y, double &_final_error) {
//CHECK-NEXT: int _t0;
//CHECK-NEXT: _t0 = x;
//CHECK-NEXT: x = y;
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_y += 1;
//CHECK-NEXT: {
//CHECK-NEXT: x = _t0;
//CHECK-NEXT: int _r_d0 = * _d_x;
//CHECK-NEXT: * _d_y += _r_d0;
//CHECK-NEXT: * _d_x -= _r_d0;
Expand All @@ -110,17 +118,20 @@ float func4(float x, float y) {
//CHECK-NEXT: double _d_z = 0;
//CHECK-NEXT: double _delta_z = 0;
//CHECK-NEXT: double _EERepl_z0;
//CHECK-NEXT: float _t0;
//CHECK-NEXT: double _delta_x = 0;
//CHECK-NEXT: float _EERepl_x0 = x;
//CHECK-NEXT: float _EERepl_x1;
//CHECK-NEXT: double z = y;
//CHECK-NEXT: _EERepl_z0 = z;
//CHECK-NEXT: _t0 = x;
//CHECK-NEXT: x = z + y;
//CHECK-NEXT: _EERepl_x1 = x;
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_x += 1;
//CHECK-NEXT: {
//CHECK-NEXT: x = _t0;
//CHECK-NEXT: float _r_d0 = * _d_x;
//CHECK-NEXT: _d_z += _r_d0;
//CHECK-NEXT: * _d_y += _r_d0;
Expand All @@ -143,16 +154,19 @@ float func5(float x, float y) {

//CHECK: void func5_grad(float x, float y, clad::array_ref<float> _d_x, clad::array_ref<float> _d_y, double &_final_error) {
//CHECK-NEXT: int _d_z = 0;
//CHECK-NEXT: float _t0;
//CHECK-NEXT: double _delta_x = 0;
//CHECK-NEXT: float _EERepl_x0 = x;
//CHECK-NEXT: float _EERepl_x1;
//CHECK-NEXT: int z = 56;
//CHECK-NEXT: _t0 = x;
//CHECK-NEXT: x = z + y;
//CHECK-NEXT: _EERepl_x1 = x;
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_x += 1;
//CHECK-NEXT: {
//CHECK-NEXT: x = _t0;
//CHECK-NEXT: float _r_d0 = * _d_x;
//CHECK-NEXT: _d_z += _r_d0;
//CHECK-NEXT: * _d_y += _r_d0;
Expand Down Expand Up @@ -181,17 +195,15 @@ float func7(float x, float y) { return (x * y); }

//CHECK: void func7_grad(float x, float y, clad::array_ref<float> _d_x, clad::array_ref<float> _d_y, double &_final_error) {
//CHECK-NEXT: float _t0;
//CHECK-NEXT: float _t1;
//CHECK-NEXT: double _ret_value0 = 0;
//CHECK-NEXT: _t1 = x;
//CHECK-NEXT: _t0 = y;
//CHECK-NEXT: _ret_value0 = (_t1 * _t0);
//CHECK-NEXT: _ret_value0 = (x * _t0);
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: {
//CHECK-NEXT: float _r0 = 1 * _t0;
//CHECK-NEXT: * _d_x += _r0;
//CHECK-NEXT: float _r1 = _t1 * 1;
//CHECK-NEXT: float _r1 = x * 1;
//CHECK-NEXT: * _d_y += _r1;
//CHECK-NEXT: }
//CHECK-NEXT: double _delta_x = 0;
Expand Down
Loading

0 comments on commit ec8682f

Please sign in to comment.