Skip to content

Commit

Permalink
Merge branch 'miscellaneous' into 'derivgrind'
Browse files Browse the repository at this point in the history
More math wrappers, fixes and improved documentation 
in test system, work on bit-trick finder

See merge request aehle/valgrind!28
  • Loading branch information
maxaehle committed Jan 12, 2025
2 parents d441dc2 + 8c27907 commit ae97ba7
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 83 deletions.
14 changes: 10 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: debian:11.5
image: debian:12.5

variables:
GIT_SUBMODULE_STRATEGY: recursive
Expand Down Expand Up @@ -72,7 +72,9 @@ test_perf_x86:
script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get install -y build-essential gcc-multilib g++-multilib clang python3 python3-numpy python3-pip time
- apt-get install -y build-essential gcc-multilib g++-multilib clang python3 python3-numpy python3-pip python3-venv time
- python3 -m venv env
- . env/bin/activate
- pip install anybadge
- mkdir -p badges
- anybadge -l 'Forward-mode run-time' -v 'Error' -f badges/dot_gcc_o3_x86.svg -c 'red'
Expand All @@ -88,7 +90,9 @@ test_torch_x86:
script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get install -y build-essential gcc-multilib g++-multilib python3 python3-pip
- apt-get install -y build-essential gcc-multilib g++-multilib python3 python3-pip python3-venv
- python3 -m venv env
- . env/bin/activate
- pip install torch numpy
- |
cat > mylib.c <<EOF
Expand Down Expand Up @@ -116,7 +120,9 @@ test_tensorflow_x86:
script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get install -y build-essential gcc-multilib g++-multilib python3 python3-pip
- apt-get install -y build-essential gcc-multilib g++-multilib python3 python3-pip python3-venv
- python3 -m venv env
- . env/bin/activate
- pip install tensorflow numpy
- |
cat > mylib.c <<EOF
Expand Down
19 changes: 1 addition & 18 deletions derivgrind/bar/dg_bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,7 @@ void* dg_bar_constant(DiffEnv* diffenv, IRConstTag type){
}

void* dg_bar_default_(DiffEnv* diffenv, IRType type){
IRExpr* zeroU = IRExpr_Const(IRConst_U64(0));
IRExpr* zero;
switch(type){
case Ity_INVALID: tl_assert(False); return NULL;
case Ity_I1: zero = IRExpr_Const(IRConst_U1(0)); break;
case Ity_I8: zero = IRExpr_Const(IRConst_U8(0)); break;
case Ity_I16: zero = IRExpr_Const(IRConst_U16(0)); break;
case Ity_I32: zero = IRExpr_Const(IRConst_U32(0)); break;
case Ity_I64: zero = zeroU; break;
case Ity_I128: zero = IRExpr_Const(IRConst_U128(0)); break;
case Ity_F32: zero = IRExpr_Unop(Iop_ReinterpI32asF32,IRExpr_Const(IRConst_U32(0))); break;
case Ity_F64: zero = IRExpr_Const(IRConst_F64i(0)); break;
case Ity_D64: zero = IRExpr_Unop(Iop_ReinterpI64asD64,zeroU); break;
case Ity_F128: zero = IRExpr_Unop(Iop_ReinterpI128asF128,IRExpr_Const(IRConst_U128(0))); break;
case Ity_V128: zero = IRExpr_Binop(Iop_64HLtoV128, zeroU, zeroU); break;
case Ity_V256: zero = IRExpr_Qop(Iop_64x4toV256, zeroU, zeroU, zeroU, zeroU); break;
default: tl_assert(False); return NULL;
}
IRExpr* zero = mkIRConst_zero(type);
return mkIRExprVec_2(zero,zero);
}

Expand Down
8 changes: 5 additions & 3 deletions derivgrind/diff_tests/TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ def __init__(self, name):
self.cflags_clang = None # Additional flags for the C compiler, if clang is used
self.fflags = "" # Additional flags for the Fortran compiler
self.ldflags = "" # Additional flags for the linker, e.g. "-lm"
self.typename = "" # C/C++: "double", "float", "longdouble"; Fortran: "real4", "real8"; Python: "float", "np64", "np32"
self.type = TYPE_DOUBLE # TYPE_DOUBLE, TYPE_FLOAT, TYPE_LONG_DOUBLE (for C/C++), TYPE_REAL4, TYPE_REAL8 (for Fortran)
self.arch = 32 # 32 bit (x86) or 64 bit (amd64)
self.disable = lambda mode, arch, language, typename : False # if True, test will not be run
self.compiler = "gcc" # gcc, g++, gfortran, python
self.install_dir = install_dir # Valgrind installation directory
self.temp_dir = temp_dir # directory of temporary files produced by tests
self.codi_dir = codi_dir # CoDiPack include directory for validation in performance tests
self.valgrindflags = lambda mode, arch, compiler, typename: [] # list of Valgrind flags

class InteractiveTestCase(TestCase):
"""Methods to run a Derivgrind regression test case interactively in VGDB."""
Expand Down Expand Up @@ -193,7 +195,7 @@ def save_remove(filename):
self.gdb_log = ""
# start Valgrind and extract "target remote" line
maybereverse = ["--record="+self.temp_dir] if self.mode=='b' else []
valgrind = subprocess.Popen([self.install_dir+"/bin/valgrind", "--tool=derivgrind", "--vgdb-error=0"]+maybereverse+[self.temp_dir+"/TestCase_exec"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True,bufsize=0)
valgrind = subprocess.Popen([self.install_dir+"/bin/valgrind", "--tool=derivgrind", "--vgdb-error=0"]+self.valgrindflags(self.mode,self.arch,self.compiler,self.typename)+maybereverse+[self.temp_dir+"/TestCase_exec"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True,bufsize=0)
while True:
line = valgrind.stdout.readline()
self.valgrind_log += line
Expand Down Expand Up @@ -535,7 +537,7 @@ def run_code(self):
else:
commands = [self.temp_dir+"/TestCase_exec"]
maybereverse = ["--record="+self.temp_dir] if self.mode=='b' else []
valgrind = subprocess.run([self.install_dir+"/bin/valgrind", "--tool=derivgrind"]+maybereverse+commands,capture_output=True,env=environ)
valgrind = subprocess.run([self.install_dir+"/bin/valgrind", "--tool=derivgrind"]+self.valgrindflags(self.mode,self.arch,self.compiler,self.typename)+maybereverse+commands,capture_output=True,env=environ)
if valgrind.returncode!=0:
self.errmsg +="VALGRIND STDOUT:\n"+valgrind.stdout.decode('utf-8')+"\n\nVALGRIND STDERR:\n"+valgrind.stderr.decode('utf-8')+"\n\n"
# for recording mode, evaluate tape
Expand Down Expand Up @@ -643,7 +645,7 @@ def runDG(self, nrep):
for irep in range(nrep+2): # measurements for the first two iterations are not taken into account
maybereverse = ["--record="+self.temp_dir] if self.mode=='b' else []
maybetapeinram = ["--tape-in-ram=yes"] if self.tape_in_ram else []
exe = subprocess.run(["/usr/bin/time", "-f", "time_output %e %M", self.install_dir+"/bin/valgrind", "--tool=derivgrind"]+maybereverse+maybetapeinram+[f"{self.temp_dir}/main_dg", f"{self.temp_dir}/dg-performance-result-dg.json"]+self.benchmarkargs.split(), capture_output=True)
exe = subprocess.run(["/usr/bin/time", "-f", "time_output %e %M", self.install_dir+"/bin/valgrind", "--tool=derivgrind"]+self.valgrindflags(self.mode,self.arch,self.compiler,self.typename)+maybereverse+maybetapeinram+[f"{self.temp_dir}/main_dg", f"{self.temp_dir}/dg-performance-result-dg.json"]+self.benchmarkargs.split(), capture_output=True)
if exe.returncode!=0:
self.errmsg += "EXECUTION WITH DERIVGRIND FAILED:\n" + "STDOUT:\n" + exe.stdout.decode('utf-8') + "\nSTDERR:\n" + exe.stderr.decode('utf-8')
with open(self.temp_dir+"/dg-performance-result-dg.json") as f:
Expand Down
Loading

0 comments on commit ae97ba7

Please sign in to comment.