-
Notifications
You must be signed in to change notification settings - Fork 125
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
TBR analysis doesn't include the for loop's step in the forward pass when there's a statement inside with a body of its own #855
Comments
The code looks good to me. Could you explain what concerns you in particular? How should the for loop's step be included? |
Yes, here the result is not compromised, but if it depended on the value of i (e.g. val += i) then it would be wrong. Hence, the increment of i should be included similarly to the case where TBR is not enabled. |
Do you mean
gives us
where we see both |
Agreed, but when there's an if or a switch statement or generally a statement with a body, its body isn't traversed I suppose and hence the increment is not included. double fn21(double val) {
double res = 0;
for (int i=1; i<5; ++i) {
if (i == 3)
continue;
res += i * val;
}
return res;
}
void fn21_grad(double val, double *_d_val) {
double _d_res = 0;
unsigned long _t0;
int _d_i = 0;
int i = 0;
clad::tape<bool> _t2 = {};
clad::tape<unsigned long> _t3 = {};
double res = 0;
_t0 = 0;
for (i = 1; i < 5; ++i) {
_t0++;
bool _t1 = i == 3;
{
if (_t1) {
clad::push(_t3, 1UL);
continue;
}
clad::push(_t2, _t1);
}
res += i * val;
clad::push(_t3, 2UL);
}
goto _label0;
_label0:
_d_res += 1;
for (; _t0; _t0--)
switch (clad::pop(_t3)) {
case 2UL:
;
{
double _r_d0 = _d_res;
_d_i += _r_d0 * val;
*_d_val += i * _r_d0;
}
if (clad::pop(_t2))
case 1UL:
;
}
} Without TBR: void fn21_grad(double val, double *_d_val) {
double _d_res = 0;
unsigned long _t0;
int _d_i = 0;
int i = 0;
clad::tape<bool> _t2 = {};
clad::tape<unsigned long> _t3 = {};
clad::tape<double> _t4 = {};
double res = 0;
_t0 = 0;
for (i = 1; i < 5; ++i) {
_t0++;
bool _t1 = i == 3;
{
if (_t1) {
clad::push(_t3, 1UL);
continue;
}
clad::push(_t2, _t1);
}
clad::push(_t4, res);
res += i * val;
clad::push(_t3, 2UL);
}
goto _label0;
_label0:
_d_res += 1;
for (; _t0; _t0--) {
--i;
switch (clad::pop(_t3)) {
case 2UL:
;
{
res = clad::pop(_t4);
double _r_d0 = _d_res;
_d_i += _r_d0 * val;
*_d_val += i * _r_d0;
}
if (clad::pop(_t2))
case 1UL:
;
}
}
}
I will update the issue title as this case was the one that made me open the issue in the first place. |
Okay, this is definitely a bug. I will need more time to find out why this happens. Thank you for pointing this out. |
@kchristin22, do you mind looking in the tbr analysis and try to pinpoint the underlying problem? Petro is overloaded with other things in the next couple of weeks. |
Unfortunately my schedule is also pretty packed these weeks. I'll try to have a look if possible. |
…passed branch Before the fix, we didn't collect data from varsData at all, and it wasn't merge afterward either. Now, we start collecting data from varsData, ensuring the final data of the CFG block is correct. Fixes:vgvassilev#855
Fixed by #1051. |
Gradient:
The text was updated successfully, but these errors were encountered: