IWES 2018 Towards Efficient and Effective Fixed Point Support - - PowerPoint PPT Presentation

iwes 2018
SMART_READER_LITE
LIVE PREVIEW

IWES 2018 Towards Efficient and Effective Fixed Point Support - - PowerPoint PPT Presentation

IWES 2018 Towards Efficient and Effective Fixed Point Support Stefano Cherubin, Giovanni Agosta <name>.<surname>@{polimi.it} Politecnico di Milano 14 September 2018 Cherubin, Agosta Fixed Point Support IWES 2018, Siena 1


slide-1
SLIDE 1

IWES 2018

Towards Efficient and Effective Fixed Point Support Stefano Cherubin, Giovanni Agosta <name>.<surname>@{polimi.it}

Politecnico di Milano

14 September 2018

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 1

slide-2
SLIDE 2

Section 1

1 Introduction 2 Manual Conversion 3 Abstract Data Type 4 Source-to-Source Compilers 5 Compiler Transformation 6 Conclusions

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 2

slide-3
SLIDE 3

Motivation

Precision Tuning

Classic technique in Embedded Systems: Trade-off computation accuracy for performance/energy Usually exploited among available floating point representations 32 bit | 64 bit | 128 bit What if we want to use less bits? specialized hardware use integer data types

FIXED POINT representations

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 3

slide-4
SLIDE 4

Motivation

Precision Tuning

Classic technique in Embedded Systems: Trade-off computation accuracy for performance/energy Usually exploited among available floating point representations 32 bit | 64 bit | 128 bit What if we want to use less bits? specialized hardware use integer data types

FIXED POINT representations

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 3

slide-5
SLIDE 5

Fixed Point Representations

Usually exploited when floating point unit is not available. Programmable hardware can implement fixed point computation using custom width. We consider the general case of x86-like architecture. Keep fixed representation width (8, 16, 32, 64 bits) +-+-----+--------------------------+ |S| INT | FRACTIONAL | +-+-----+--------------------------+

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 4

slide-6
SLIDE 6

Coding in Fixed Point

The Embedded C language allows programmers to use native fixed point data types. What about other programming languages? Let’s take the example of ANSI C, C++ where the only way to represent reals is via floating point? Use native integer data types

HOW?

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 5

slide-7
SLIDE 7

Section 2

1 Introduction 2 Manual Conversion 3 Abstract Data Type 4 Source-to-Source Compilers 5 Compiler Transformation 6 Conclusions

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 6

slide-8
SLIDE 8

Manual Conversion

Time consuming Error prone Unfeasible on large code base

Alternatives?

Several approaches have been proposed. Let’s discuss their benefits and drawbacks by examples.

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 7

slide-9
SLIDE 9

Manual Conversion

Time consuming Error prone Unfeasible on large code base

Alternatives?

Several approaches have been proposed. Let’s discuss their benefits and drawbacks by examples.

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 7

slide-10
SLIDE 10

Section 3

1 Introduction 2 Manual Conversion 3 Abstract Data Type 4 Source-to-Source Compilers 5 Compiler Transformation 6 Conclusions

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 8

slide-11
SLIDE 11

Template-based C++ class

Define a data type to automatize the most common operations ADT provide automatic scaling at every mul/div operation ADT provide conversion between representations ADT provide implicit static cast Programmer does the rest

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 9

slide-12
SLIDE 12

ADT: Pro & Con

PRO

Easy to use: just include an header file Portable

CON

Force code standard change to C++ Data format controlled by the programmer

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 10

slide-13
SLIDE 13

Section 4

1 Introduction 2 Manual Conversion 3 Abstract Data Type 4 Source-to-Source Compilers 5 Compiler Transformation 6 Conclusions

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 11

slide-14
SLIDE 14

S2S Approach

Change the source code to replace the floating point instruction with fixed point equivalents Programmer writes pragmas (or custom language) Tool performs pattern matching & rewrites code Requires custom environment

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 12

slide-15
SLIDE 15

Example: ID.Fix & GeCoS

Programmer annotates ID.Fix1 propagates annotations GeCoS2 source-to-source replaces floating point with fixed point Conversion utils are inserted before/after the given region

1http://idfix.gforge.inria.fr 2http://gecos.gforge.inria.fr Cherubin, Agosta Fixed Point Support IWES 2018, Siena 13

slide-16
SLIDE 16

Annotations

Programmer remarks variables that needs to be converted ID.Fix analysis returns dynamic range for annotated variable(s) #pragma VARIABLE_TRACKING variable for (int i = 0, i < 10, i++) { variable = i; } Output: variable_min = 0 variable_max = 9

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 14

slide-17
SLIDE 17

Annotations

Programmer remarks variables that needs to be converted ID.Fix analysis returns dynamic range for annotated variable(s) #pragma VARIABLE_TRACKING variable for (int i = 0, i < 10, i++) { variable = i; } Output: variable_min = 0 variable_max = 9

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 14

slide-18
SLIDE 18

ID.Fix plugin

Dynamic value range is propagated to all intermediate values For each variable we compute the minimun number of integer bits we need to represent it We leave the rest of the data size for the fractional part Example: variable ∈ [0; 9] = ⇒

  • INTvariable

≥ 4 FRACvariable = 32 − INTvariable +-+----+---------------------------+ |S|INT | FRACTIONAL | +-+----+---------------------------+

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 15

slide-19
SLIDE 19

ID.Fix plugin

Dynamic value range is propagated to all intermediate values For each variable we compute the minimun number of integer bits we need to represent it We leave the rest of the data size for the fractional part Example: variable ∈ [0; 9] = ⇒

  • INTvariable

≥ 4 FRACvariable = 32 − INTvariable +-+----+---------------------------+ |S|INT | FRACTIONAL | +-+----+---------------------------+

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 15

slide-20
SLIDE 20

Source-To-Source

The S2S compiler GeCoS takes the output of ID.Fix and converts the floating point code to fixed point code Uses a C++ template-based fixed point library double m[SIZE1][SIZE2]; FixedPoint<3,29> m_fixp[SIZE1][SIZE2]; convert2DtoFixP<double, SIZE1, SIZE2>(m, m_fixp);

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 16

slide-21
SLIDE 21

GeCoS Infrastructure

ID.Fix is a plugin of the GeCoS source-to-source compiler GeCoS is a plugin of the Eclipse IDE

Requires to work with GUI

Requires JVM

Requires an equation solver Then, the code can be compiled using the system compiler.

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 17

slide-22
SLIDE 22

S2S: Pro & Con

PRO

Dynamically select the data types Fully automated

CON

Source-language dependent Data format decision based on selected input test set Huge dependencies requirements Difficult to maintain

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 18

slide-23
SLIDE 23

Section 5

1 Introduction 2 Manual Conversion 3 Abstract Data Type 4 Source-to-Source Compilers 5 Compiler Transformation 6 Conclusions

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 19

slide-24
SLIDE 24

Compiler Transformation Approach

Perform analysis and code conversion within the compiler Provides the same features of the S2S compiler Static code analysis instead of dynamic profiling

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 20

slide-25
SLIDE 25

Compiler-based Tuning Assistant

Programmer specifies ranges of input values Compiler propagates ranges to intermediate values Compiler statically analyze the code Compiler automatically selects the best data type Compiler performs code conversion Compiler provides optimized code

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 21

slide-26
SLIDE 26

Annotation Example

The no_float and force_no_float annotations indicate which variables have to be converted to fixed point. The conversion propagates to related compu- tations in different ways: force_no_float entails the conversion of the depen- dencies, while no_float propagates only to intermediate values. It is possible to specify the size of the integer and fractional part of the repre- sentation. Variables and computations which are conver- ted to fixed point. Connections between them highlight the ope- rations affected by the conversion. float a __attribute((annotate("force_no_float"))); int b = 98; a = b * 2.0; a += 10.0; float c __attribute((annotate("no_float 12 20"))); c = function1(b) + 3.5; a += c * 2.0;

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 22

slide-27
SLIDE 27

Example: Our Tool Infrastructure

Based on the LLVM compiler toolchain Annotations are natively supported by clang

Applies to a large variety of programming languages

Packaged as self-contained clang plug-in clang can be used instead of the system compiler

  • r can be easily integrated with the target toolchain

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 23

slide-28
SLIDE 28

Component Schema

Annotation propagation Value Range Analysis Data Type Allocation Code Conversion Feedback Estimation Check improvement N Y

0101 1011 0100 0111

reduced precision LLVM bitcode

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 24

slide-29
SLIDE 29

Benefits

Relies only on the well-known LLVM compiler framework Does not require any customization of the compiler Source language agnostic Easy to maintain

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 25

slide-30
SLIDE 30

Success Story

We applied our tool to the Miosix embedded operating system

Hardware Board Support Package Base Kernel Control scheduler EDF scheduler Priority scheduler Synchronizaton Mutex, etc. Console I/O Filesystem Applications Native thread API pthread API C/C++ std library

Convert the Control-Theoretical scheduler from floating point to fixed point. Speedup achieved on real-time benchmarks (scheduling time) Work presented in Euromicro DSD 2018

clang reference clang c++lib clang manual gcc c++lib gcc manual clang pass

version

0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5

speedup

f469 f207 lpc2138 clang reference clang c++lib clang manual gcc c++lib gcc manual clang pass

version

0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5

speedup

f469 f207 lpc2138

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 26

slide-31
SLIDE 31

Section 6

1 Introduction 2 Manual Conversion 3 Abstract Data Type 4 Source-to-Source Compilers 5 Compiler Transformation 6 Conclusions

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 27

slide-32
SLIDE 32

Conclusions

We presented different approaches to perform reduced precision computation with different automation levels

Exploit the domain knowledge of the programmer to perform selective conversion in a given source code

We showed how to exploit fixed point for reduced precision computation in x86-like architectures

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 28

slide-33
SLIDE 33

Conclusions

We presented different approaches to perform reduced precision computation with different automation levels

Exploit the domain knowledge of the programmer to perform selective conversion in a given source code

We showed how to exploit fixed point for reduced precision computation in x86-like architectures

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 28

slide-34
SLIDE 34

Questions?

?

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 29

slide-35
SLIDE 35

End

Thanks for your attention!

Cherubin, Agosta Fixed Point Support IWES 2018, Siena 30