uwplse / herbgrind

A Valgrind tool for Herbie
GNU General Public License v3.0
90 stars 7 forks source link

Confusion with error reported #33

Closed sangeeta0201 closed 6 years ago

sangeeta0201 commented 6 years ago

Hi,

I have run herbgrind with one of the microbenchmarks - sum-50.c Herbgrind reports 2.000000 bits average error aggregated over 1 instances but there is only fp computation and that is 'add' and its executed 52 times then why herbgrind reports average over 1 instance, whereas compare is reported over 52 times.

int main() {
  volatile double x;
  for (x = 0.0; x < 10.0; x += 0.2);
  printf("%.20g\n", x);
}
./herbgrind.sh bench/sum-50.c.out
==18853== Herbgrind, a valgrind tool for Herbie
==18853== Copyright (C) 2016-2017, and GNU GPL'd, by Alex Sanchez-Stern
==18853== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==18853== Command: bench/sum-50.c.out
==18853== 
10.199999999999995737
==18853== 

herbgrind$ cat bench/sum-50.c.out.gh 
Output @ sum-50.c:6 in main (addr 40057D)
2.000000 bits average error
2.000000 bits max error
Aggregated over 1 instances
Influenced by erroneous expression:

No influences found!

compare @ sum-50.c:5 in main (addr 400554)
1% incorrect
1 incorrect values
52 total instances
Influenced by erroneous expressions:

No influences found!
pavpanchekha commented 6 years ago

Ah, here Herbgrind is indicating that there are two spots: is one output executed once (with 2 bits average error and no influences, since the rounding error is never very large), and one comparison executed 52 times (with 1 incorrect result, out of 52, again with no influences).

I admit it is a little confusing, but here Herbgrind is not printing any information about any FP computations (you would need to lower the threshold to see that); it is only printing information about outputs and comparisons.

sangeeta0201 commented 6 years ago

But the average error is incorrect if I understand correctly. The average error should be total error calculated for 52 iterations, divided by 52.

sangeeta0201 commented 6 years ago

Also, when I enable logging in herbgrind it shows -

The shadow value is 7.00000000000000e0, but 7.000000 was computed.
2.321928 bits error (4 ulps)

So max error should be 2.3 but its showing in output file as 2.0

pavpanchekha commented 6 years ago

Sorry, I was unclear. The average error you see is the average error of the value passed to printf. You only call printf once, so the average error is computed across that one instance.