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 18, 2023
1 parent 81a3faf commit 0c23136
Show file tree
Hide file tree
Showing 49 changed files with 2,200 additions and 2,691 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
110 changes: 49 additions & 61 deletions test/CUDA/GradientCuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,92 +35,80 @@ auto gauss_g = clad::gradient(gauss, "p");
//CHECK-NEXT: unsigned long _t0;
//CHECK-NEXT: int _d_i = 0;
//CHECK-NEXT: clad::tape<double> _t1 = {};
//CHECK-NEXT: clad::tape<int> _t2 = {};
//CHECK-NEXT: clad::tape<int> _t4 = {};
//CHECK-NEXT: clad::tape<double> _t6 = {};
//CHECK-NEXT: clad::tape<int> _t7 = {};
//CHECK-NEXT: clad::tape<int> _t9 = {};
//CHECK-NEXT: double _t11;
//CHECK-NEXT: double _t12;
//CHECK-NEXT: double _t13;
//CHECK-NEXT: double _t14;
//CHECK-NEXT: double _t15;
//CHECK-NEXT: double _t16;
//CHECK-NEXT: double _t17;
//CHECK-NEXT: double _t18;
//CHECK-NEXT: double _t19;
//CHECK-NEXT: double _t20;
//CHECK-NEXT: double _t21;
//CHECK-NEXT: double _t22;
//CHECK-NEXT: double _t23;
//CHECK-NEXT: clad::tape<double> _t2 = {};
//CHECK-NEXT: double _t3;
//CHECK-NEXT: double _t4;
//CHECK-NEXT: double _t5;
//CHECK-NEXT: double _t6;
//CHECK-NEXT: double _t7;
//CHECK-NEXT: double _t8;
//CHECK-NEXT: double _t9;
//CHECK-NEXT: double _t10;
//CHECK-NEXT: double t = 0;
//CHECK-NEXT: _t0 = 0;
//CHECK-NEXT: for (int i = 0; i < dim; i++) {
//CHECK-NEXT: _t0++;
//CHECK-NEXT: t += clad::push(_t6, (x[clad::push(_t2, i)] - p[clad::push(_t4, i)])) * clad::push(_t1, (x[clad::push(_t7, i)] - p[clad::push(_t9, i)]));
//CHECK-NEXT: clad::push(_t1, t);
//CHECK-NEXT: t += (x[i] - p[i]) * clad::push(_t2, (x[i] - p[i]));
//CHECK-NEXT: }
//CHECK-NEXT: _t12 = -t;
//CHECK-NEXT: _t14 = sigma;
//CHECK-NEXT: _t15 = 2 * _t14;
//CHECK-NEXT: _t13 = sigma;
//CHECK-NEXT: _t11 = (_t15 * _t13);
//CHECK-NEXT: t = _t12 / _t11;
//CHECK-NEXT: _t18 = 2 * 3.1415926535897931;
//CHECK-NEXT: _t19 = -dim / 2.;
//CHECK-NEXT: _t20 = std::pow(_t18, _t19);
//CHECK-NEXT: _t21 = sigma;
//CHECK-NEXT: _t17 = std::pow(_t21, -0.5);
//CHECK-NEXT: _t22 = _t20 * _t17;
//CHECK-NEXT: _t23 = t;
//CHECK-NEXT: _t16 = std::exp(_t23);
//CHECK-NEXT: _t3 = t;
//CHECK-NEXT: _t6 = sigma;
//CHECK-NEXT: _t5 = sigma;
//CHECK-NEXT: _t4 = (2 * _t6 * _t5);
//CHECK-NEXT: t = -t / _t4;
//CHECK-NEXT: _t9 = 3.1415926535897931;
//CHECK-NEXT: _t10 = 2.;
//CHECK-NEXT: _t8 = std::pow(sigma, -0.5);
//CHECK-NEXT: _t7 = std::exp(t);
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: {
//CHECK-NEXT: double _r8 = 1 * _t16;
//CHECK-NEXT: double _r9 = _r8 * _t17;
//CHECK-NEXT: double _r8 = 1 * _t7;
//CHECK-NEXT: double _r9 = _r8 * _t8;
//CHECK-NEXT: double _grad0 = 0.;
//CHECK-NEXT: double _grad1 = 0.;
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(_t18, _t19, _r9, &_grad0, &_grad1);
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(2 * _t9, -dim / _t10, _r9, &_grad0, &_grad1);
//CHECK-NEXT: double _r10 = _grad0;
//CHECK-NEXT: double _r11 = _r10 * 3.1415926535897931;
//CHECK-NEXT: double _r12 = _grad1;
//CHECK-NEXT: double _r13 = _r12 / 2.;
//CHECK-NEXT: _d_dim += -_r13;
//CHECK-NEXT: double _r14 = _t20 * _r8;
//CHECK-NEXT: double _r11 = _r10 * _t9;
//CHECK-NEXT: double _r12 = 2 * _r10;
//CHECK-NEXT: double _r13 = _grad1;
//CHECK-NEXT: double _r14 = _r13 / _t10;
//CHECK-NEXT: _d_dim += -_r14;
//CHECK-NEXT: double _r15 = _r13 * --dim / (_t10 * _t10);
//CHECK-NEXT: double _r16 = std::pow(2 * _t9, -dim / _t10) * _r8;
//CHECK-NEXT: double _grad2 = 0.;
//CHECK-NEXT: double _grad3 = 0.;
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(_t21, -0.5, _r14, &_grad2, &_grad3);
//CHECK-NEXT: double _r15 = _grad2;
//CHECK-NEXT: _d_sigma += _r15;
//CHECK-NEXT: double _r16 = _grad3;
//CHECK-NEXT: double _r17 = _t22 * 1;
//CHECK-NEXT: double _r18 = _r17 * clad::custom_derivatives::exp_pushforward(_t23, 1.).pushforward;
//CHECK-NEXT: _d_t += _r18;
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(sigma, -0.5, _r16, &_grad2, &_grad3);
//CHECK-NEXT: double _r17 = _grad2;
//CHECK-NEXT: _d_sigma += _r17;
//CHECK-NEXT: double _r18 = _grad3;
//CHECK-NEXT: double _r19 = std::pow(2 * _t9, -dim / _t10) * _t8 * 1;
//CHECK-NEXT: double _r20 = _r19 * clad::custom_derivatives::exp_pushforward(t, 1.).pushforward;
//CHECK-NEXT: _d_t += _r20;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: t = _t3;
//CHECK-NEXT: double _r_d1 = _d_t;
//CHECK-NEXT: double _r2 = _r_d1 / _t11;
//CHECK-NEXT: double _r2 = _r_d1 / _t4;
//CHECK-NEXT: _d_t += -_r2;
//CHECK-NEXT: double _r3 = _r_d1 * -_t12 / (_t11 * _t11);
//CHECK-NEXT: double _r4 = _r3 * _t13;
//CHECK-NEXT: double _r5 = _r4 * _t14;
//CHECK-NEXT: double _r3 = _r_d1 * --t / (_t4 * _t4);
//CHECK-NEXT: double _r4 = _r3 * _t5;
//CHECK-NEXT: double _r5 = _r4 * _t6;
//CHECK-NEXT: double _r6 = 2 * _r4;
//CHECK-NEXT: _d_sigma += _r6;
//CHECK-NEXT: double _r7 = _t15 * _r3;
//CHECK-NEXT: double _r7 = 2 * _t6 * _r3;
//CHECK-NEXT: _d_sigma += _r7;
//CHECK-NEXT: _d_t -= _r_d1;
//CHECK-NEXT: }
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: t = clad::pop(_t1);
//CHECK-NEXT: double _r_d0 = _d_t;
//CHECK-NEXT: _d_t += _r_d0;
//CHECK-NEXT: double _r0 = _r_d0 * clad::pop(_t1);
//CHECK-NEXT: int _t3 = clad::pop(_t2);
//CHECK-NEXT: int _t5 = clad::pop(_t4);
//CHECK-NEXT: _d_p[_t5] += -_r0;
//CHECK-NEXT: double _r1 = clad::pop(_t6) * _r_d0;
//CHECK-NEXT: int _t8 = clad::pop(_t7);
//CHECK-NEXT: int _t10 = clad::pop(_t9);
//CHECK-NEXT: _d_p[_t10] += -_r1;
//CHECK-NEXT: double _r0 = _r_d0 * clad::pop(_t2);
//CHECK-NEXT: _d_p[i] += -_r0;
//CHECK-NEXT: double _r1 = (x[i] - p[i]) * _r_d0;
//CHECK-NEXT: _d_p[i] += -_r1;
//CHECK-NEXT: _d_t -= _r_d0;
//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 0c23136

Please sign in to comment.