Giter Site home page Giter Site logo

verificarlo / significantdigits Goto Github PK

View Code? Open in Web Editor NEW
3.0 9.0 2.0 75 KB

Solid statistical analysis of Stochastic Arithmetic.

Home Page: https://verificarlo.github.io/significantdigits/

License: Other

Makefile 0.11% Python 84.56% C 13.70% Jinja 1.63%
floating-point ieee754 significant significant-digits stochastic-arithmetic

significantdigits's Introduction

Verificarlo v2.0.0

A tool for debugging and assessing floating point precision and reproducibility.

verificarlo logo

GitHub Release Build Status Docker Pulls DOI Coverity License

Installation

To install Verificarlo please refer to the installation documentation. Verificarlo supports both amd64 and aarch64 architectures.

Using Verificarlo through its Docker image

A docker image is available at https://hub.docker.com/r/verificarlo/verificarlo/. This image uses the latest release version of Verificarlo and includes support for Fortran. It uses llvm-7 and gcc-7.

Example of usage with Monte Carlo arithmetic:

$ cat > test.c <<HERE
#include <stdio.h>
int main() {
  double a = 0;
  for (int i=0; i < 10000; i++) a += 0.1;
  printf("%0.17f\n", a);
  return 0;
}
HERE

$ docker pull verificarlo/verificarlo
$ docker run -v "$PWD":/workdir verificarlo/verificarlo \
   verificarlo-c test.c -o test
$ docker run -v "$PWD":/workdir -e VFC_BACKENDS="libinterflop_mca.so" \
   verificarlo/verificarlo ./test
999.99999999999795364
$ docker run -v "$PWD":/workdir -e VFC_BACKENDS="libinterflop_mca.so" \
   verificarlo/verificarlo ./test
999.99999999999761258

Usage

To automatically instrument a program with Verificarlo you must compile it using the verificarlo --linker=<linker> command, where <linker> depends on the targeted language:

  • verificarlo --linker=clang for C
  • verificarlo --linker=clang++ for C++
  • verificarlo --linker=flang for Fortran

Verificarlo uses the linker clang by default.

You can also use the provided wrappers to call verificarlo with the right linker:

  • verificarlo-c for C
  • verificarlo-c++ for C++
  • verificarlo-f for Fortran

First, make sure that the verificarlo installation directory is in your PATH.

Then you can use the verificarlo-c, verificarlo-f and verificarlo-c++ commands to compile your programs. Either modify your makefile to use verificarlo as the compiler (CC=verificarlo-c, FC=verificarlo-f, and CXX=verificarlo-c++) and linker (LD=verificarlo --linker=<linker>) or use the verificarlo command directly:

   $ verificarlo-c program.c -o ./program

If you are trying to compile a shared library, such as those built by the Cython extension to Python, you can then also set the shared linker environment variable (LDSHARED='verificarlo --linker=<linker> -shared') to enable position-independent linking.

When invoked with the --verbose flag, verificarlo provides a detailed output of the instrumentation process.

It is important to include the necessary link flags if you use extra libraries. For example, you should include -lm if you are linking against the math library.

Branch instrumentation

Verificarlo can instrument floating point comparison operations. By default, comparison operations are not instrumented and default backends do not make use of this feature. If your backend requires instrumenting floating-point comparisons, you must call verificarlo with the --inst-fcmp flag.

FMA instrumentation

Verificarlo can instrument Fused Multiply-Add (FMA) operations. By default, FMA operations are not instrumented and default backends do not make use of this feature. If your backend requires instrumenting FMA operations, you must call verificarlo with the --inst-fma flag.

Cast instrumentation

Verificarlo can also instrument cast operations. By default, cast operations are not instrumented and default backends do not make use of this feature. If your backend requires instrumenting cast operations, you must call verificarlo with the --inst-cast flag.

Examples and Tutorial

The tests/ directory contains various examples of Verificarlo usage.

A tutorial is available.

Backends

Verificarlo includes different numerical backends. Please refer to the backends' documentation.

Inclusion/exclusion options

To include only certain parts of the code in the analysis or exclude parts of the code from instrumentation please refer to inclusion/exclusion options documentation.

Pinpointing numerical errors with Delta-Debug

To pinpoint numerical errors please refer to the Delta-Debug documentation.

VPREC Function Instrumentation

A function instrumentation pass enables VPREC exploration and optimization at the function granularity level. Please refer to the VPREC Function Instrumentation documentation.

Postprocessing

Verificarlo includes a set of postprocessing tools to help analyze Verificarlo results and produce high-level reports.

Interflop user call instrumentation

Verificarlo provides the ability to call low-level backend functions directly through the interflop_call function. Please refer to the Interflop user call instrumentation documentation.

How to cite Verificarlo

If you use Verificarlo in your research, please cite one of the following papers:

Thanks! ✨

Discussion Group

For questions, feedback, or discussions about Verificarlo, you can use the Discussions section on our GitHub project page.

License

This file is part of the Verificarlo project,
under the Apache License v2.0 with LLVM Exceptions.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
See https://llvm.org/LICENSE.txt for license information.

Copyright (c) 2019-2024 Verificarlo Contributors

Copyright (c) 2018 Universite de Versailles St-Quentin-en-Yvelines

Copyright (c) 2015 Universite de Versailles St-Quentin-en-Yvelines CMLA, Ecole Normale Superieure de Cachan

significantdigits's People

Contributors

purplepachyderm avatar yohanchatelain avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

significantdigits's Issues

Bug with numpy deprecation ?

The latest test run in verificarlo fails with the following message:

 [...]
  File "/usr/local/lib/python3.8/site-packages/verificarlo/ci/test_data_processing.py", line 51, in significant_digits
    s = sd.significant_digits(
  File "/usr/local/lib/python3.8/site-packages/verificarlo/sigdigits.py", line 193, in significant_digits
    sig = significant_digits_general(array=array,
  File "/usr/local/lib/python3.8/site-packages/verificarlo/sigdigits.py", line 157, in significant_digits_general
    pow2minusk = np.power(2, -np.float(k))
  File "/usr/local/lib/python3.8/dist-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
ls: cannot access '*.vfcrun.h5': No such file or directory
Run file not found, FAILURE

It seems the syntax used in sigdigits.py line 157 is deprecated.

Noticed a few issues in sigdigits.py

Hi, I'm @pablooliveira 's intern and I'm currently working at the LI-PaRAD.

I was looking into significantdigits to integrate it in my project, and ran into a few issues with sigdigits.py (all of which I could solve quite easily with small changes to the code) :

  • def change_base(sig, base):
    sig_power2 = np.power(2, -sig)
    to_base = np.frompyfunc(lambda x: math.log(x, base))
    return to_base(sig_power2)

    First of all, I'm guessing the minus sign on line 57 should not be there ? The function would just return the result with the wrong sign here.
    Moreover, it looks like frompyfunc now requires two other arguments (nin and nout) to specify the number of input/output arguments of the resulting function (https://numpy.org/doc/stable/reference/generated/numpy.frompyfunc.html). I assume they were previously optional with a default value of 1, and were made mandatory in a recent update.

  • if precision == Precision.Absolute:
    z = array - reference
    elif precision == Precision.Relative:
    z = array/reference - 1

    I think x and y should be used here, instead of array and reference (since they are previously used to generate x and y). For instance, if reference is None, this would result in an error.

  • z_mask = np.ma.masked_array(_z, axis=0, fill_value=k)

    Here the axis argument is not recognized, nor is it referenced in NumPy's documentation (https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#the-maskedarray-class). Once again, this probably has something to do with it being removed in an update.

As I previously wrote, these errors were easy to fix with only minor changes to the code: if you're interested, I can open a PR with my fixes. I would also be pleased to discuss these errors if you want to.

Thanks for your attention,
Aurélien Delval

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.