Skip to content

Dynamic Program Analysis based on Valgrind to find Floating-Point Accuracy Problems

Notifications You must be signed in to change notification settings

dpc-grindland/FpDebug

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FpDebug is a heavyweight Valgrind tool for detecting floating-point accuracy problems.

The tool uses MPFR for its analysis. Because MPFR is run with the tool on top of Valgrind, it has only access to the partial C library provided by Valgrind. Thus, a patch for MPFR is provided that adjusts it to run on top of Valgrind. As GMP is used by MFPR, a patch for GMP is also  provided.

NOTE: The tool was only tested on 64bit systems.

Detailed installation instructions for Ubuntu 12.04.5 LTS (64bit):
Is is assumed that the home folder is '/home/test', otherwise just replace this part of the paths.

$ sudo apt-get install git
m4 is a dependency of GMP
$ sudo apt-get install m4
libc6-dbg is required for Valgrind (otherwise it fails at runtime)
$ sudo apt-get install libc6-dbg
$ mkdir pldi; cd pldi
$ git clone https://github.com/fbenz/FpDebug.git

GMP
Unpack GMP 5.0.1 into the 'FpDebug/gmp' folder
$ patch -p1 -i gmp-5.0.1.patch
$ ./configure --prefix=/home/test/pldi/FpDebug/gmp/install
$ make
$ make check
fails because of patch
$ make install

MPFR
Unpack MPFR 3.0.0 into the 'FpDebug/mpfr' folder
$ ./configure --prefix=/home/test/pldi/FpDebug/mpfr/install --with-gmp=/home/test/pldi/FpDebug/gmp/install
$ patch -p1 -i mpfr-3.0.0.patch
$ make
$ make check
fails because of patch
$ make install

Valgrind
Unpack Valgrind 3.7.0 into the 'FpDebug/valgrind'

Edit configure by adding "fpdebug/Makefile" to the AC_CONFIG_FILES list.

add the following to lines to AM_CFLAGS_BASE in fpdebug/Makefile.in
	-I/home/test/pldi/FpDebug/gmp/install/include/ \
	-I/home/test/pldi/FpDebug/mpfr/install/include/

replace the content of TOOL_LDADD_COMMON in fpdebug/Makefile.in with
TOOL_LDADD_COMMON = -lgcc -Wl,-rpath -Wl,/home/test/pldi/FpDebug/gmp/install/lib/libgmp.a -Wl,/home/test/pldi/FpDebug/mpfr/install/lib/libmpfr.a -Wl,/home/test/pldi/FpDebug/gmp/install/lib/libgmp.a

$ ./configure --prefix=/home/test/pldi/FpDebug/valgrind/install

Problem: checking the GLIBC_VERSION version... unsupported version 2.15
         configure: error: Valgrind requires glibc version 2.2 - 2.14
Solution: http://stackoverflow.com/a/10569078
add the following around line 6404
"2.15)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 2.15 family" >&5
$as_echo "2.15 family" >&6; }

$as_echo "#define GLIBC_2_14 1" >>confdefs.h

DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
;;"

Edit Makefile by adding the new directory "fpdebug" to the EXP_TOOLS variables.
Create valgrind/fpdebug/tests with a Makefile (e.g. copy test folder from valgrind/none)
$ make
$ make install


$ cd fpdebug/examples
$ gcc test_1.c -O0 -g -o test_1.out
(or $ gcc test_1.c -O0 -g -mfpmath=387 -o test_1.out )
$ /home/test/pldi/FpDebug/valgrind/install/bin/valgrind --tool=fpdebug /home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out
should write the following to standard out:

==7041== FpDebug-0.1, Floating-point arithmetic debugger
==7041== Copyright (C) 2010-2011 by Florian Benz.
==7041== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==7041== Command: /home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out
==7041== 
==7041== precision=120
==7041== mean-error=yes
==7041== ignore-libraries=no
==7041== ignore-accurate=yes
==7041== sim-original=no
==7041== analyze-all=yes
==7041== bad-cancellations=yes
==7041== ignore-end=no
Test program: machine epsilon, client request
Sum: 1.0000000e+00
Running on valgrind
==7041== (float) sum PRINT ERROR OF: 0x7FF0000F4
==7041== (float) sum ORIGINAL:          1.00000000000000 * 10^0, 1/120 bit
==7041== (float) sum SHADOW VALUE:      1.00000025000000 * 10^0, 49/120 bit
==7041== (float) sum ABSOLUTE ERROR:    2.50000002921524 * 10^-7, 27/120 bit
==7041== (float) sum RELATIVE ERROR:    2.49999940421539 * 10^-7, 120/120 bit
==7041== (float) sum CANCELED BITS:     0
==7041== (float) sum Last operation: 0x4007AD: main (test_1.c:14)
==7041== (float) sum Operation count (max path): 5
==7041== DUMP GRAPH (test_1_sum.vcg): successful
==7041== 
==7041== DUMP GRAPH (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_1_0.vcg): successful
==7041== SHADOW VALUES (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_shadow_values_relative_error_1): successful
==7041== SHADOW VALUES (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_shadow_values_canceled_1): successful
==7041== SHADOW VALUES (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_shadow_values_special_1): successful
==7041== MEAN ERRORS (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_mean_errors_addr_1): successful
==7041== MEAN ERRORS (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_mean_errors_canceled_1): successful
==7041== MEAN ERRORS (/home/test/pldi/FpDebug/valgrind/fpdebug/examples/test_1.out_mean_errors_intro_1): successful

About

Dynamic Program Analysis based on Valgrind to find Floating-Point Accuracy Problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 98.0%
  • C++ 2.0%