Giter Site home page Giter Site logo

mixed-precision's Introduction

Mixed Precision Proof-of-Concept

The repo contains a proof-of-concept of one way of setting up "mixed precision" support in a library.

Motivation

  • Allow for the compile-time configuration of the precision used by the library (i.e. build everything either in double precision or in single precision).
    • If the library is re-configured with a different precision, applications will use the newly configured precision without changing their code.
  • Allow the same application to mix double-precision and single-precision computations.
    • For example, operator evaluation can be performed in double precision and the preconditioner can be applied in single precision.
  • If mixed precision support is not desired or needed, then there is no extra compile time (the library can be compiled for only one precision if wanted).
  • Minimal changes to the existing library (i.e. not everything needs to be templated).
  • Backwards compatible: all existing applications should continue to compile/work with no changes.

How it Works

The makefile will build a library (libexample.a) and an executable linking against the library (main).

There are two configuration options available in the makefile:

  • ENABLED_PRECISIONS contains a list of enabled precicisions (i.e. one or both of FP64 and FP32)
  • DEFAULT_PRECISION defines the default precision, and must be one of the precisions listed in ENABLED_PRECISIONS.

If FP64 is enabled, the double-precision API will be made available in the mp::fp64 namespace. Likewise, if FP32 is enabled, the single-precision API will be made available in the mp::fp32 namespace. If both are enabled, then both mp::fp64 and mp::32 namespaces will be available, and the library will have both versions compiled.

Depending on DEFAULT_PRECISION, all the names from either mp::64 or mp::32 will be injected into the mp namespace with a using directive. This allows users to access e.g. mp::Vector without specifiying the desired precision—the configured DEFAULT_PRECISION will be used in this case.

Running the main executable will print out the element type (either double or float) used for three vectors:

mp::Vector v1(10);
mp::fp64::Vector v2(10);
mp::fp32::Vector v3(10);

The vector v1 will have element type defined by DEFAULT_PRECISION. Vectors v2 and v3 will ahve element types double and float, respectively.

The expected output (with DEFAULT_PRECISION = FP64) is:

The vector v1 has elements of type: double
The vector v2 has elements of type: double
The vector v3 has elements of type: float

Removing one of FP64 or FP32 from the ENABLED_PRECISIONS list will result in a compile-time error (unless the corresponding v2 or v3 is deleted from main.cpp).

mixed-precision's People

Contributors

pazner avatar

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.