Skip to content
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

Ah/branch backend libs #37

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ jobs:
run: python -m pip install Jinja2
- name: Installing pytest
run: python -m pip install pytest
- name: Update submodules (Linux)
run: |
git submodule update --init
git submodule foreach 'git checkout main'
- name: Running cmake (Linux)
run: |
ls ${{github.workspace}}
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_FMA_INTRINSIC=1 ..
- name: Build Solution (Linux)
run: |
cd build
Expand Down
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "extern/interflop"]
path = extern/interflop
url = https://github.com/a-hamitouche/interflop-stdlib.git
[submodule "extern/interflop-backend-ieee"]
path = extern/interflop-backend-ieee
url = https://github.com/a-hamitouche/interflop-backend-ieee.git
[submodule "extern/interflop-backend-verrou"]
path = extern/interflop-backend-verrou
url = https://github.com/a-hamitouche/interflop-backend-verrou.git
[submodule "extern/interflop-backend-vprec"]
path = extern/interflop-backend-vprec
url = https://github.com/a-hamitouche/interflop-backend-vprec.git
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ endif()

# Include sub-projects.

if(UNIX)
include_directories("extern")
include_directories("extern/interflop")
add_subdirectory ("extern")
endif()

include_directories("include")
include_directories("include/replace/backend/backend_verrou")
add_subdirectory("code_generator")
Expand All @@ -105,3 +111,4 @@ add_subdirectory ("Test/cpp_unit")
add_subdirectory ("Test/test_backend")
add_subdirectory ("Test/test_backend_verrou")


44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ To do so, run via your command line on Linux or your powershell on Windows:

```shell
cd [PENE repository]
cmake .
git submodule update --init
git submodule foreach 'git checkout main'
cmake -DUSE_FMA_INTRINSIC=1 .
cmake --build .
ctest -C Debug
```
Expand All @@ -47,6 +49,9 @@ Without specifying any options, this command will execute your code under PENE w

# How to instrument your code with PENE?

PENE offers two ways to instrument code. A cross-plateforme based on backend [Verrou](https://github.com/edf-hpc/verrou) named **fp-replace** and on based one [Interflop](https://github.com/interflop), available on Linux only.

## **FP-REPLACE** mode
To instrument your code, you can use the **fp-replace** option:

```shell
Expand All @@ -70,6 +75,43 @@ where:
- rounding-mode = 4 : rounding to zero
- rounding-mode = 5 : random rounding

## **INTERFLOP** mode (Linux only)

The interflop mode allows to dynamicaly load up to 16 backends and make them work separately. Available backends are :

| Backend | Description |
|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
|[backend ieee](https://github.com/a-hamitouche/interflop-backend-ieee) | The IEEE backend implements straighforward IEEE-754 arithmetic. It should have no effect on the output and behavior of your program. |
|[backend verrou](https://github.com/a-hamitouche/interflop-backend-verrou) | The Verrou backend implements software couterpart of all IEEE-754 standard rounding modes |
|[backend vprec](https://github.com/a-hamitouche/interflop-backend-vprec) | The VPREC backend simulates any floating-point formats that can fit into the IEEE-754 double precision format with a round to the nearest.|

Each of these backends accepts different arguments and exhibits distinct behavior. To learn more, please consult the README.md files of each backend (located in the external subfolder or on their GitHub page).
With this mode, backends can be used with a scalar mode (by devectorizing operations) or in vector mode to reduce instrumentation overhead.

Usage :

```bash
VFC_BACKENDS="libbackend.so [option]" path/to/pin -t path/to/pene.so/or/pene.so -interflop -- path/to/executable
```

Exemple of usage with Verrou :


```bash
#Scalar mode
VFC_BACKENDS="libinterflop_verrou.so --rounding-mode=upward" path/to/pin -t path/to/pene.so/or/pene.so -interflop -- path/to/executable

#Vector mode
VFC_BACKENDS="libinterflop_verrou.so --rounding-mode=downward" path/to/pin -t path/to/pene.so/or/pene.so -interflop -vector-mode -- path/to/executable

#Multiple backends
VFC_BACKENDS="libinterflop_verrou.so --rounding-mode=upward; libinterflop_vprec.so --mode=full --precision-binary32=23 --debug" path/to/pin -t path/to/pene.so/or/pene.so -interflop -- path/to/executable
```

/!\ Note :
- Proposed backends fully work only in scalar mode
- For backend Verrou, only nearest, upward and downward modes are available on vector mode

## How to exclude parts of the code from instrumentation?

You can filter which parts of the code your want to instrument using the option `-exclude` along with an exclusion file containing a list of the functions you want to exclude.
Expand Down
113 changes: 113 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
project("Interflop")


include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/interflop")

if(DEFINED USE_FMA_INTRINSIC)
message("-- Using FMA Intrinsic")
set(HAVE_FMA_INTRINSIC=${HAVE_FMA_INTRINSIC})
set(FMA_FLAGS "-mfma")
endif()

set(CRT_COMPILE_DEFINITIONS
# Preprocessor Options
"-D__PIN__=1 -DPIN_CRT=1 "
"-DTARGET_IA32E -DHOST_IA32E "
"-DTARGET_LINUX "
${HAVE_FMA_INTRINSIC}
"-DHAVE_FENV_H "
"-D__PENE_FRONTEND__ "
)
set(CRT_COMPILE_OPTIONS
# Compilateur (middle)
"-funwind-tables" # Code Gen Options
"-fasynchronous-unwind-tables" # Code Gen Option
"-fomit-frame-pointer" # Code Optimize Options
"-fno-strict-aliasing" # Code Optimize Options
"-fno-stack-protector" # Instrumentation Options
${FMA_FLAGS}
"-fPIC"
)
set(CRT_PREPROCESS_OPTIONS
# Preprocesseur (front)
"-isystem ${PIN_ROOT}/extras/stlport/include "
"-isystem ${PIN_ROOT}/extras/libstdc++/include "
"-isystem ${PIN_ROOT}/extras/crt/include "
"-isystem ${PIN_ROOT}/extras/crt/include/arch-x86_64 "
"-isystem ${PIN_ROOT}/extras/crt/include/kernel/uapi "
"-isystem ${PIN_ROOT}/extras/crt/include/kernel/uapi/asm-x86 "
"-I${PIN_ROOT}/source/include/pin "
"-I${PIN_ROOT}/source/include/pin/gen "
"-I${PIN_ROOT}/extras/components/include "
"-I${PIN_ROOT}/extras/xed-intel64/include/xed "
)
set(CRT_CXX_COMPILE_OPTIONS
"-fno-exceptions"
"-fno-rtti"
"-fPIC"
"-faligned-new"
)
set(CRT_LINK_OPTIONS
"-fPIC"
"-Wl,--hash-style=sysv"
)

set(CRT_LINK_LIBRARIES
"-L${PIN_ROOT}/intel64/runtime/pincrt"
"-L${PIN_ROOT}/intel64/lib-ext"
"-nostdlib" "c-dynamic" "m-dynamic" "stlport-dynamic" "pin3dwarf" "dl-dynamic"
)

set(OUTPUT_DIRECTORY "${PIN_ROOT}/intel64/lib-ext")

add_subdirectory ("argp")
add_subdirectory ("interflop")
add_subdirectory ("interflop-backend-verrou")
add_subdirectory ("interflop-backend-vprec")
add_subdirectory ("interflop-backend-ieee")

get_directory_property(CRT_COMPILE_DEFINITIONS DIRECTORY interflop VARIABLES CRT_COMPILE_DEFINITIONS
DIRECTORY interflop-backend-verrou VARIABLES CRT_COMPILE_DEFINITIONS
DIRECTORY interflop-backend-vprec VARIABLES CRT_COMPILE_DEFINITIONS
DIRECTORY interflop-backend-ieee VARIABLES CRT_COMPILE_DEFINITIONS
DIRECTORY argp VARIABLES CRT_COMPILE_DEFINITIONS
)
get_directory_property(CRT_COMPILE_OPTIONS DIRECTORY interflop VARIABLES CRT_COMPILE_OPTIONS
DIRECTORY interflop-backend-verrou VARIABLES CRT_COMPILE_OPTIONS
DIRECTORY interflop-backend-vprec VARIABLES CRT_COMPILE_OPTIONS
DIRECTORY interflop-backend-ieee VARIABLES CRT_COMPILE_OPTIONS
DIRECTORY argp VARIABLES CRT_COMPILE_OPTIONS
)
get_directory_property(CRT_CXX_COMPILE_OPTIONS DIRECTORY interflop VARIABLES CRT_CXX_COMPILE_OPTIONS
DIRECTORY interflop-backend-verrou VARIABLES CRT_CXX_COMPILE_OPTIONS
DIRECTORY interflop-backend-vprec VARIABLES CRT_CXX_COMPILE_OPTIONS
DIRECTORY interflop-backend-ieee VARIABLES CRT_CXX_COMPILE_OPTIONS
DIRECTORY argp VARIABLES CRT_CXX_COMPILE_OPTIONS
)
get_directory_property(CRT_PREPROCESS_OPTIONS DIRECTORY interflop VARIABLES CRT_PREPROCESS_OPTIONS
DIRECTORY interflop-backend-verrou VARIABLES CRT_PREPROCESS_OPTIONS
DIRECTORY interflop-backend-vprec VARIABLES CRT_PREPROCESS_OPTIONS
DIRECTORY interflop-backend-ieee VARIABLES CRT_PREPROCESS_OPTIONS
DIRECTORY argp VARIABLES CRT_PREPROCESS_OPTIONS
)
get_directory_property(CRT_LINK_OPTIONS DIRECTORY interflop VARIABLES CRT_LINK_OPTIONS
DIRECTORY interflop VARIABLES CRT_LINK_OPTIONS
DIRECTORY interflop-backend-verrou VARIABLES CRT_LINK_OPTIONS
DIRECTORY interflop-backend-vprec VARIABLES CRT_LINK_OPTIONS
DIRECTORY interflop-backend-ieee VARIABLES CRT_LINK_OPTIONS
DIRECTORY argp VARIABLES CRT_LINK_OPTIONS
)
get_directory_property(CRT_LINK_LIBRARIES DIRECTORY interflop VARIABLES CRT_LINK_LIBRARIES
DIRECTORY interflop-backend-verrou VARIABLES CRT_LINK_LIBRARIES
DIRECTORY interflop-backend-vprec VARIABLES CRT_LINK_LIBRARIES
DIRECTORY interflop-backend-ieee VARIABLES CRT_LINK_LIBRARIES
DIRECTORY argp VARIABLES CRT_LINK_LIBRARIES
)

get_directory_property( OUTPUT_DIRECTORY DIRECTORY interflop VARIABLES OUTPUT_DIRECTORY
DIRECTORY interflop-backend-verrou VARIABLES OUTPUT_DIRECTORY
DIRECTORY interflop-backend-vprec VARIABLES OUTPUT_DIRECTORY
DIRECTORY interflop-backend-ieee VARIABLES OUTPUT_DIRECTORY
DIRECTORY argp VARIABLES OUTPUT_DIRECTORY
)
17 changes: 17 additions & 0 deletions extern/argp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project("argp")

cmake_minimum_required(VERSION 3.20)

set (ARGP_C_SRC
"argp-parse.c"
)

add_library(argp_c OBJECT ${ARGP_C_SRC})
target_compile_definitions(argp_c PRIVATE ${CRT_COMPILE_DEFINITIONS})
target_compile_options (argp_c PRIVATE ${CRT_PREPROCESS_OPTIONS} ${CRT_COMPILE_OPTIONS} "-fPIC")

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
add_library (argp SHARED $<TARGET_OBJECTS:argp_c>)
target_link_options (argp PRIVATE ${CRT_LINK_OPTIONS})
target_link_libraries (argp ${CRT_LINK_LIBRARIES})

149 changes: 149 additions & 0 deletions extern/argp/argp-namefrob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* Name frobnication for compiling argp outside of glibc
Copyright (C) 1997-2023 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <[email protected]>.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */

#if !_LIBC
/* This code is written for inclusion in gnu-libc, and uses names in the
namespace reserved for libc. If we're not compiling in libc, define those
names to be the normal ones instead. */

/* argp-parse functions */
#undef __argp_parse
#define __argp_parse argp_parse
#undef __option_is_end
#define __option_is_end _option_is_end
#undef __option_is_short
#define __option_is_short _option_is_short
#undef __argp_input
#define __argp_input _argp_input

/* argp-help functions */
#undef __argp_help
#define __argp_help argp_help
#undef __argp_error
#define __argp_error argp_error
#undef __argp_failure
#define __argp_failure argp_failure
#undef __argp_state_help
#define __argp_state_help argp_state_help
#undef __argp_usage
#define __argp_usage argp_usage

/* argp-fmtstream functions */
#undef __argp_make_fmtstream
#define __argp_make_fmtstream argp_make_fmtstream
#undef __argp_fmtstream_free
#define __argp_fmtstream_free argp_fmtstream_free
#undef __argp_fmtstream_putc
#define __argp_fmtstream_putc argp_fmtstream_putc
#undef __argp_fmtstream_puts
#define __argp_fmtstream_puts argp_fmtstream_puts
#undef __argp_fmtstream_write
#define __argp_fmtstream_write argp_fmtstream_write
#undef __argp_fmtstream_printf
#define __argp_fmtstream_printf argp_fmtstream_printf
#undef __argp_fmtstream_set_lmargin
#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
#undef __argp_fmtstream_set_rmargin
#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
#undef __argp_fmtstream_set_wmargin
#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
#undef __argp_fmtstream_point
#define __argp_fmtstream_point argp_fmtstream_point
#undef __argp_fmtstream_update
#define __argp_fmtstream_update _argp_fmtstream_update
#undef __argp_fmtstream_ensure
#define __argp_fmtstream_ensure _argp_fmtstream_ensure
#undef __argp_fmtstream_lmargin
#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
#undef __argp_fmtstream_rmargin
#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
#undef __argp_fmtstream_wmargin
#define __argp_fmtstream_wmargin argp_fmtstream_wmargin

/* normal libc functions we call */
#undef __flockfile
#define __flockfile flockfile
#undef __funlockfile
#define __funlockfile funlockfile
#undef __mempcpy
#define __mempcpy mempcpy
#undef __sleep
#define __sleep sleep
#undef __strcasecmp
#define __strcasecmp strcasecmp
#undef __strchrnul
#define __strchrnul strchrnul
#undef __strerror_r
#define __strerror_r strerror_r
#undef __strndup
#define __strndup strndup

#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
# define clearerr_unlocked(x) clearerr (x)
#endif
#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
# define feof_unlocked(x) feof (x)
# endif
#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
# define ferror_unlocked(x) ferror (x)
# endif
#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
# define fflush_unlocked(x) fflush (x)
# endif
#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
# define fgets_unlocked(x,y,z) fgets (x,y,z)
# endif
#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED
# define fputc_unlocked(x,y) fputc (x,y)
# endif
#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
# define fputs_unlocked(x,y) fputs (x,y)
# endif
#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
# endif
#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
# endif
#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED
# define getc_unlocked(x) getc (x)
# endif
#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED
# define getchar_unlocked() getchar ()
# endif
#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED
# define putc_unlocked(x,y) putc (x,y)
# endif
#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED
# define putchar_unlocked(x) putchar (x)
# endif

extern char *__argp_basename (char *name);

#endif /* !_LIBC */

#ifndef __set_errno
#define __set_errno(e) (errno = (e))
#endif

#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
# define __argp_short_program_name() (program_invocation_short_name)
#else
extern char *__argp_short_program_name (void);
#endif
Loading
Loading