Skip to content

Commit

Permalink
restructure python binding
Browse files Browse the repository at this point in the history
  • Loading branch information
lathuili-home committed Apr 26, 2024
1 parent 8c97dce commit 5927716
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 263 deletions.
66 changes: 40 additions & 26 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ pkginclude_HEADERS = verrou.h synchroLib/verrouSynchroLib.h

PYTHON_REP=pyTools

bin_SCRIPTS = ${PYTHON_REP}/verrou_dd_line ${PYTHON_REP}/verrou_dd_sym ${PYTHON_REP}/genCovBB ${PYTHON_REP}/verrou_plot_stat ${PYTHON_REP}/paraview_script.py ${PYTHON_REP}/verrou_dd_synchro ${PYTHON_REP}/post_verrou_dd ${PYTHON_REP}/verrou_dd_stdout
bin_SCRIPTS = ${PYTHON_REP}/verrou_dd_line ${PYTHON_REP}/verrou_dd_sym ${PYTHON_REP}/genCovBB ${PYTHON_REP}/verrou_plot_stat ${PYTHON_REP}/paraview_script.py ${PYTHON_REP}/verrou_dd_synchro ${PYTHON_REP}/post_verrou_dd ${PYTHON_REP}/verrou_dd_stdout synchroLib/trace_verrou_synchro.py

pkgpython_PYTHON = ${PYTHON_REP}/DD.py ${PYTHON_REP}/dd_config.py ${PYTHON_REP}/DD_stoch.py ${PYTHON_REP}/DD_exec_stat.py ${PYTHON_REP}/convNumLineTool.py ${PYTHON_REP}/post_config.py ${PYTHON_REP}/gen_config.py ${PYTHON_REP}/rounding_tool.py
pkgpython_PYTHON = ${PYTHON_REP}/DD.py ${PYTHON_REP}/dd_config.py ${PYTHON_REP}/DD_stoch.py ${PYTHON_REP}/DD_exec_stat.py ${PYTHON_REP}/convNumLineTool.py ${PYTHON_REP}/post_config.py ${PYTHON_REP}/gen_config.py ${PYTHON_REP}/rounding_tool.py pyWrapper/verrouPyBinding.py

install-exec-local:
mkdir -p ${pkgpythondir}
touch ${pkgpythondir}/__init__.py
install -t ${prefix} -m 644 env.sh
install -t ${verrouUnbuffereddir} verrouUnbuffered.so
install -t ${verrouCbindingDir} verrouCBinding.so


noinst_PROGRAMS = verrou-@VGCONF_ARCH_PRI@-@VGCONF_OS@
if VGCONF_HAVE_PLATFORM_SEC
Expand Down Expand Up @@ -168,27 +170,6 @@ endif





#----------------------------------------------------------------------------
# verrouSynchroLib-<platform>.so
#----------------------------------------------------------------------------

noinst_PROGRAMS += verrouSynchroLib-@VGCONF_ARCH_PRI@-@[email protected]
if VGCONF_HAVE_PLATFORM_SEC
noinst_PROGRAMS += verrouSynchroLib-@VGCONF_ARCH_SEC@-@[email protected]
endif

VERROUSYNCHROLIB_SOURCES_COMMON = synchroLib/verrouSynchroLib.cxx

verrouSynchroLib_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_SOURCES = \
$(VERROUSYNCHROLIB_SOURCES_COMMON)
verrouSynchroLib_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CPPFLAGS = \
$(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@)
verrouSynchroLib_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDFLAGS = \
$(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)


#----------------------------------------------------------------------------
# vgpreload_verrou-<platform>.so
#----------------------------------------------------------------------------
Expand All @@ -214,7 +195,7 @@ vgpreload_verrou_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDFLAGS = \
vgpreload_verrou_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDADD = -ldl $(VERROU_LD)

#----------------------------------------------------------------------------
# verrouUnbuffered-<platform>.so
# verrouUnbuffered.so
#----------------------------------------------------------------------------
verrouUnbuffereddir = $(pkglibdir)
noinst_PROGRAMS += verrouUnbuffered.so
Expand All @@ -224,6 +205,39 @@ VERROUUNBUFFERED_SOURCES_COMMON = unbufferPrintf.c
verrouUnbuffered_so_SOURCES = \
$(VERROUUNBUFFERED_SOURCES_COMMON)
verrouUnbuffered_so_CPPFLAGS = \
$(subst -Wstrict-prototypes,,$(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@)) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@)
verrouUnbuffered_so_LDFLAGS = $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)


#----------------------------------------------------------------------------
# verrouCBinding.so
#----------------------------------------------------------------------------
verrouCbindingDir = $(pkglibdir)
noinst_PROGRAMS += verrouCBinding.so


VERROUCBINDING_SOURCES_COMMON = pyWrapper/verrouCBinding.c

verrouCBinding_so_SOURCES = $(VERROUCBINDING_SOURCES_COMMON)
verrouCBinding_so_CPPFLAGS = \
$(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@)
verrouCBinding_so_LDFLAGS = $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)


#----------------------------------------------------------------------------
# verrouSynchro.so
#----------------------------------------------------------------------------
noinst_PROGRAMS += verrouSynchro.so
if VGCONF_HAVE_PLATFORM_SEC
noinst_PROGRAMS += verrouSynchro.so
endif

PRELOADSYNCHRO1 = $(subst -nodefaultlibs,,$(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@))
PRELOADSYNCHRO = $(subst -m64,,$(PRELOADSYNCHRO1))

VERROUSYNCHRO_SOURCES_COMMON = synchroLib/verrouSynchroLib.cxx
verrouSynchro_so_SOURCES = $(VERROUSYNCHRO_SOURCES_COMMON)
verrouSynchro_so_CPPFLAGS = \
$(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@)
verrouUnbuffered_so_LDFLAGS = \
$(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
verrouSynchro_so_LDFLAGS = -static-libstdc++ \
$(PRELOADSYNCHRO)
12 changes: 7 additions & 5 deletions pyTools/verrou_dd_stdout
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ class DDstdout(DD_stoch.DDStoch):
refFile.write("begin:\n")
refFile.close()
res= {"PYTHONUNBUFFERED": "x",
"VERROU_ROUNDING_MODE": self.config_.referenceRounding,
"VERROU_MCA_MODE": "ieee",
"VERROU_EXPECT_CLR":refPath,
"VERROU_OUTPUT_EXPECT_REP":self.ref_
}
"LD_PRELOAD": "verrouUnbuffered.so:"+os.environ["LD_PRELOAD"],
"VERROU_ROUNDING_MODE": self.config_.referenceRounding,
"VERROU_MCA_MODE": "ieee",
"VERROU_EXPECT_CLR":refPath,
"VERROU_OUTPUT_EXPECT_REP":self.ref_
}
filePattern=self.config_.get_file_pattern()
if filePattern!=None:
res["VERROU_EXPECT_FILE_PATTERN"]=filePattern
Expand Down Expand Up @@ -209,6 +210,7 @@ class DDstdout(DD_stoch.DDStoch):

def sampleRunEnv(self,dirName):
res={"PYTHONUNBUFFERED": "x",
"LD_PRELOAD": "verrouUnbuffered.so:"+os.environ["LD_PRELOAD"],
"VERROU_EXPECT_CLR": os.path.join(dirName, "vr_expect.txt"),
"VERROU_OUTPUT_EXPECT_REP":os.path.join(dirName,"%DDRUN%"),
"VERROU_LIBM_NOINST_ROUNDING_MODE":self.config_.referenceRounding,
Expand Down
16 changes: 8 additions & 8 deletions synchroLib/verrouCBinding.c → pyWrapper/verrouCBinding.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@

#include <stdio.h>

void c_verrou_start_instrumentation(){
void c_verrou_start_instrumentation(void){
VERROU_START_INSTRUMENTATION;
}

void c_verrou_stop_instrumentation(){
void c_verrou_stop_instrumentation(void){
VERROU_STOP_INSTRUMENTATION;
}

void c_verrou_start_soft_instrumentation(){
void c_verrou_start_soft_instrumentation(void){
VERROU_START_SOFT_INSTRUMENTATION;
}

void c_verrou_stop_soft_instrumentation(){
void c_verrou_stop_soft_instrumentation(void){
VERROU_STOP_SOFT_INSTRUMENTATION;
}

Expand All @@ -55,21 +55,21 @@ void c_verrou_stop_determinitic(int level){
}


void c_verrou_display_counters(){
void c_verrou_display_counters(void){
VERROU_DISPLAY_COUNTERS;
}

unsigned int c_verrou_dump_cover(){
unsigned int c_verrou_dump_cover(void){
return VERROU_DUMP_COVER;
}


unsigned int c_verrou_count_fp_instrumented(){
unsigned int c_verrou_count_fp_instrumented(void){
unsigned int res=VERROU_COUNT_FP_INSTRUMENTED;
return res;
}

unsigned int c_verrou_count_fp_not_instrumented(){
unsigned int c_verrou_count_fp_not_instrumented(void){
unsigned int res=VERROU_COUNT_FP_NOT_INSTRUMENTED;
return res;
}
23 changes: 23 additions & 0 deletions pyWrapper/verrouCBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

//C functions to call verrou client request

// start/stop instrumentation
void c_verrou_start_instrumentation(void);
void c_verrou_stop_instrumentation(void);

void c_verrou_start_soft_instrumentation(void);
void c_verrou_stop_soft_instrumentation(void);

// define derteministic section
void c_verrou_start_determinitic(int level);
void c_verrou_stop_determinitic(int level);

//dump cover
unsigned int c_verrou_dump_cover(void);


//counters
void c_verrou_display_counters(void);
unsigned int c_verrou_count_fp_instrumented(void);
unsigned int c_verrou_count_fp_not_instrumented(void);
125 changes: 125 additions & 0 deletions pyWrapper/verrouPyBinding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/python3
import sys, platform
import ctypes, ctypes.util
import os
import os.path


def searchDefaultPath(fileName):
dirName=os.path.dirname(os.path.abspath(__file__))
pathPrefixTab=["./", dirName, os.path.join(dirName, "..", "lib"),
os.path.join(dirName, "..", "..","..","valgrind"),
os.path.join(dirName, "..", "..","..","..","libexec","valgrind"),
"../"
]

print(pathPrefixTab, file=sys.stderr)
for pathPrefix in pathPrefixTab:
absPath=os.path.join(pathPrefix, fileName)
if os.path.exists(absPath):
# print("absPath: ", absPath,file=sys.stderr)
return absPath
print("FileName %s not found"%(fileName),file=sys.stderr)
sys.exit(42)

class bindingSynchroLib:
def __init__(self, pathLib=None):
if(pathLib!=None):
self.lib=ctypes.CDLL(pathLib)
else:
self.lib=ctypes.CDLL(searchDefaultPath("verrouSynchro.so"), ctypes.RTLD_GLOBAL )
self.lib.verrou_synchro.argtypes = [ ctypes.c_char_p, ctypes.c_int]
self.lib.verrou_synchro_init()
def __del__(self):
self.lib.verrou_synchro_finalyze()

bindSynchro=bindingSynchroLib()

def synchro(string, index):
bindSynchro.lib.verrou_synchro(string.encode('utf-8'), index)

class bindingVerrouCLib:
def __init__(self, pathLib=None):
if(pathLib!=None):
self.lib=ctypes.CDLL(pathLib)
else:
self.lib=ctypes.CDLL(searchDefaultPath("verrouCBinding.so") )

self.lib.c_verrou_start_instrumentation.argtypes = []
self.lib.c_verrou_stop_instrumentation.argtypes = []
self.lib.c_verrou_start_soft_instrumentation.argtypes = []
self.lib.c_verrou_stop_soft_instrumentation.argtypes = []
self.lib.c_verrou_start_determinitic.argtypes = [ctypes.c_int]
self.lib.c_verrou_stop_determinitic.argtypes = [ctypes.c_int]

self.lib.c_verrou_display_counters.argtypes = []

self.lib.c_verrou_dump_cover.argtypes= []
self.lib.c_verrou_dump_cover.restype= ctypes.c_uint

self.lib.c_verrou_count_fp_instrumented.argtypes= []
self.lib.c_verrou_count_fp_not_instrumented.argtypes= []
self.lib.c_verrou_count_fp_instrumented.restype= ctypes.c_uint
self.lib.c_verrou_count_fp_not_instrumented.restype= ctypes.c_uint


bindVerrou=bindingVerrouCLib()

def start_instrumentation():
bindVerrou.lib.c_verrou_start_instrumentation()

def stop_instrumentation():
bindVerrou.lib.c_verrou_stop_instrumentation()

def start_soft_instrumentation():
bindVerrou.lib.c_verrou_start_soft_instrumentation()

def stop_soft_instrumentation():
bindVerrou.lib.c_verrou_stop_soft_instrumentation()

def start_determinitic (level):
bindVerrou.lib.c_verrou_start_determinitic(level)

def stop_determinitic (level):
bindVerrou.lib.c_verrou_stop_determinitic(level)

def dump_cover():
return bindVerrou.lib.c_verrou_dump_cover();

def display_counters():
bindVerrou.lib.c_verrou_display_counters()

def count_fp_instrumented():
return bindVerrou.lib.c_verrou_count_fp_instrumented()

def count_fp_not_instrumented():
return bindVerrou.lib.c_verrou_count_fp_not_instrumented()



if __name__=="__main__":

print("avt a binding fp: ", count_fp_instrumented())
print("avt a binding not fp: ", count_fp_not_instrumented())
a=3.*4.
print(a)
print("apres a binding fp: ", count_fp_instrumented())
print("apres a binding not fp: ", count_fp_not_instrumented())


synchro("toto",10)

display_counters()
start_instrumentation()
a=3.*4
stop_instrumentation()

synchro("toto",10)
start_instrumentation()

a*=5
stop_instrumentation()

print(a)
synchro("toto",10)

Loading

0 comments on commit 5927716

Please sign in to comment.