Computing just right: Application-specific arithmetic x x 2+ y 2+ z - - PowerPoint PPT Presentation

computing just right application specific arithmetic
SMART_READER_LITE
LIVE PREVIEW

Computing just right: Application-specific arithmetic x x 2+ y 2+ z - - PowerPoint PPT Presentation

Computing just right: Application-specific arithmetic x x 2+ y 2+ z 2 x log x s i x i n e x n e x + i =0 Florent de Dinechin y Outline Anti-introduction: the arithmetic you want in a processor Operator parameterization


slide-1
SLIDE 1

Computing just right: Application-specific arithmetic

Florent de Dinechin

e

x

x2+y2+z2

πx

s i n

e

x+ y n

  • i=0

xi

√x

logx

slide-2
SLIDE 2

Outline

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 2

slide-3
SLIDE 3

Anti-introduction: the arithmetic you want in a processor

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 3

slide-4
SLIDE 4

Processors are general-purpose

(more or less – Intel and ARM more, GPUs less) The good arithmetic in a processor is the most generally useful: additions, multiplications, and then? Should a processor include a divider and square root? Should a processor include elementary functions (exp, log sine/cosine) Should a processor include decimal hardware? ...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 4

slide-5
SLIDE 5

Should a processor include a divider? (1)

How do you divide X by D?

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 5

slide-6
SLIDE 6

Should a processor include a divider? (1)

How do you divide X by D? As in decimal, but simpler:

The iteration of the paper-and-pencil algorithm

find the next quotient digit binary: it can be 0 or 1, so try 1 multiply this digit by the dividend this one is easy subtract from the divisor

  • ne subtraction here

if the result is negative,

the quotient digit should have been zero, therefore we should have subtracted 0, it will be easy to fix.

start again, one digit to the right Very light iteration (one subtraction and one test), but each iteration provides only one bit of the quotient: (more than) 53 cycles for double-precision floating-point.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 5

slide-7
SLIDE 7

Should a processor include a divider? (2)

Answer in 1993 is : YES (Oberman & Flynn, 1993)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 6

slide-8
SLIDE 8

Should a processor include a divider? (2)

Answer in 1993 is : YES (Oberman & Flynn, 1993) And this divider should be a fast one, because of Amdahl law. Although division is not frequent, (...) a high latency divider can contribute an additional 0.50 CPI to a system executing SPECfp92

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 6

slide-9
SLIDE 9

Should a processor include a divider? (2)

Answer in 1993 is : YES (Oberman & Flynn, 1993) And this divider should be a fast one, because of Amdahl law. Although division is not frequent, (...) a high latency divider can contribute an additional 0.50 CPI to a system executing SPECfp92

Digit recurrence algorithms

Generalizations of the paper-and-pencil algorithm large radix: from 23 to 26 fancy internal number systems to speedup

digit-by-number product subtraction finding the next quotient digit

Heavier iterations, giving one digit (2 to 5 bits) per iteration.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 6

slide-10
SLIDE 10

Should a processor include a divider? (2)

Answer in 1993 is : YES (Oberman & Flynn, 1993) And this divider should be a fast one, because of Amdahl law. Although division is not frequent, (...) a high latency divider can contribute an additional 0.50 CPI to a system executing SPECfp92

Digit recurrence algorithms

Generalizations of the paper-and-pencil algorithm large radix: from 23 to 26 fancy internal number systems to speedup

digit-by-number product subtraction finding the next quotient digit

Heavier iterations, giving one digit (2 to 5 bits) per iteration. A lot of research, worth one full book (Ercegovac and Lang, 1994)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 6

slide-11
SLIDE 11

Should a processor include a divider? (3)

Answer in 2000 is : NO (Markstein)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 7

slide-12
SLIDE 12

Should a processor include a divider? (3)

Answer in 2000 is : NO (Markstein) The Itanium: a brand new processor without a divide instruction. Instead of a hardware divider, a second FMA (fused multiply and add) is more generally useful

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 7

slide-13
SLIDE 13

Should a processor include a divider? (3)

Answer in 2000 is : NO (Markstein) The Itanium: a brand new processor without a divide instruction. Instead of a hardware divider, a second FMA (fused multiply and add) is more generally useful and can even be used to compute divisions.

Multiplicative division algorithms

Executive summary: approximate 1/D Various iterations involving 2 multiplications

Newton-Raphson, Goldschmidt, ... Polynomial approximation (Taylor-like), ...

Each iteration doubles the number of correct quotient digits Heavy iterations, but few of them, and all the freedom of software. ... and two more books.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 7

slide-14
SLIDE 14

Should a processor include a divider? (4)

Answer in 2018 is : YES again (Bruguera, Arith 2018)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 8

slide-15
SLIDE 15

Should a processor include a divider? (4)

Answer in 2018 is : YES again (Bruguera, Arith 2018) Bruguera designs floating-point units for ARM (low-power processors)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 8

slide-16
SLIDE 16

Should a processor include a divider? (4)

Answer in 2018 is : YES again (Bruguera, Arith 2018) Bruguera designs floating-point units for ARM (low-power processors) Their current divisor is the most expensive you could think of Digit-recurrence, but 6 quotients bits per iteration 11 cycles for double precision (better than intel, IBM, ...)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 8

slide-17
SLIDE 17

Should a processor include a divider? (4)

Answer in 2018 is : YES again (Bruguera, Arith 2018) Bruguera designs floating-point units for ARM (low-power processors) Their current divisor is the most expensive you could think of Digit-recurrence, but 6 quotients bits per iteration 11 cycles for double precision (better than intel, IBM, ...) Achieved thanks to a totally redneck implementation speculation all over the place prescaling and other tricks iteration hardware: 20 fast 58-bit adders, 12 58-bit muxes, and more...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 8

slide-18
SLIDE 18

Should a processor include a divider? (4)

Answer in 2018 is : YES again (Bruguera, Arith 2018) Bruguera designs floating-point units for ARM (low-power processors) Their current divisor is the most expensive you could think of Digit-recurrence, but 6 quotients bits per iteration 11 cycles for double precision (better than intel, IBM, ...) Achieved thanks to a totally redneck implementation speculation all over the place prescaling and other tricks iteration hardware: 20 fast 58-bit adders, 12 58-bit muxes, and more... We do this to reduce overal energy consumption! There is this huge superscalar ARM core that consumes a lot, we save energy if we can switch it off a few cycles earlier

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 8

slide-19
SLIDE 19

A good example of dark silicon made useful

Dark silicon?

In current tech, you can no longer use 100% of the transistors 100% of the time without destroying your chip. “Dark silicon” is the percentage that must be off at a given time (picture from a 2013 HiPEAC keynote by Doug Burger)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 9

slide-20
SLIDE 20

Pleasant times to be an architect

One way out the dark silicon apocalypse (M.B. Taylor, 2012)

Hardware implementations of rare (but useful) operations: when used, dramatically reduce the energy per operation (compared to a software implementation that would take many more cycles) when unused, serve as radiator for the used parts

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 10

slide-21
SLIDE 21

Should a processor include elementary functions? (1)

Dura Amdahl lex, sed lex

SPICE Model-Evaluation, cut from Kapre and DeHon (FPL 2009)

Current performance of exp or log is 10 to 100 cycles, to compare with 1 to 5 cycles for add and mult.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 11

slide-22
SLIDE 22

Should a processor include elementary functions? (2)

Answer in 1976 is YES (Paul&Wilson)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 12

slide-23
SLIDE 23

Should a processor include elementary functions? (2)

Answer in 1976 is YES (Paul&Wilson) ... and the initial x87 floating-point coprocessor was designed with a basic set of elementary functions implemented in microcode with some hardware assistance, in particular the 80-bit extended format.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 12

slide-24
SLIDE 24

Should a processor include elementary functions? (3)

Answer in 1991 is NO (Tang)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 13

slide-25
SLIDE 25

Should a processor include elementary functions? (3)

Answer in 1991 is NO (Tang)

Table-based algorithms

Moore’s Law means cheap memory Fast algorithms thanks to huge (tens of Kbytes!) tables of pre-computed values Software beats micro-code, which cannot afford such tables

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 13

slide-26
SLIDE 26

Should a processor include elementary functions? (3)

Answer in 1991 is NO (Tang)

Table-based algorithms

Moore’s Law means cheap memory Fast algorithms thanks to huge (tens of Kbytes!) tables of pre-computed values Software beats micro-code, which cannot afford such tables None of the RISC processors designed in this period even considers elementary functions support

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 13

slide-27
SLIDE 27

Should a processor include elementary functions? (4)

Answer in 2018 is... maybe?

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 14

slide-28
SLIDE 28

Should a processor include elementary functions? (4)

Answer in 2018 is... maybe? A few low-precision hardware functions in NVidia GPUs (Oberman & Siu 2005) The SpiNNaker-2 chip includes hardware exp and log (Mikaitis et al. 2018) Intel AVX-512 includes all sort of fancy floating-point instructions to speed up elementary function evaluation (Anderson et al. 2018)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 14

slide-29
SLIDE 29

I won’t answer the other questions here

... because we are working on them Should a processor include a divider and square root? Should a processor include elementary functions (exp, log sine/cosine) Should a processor include decimal hardware? ...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 15

slide-30
SLIDE 30

At this point of the talk...

... everybody is wondering when I start talking about FPGAs.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 16

slide-31
SLIDE 31

One nice thing with FPGAs

... is that there is an easy answer to all these questions divider? square root? Yes iff your application needs it elementary functions? Yes iff your application needs it decimal hardware? Yes iff your application needs it

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 17

slide-32
SLIDE 32

One nice thing with FPGAs

... is that there is an easy answer to all these questions divider? square root? Yes iff your application needs it elementary functions? Yes iff your application needs it decimal hardware? Yes iff your application needs it multiplier by log(2)? By sin 17π

256 ?

Yes iff your application needs it

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 17

slide-33
SLIDE 33

One nice thing with FPGAs

... is that there is an easy answer to all these questions divider? square root? Yes iff your application needs it elementary functions? Yes iff your application needs it decimal hardware? Yes iff your application needs it multiplier by log(2)? By sin 17π

256 ?

Yes iff your application needs it

there probably never will be an instruction “multiply by log(2)” in a general purpose processor.

... In FPGAs, useful means: useful to one application.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 17

slide-34
SLIDE 34

In an FPGA, you pay only for what you need

If your application is to simulate jfet, ... you want to build a floating-point unit with 13 adds, 31 mults, 2 divs, 2 exps, and nothing more.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 18

slide-35
SLIDE 35

Conclusion so far: FPGA arithmetic is ...

... all sorts of operators that just wouldn’t make sense in a processor.

4 recipes to exploit the flexibility of FPGAs

  • perator parameterization
  • perator specialization
  • perator fusion

tabulation of precomputed values

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 19

slide-36
SLIDE 36

Conclusion so far: FPGA arithmetic is ...

... all sorts of operators that just wouldn’t make sense in a processor.

4 recipes to exploit the flexibility of FPGAs

  • perator parameterization
  • perator specialization
  • perator fusion

tabulation of precomputed values (I hesitated to add a fifth: fancy number systems)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 19

slide-37
SLIDE 37

Operator parameterization

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 20

slide-38
SLIDE 38

Example: an architecture for floating-point exponential

Shift to fixed−point normalize / round Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

1 + wF + g wF + g − k wF + g + 2 − k MSB wF + g + 2 − k wF + g + 1 − k MSB wF + g + 1 − 2k 1 + wF + g wE + wF + g + 1 wE + 1 wE + wF + g + 1 wE + wF + g + 1 k

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 21

slide-39
SLIDE 39

Don’t move useless bits around!

In software, you have to make dramatic choices between a few integer formats and a few floating-point ones.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 22

slide-40
SLIDE 40

Don’t move useless bits around!

In software, you have to make dramatic choices between a few integer formats and a few floating-point ones. When designing for FPGAs, bit-level freedom!

in this exponential, some signals are 12 bits, some 69 bits.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 22

slide-41
SLIDE 41

Don’t move useless bits around!

In software, you have to make dramatic choices between a few integer formats and a few floating-point ones. When designing for FPGAs, bit-level freedom!

in this exponential, some signals are 12 bits, some 69 bits.

Overwhelming freedom! Too many parameters!

Fortunately, we have constraints: Computing just right: a high-level constraint of overal accuracy (to be defined).

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 22

slide-42
SLIDE 42

Don’t move useless bits around!

In software, you have to make dramatic choices between a few integer formats and a few floating-point ones. When designing for FPGAs, bit-level freedom!

in this exponential, some signals are 12 bits, some 69 bits.

Overwhelming freedom! Too many parameters!

Fortunately, we have constraints: Computing just right: a high-level constraint of overal accuracy (to be defined). A few resource/performance constraints:

dimensions of DSP and RAM blocks LUT cluster size, ...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 22

slide-43
SLIDE 43

Don’t move useless bits around!

In software, you have to make dramatic choices between a few integer formats and a few floating-point ones. When designing for FPGAs, bit-level freedom!

in this exponential, some signals are 12 bits, some 69 bits.

Overwhelming freedom! Too many parameters!

Fortunately, we have constraints: Computing just right: a high-level constraint of overal accuracy (to be defined). A few resource/performance constraints:

dimensions of DSP and RAM blocks LUT cluster size, ...

... to guide you when navigating the implementation space

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 22

slide-44
SLIDE 44

Example: single precision exponential

Shift to fixed−point normalize / round Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

1 + wF + g wF + g − k wF + g + 2 − k MSB wF + g + 2 − k wF + g + 1 − k MSB wF + g + 1 − 2k 1 + wF + g wE + wF + g + 1 wE + 1 wE + wF + g + 1 wE + wF + g + 1 k

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 23

slide-45
SLIDE 45

Example: single precision exponential

Shift to fixed−point normalize / round

27 17 9 9 17 9

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 23

slide-46
SLIDE 46

Example: single precision exponential

Shift to fixed−point normalize / round

27 17 9 9 17 9 18 Kbit ROM (dual−port) DSP

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 23

slide-47
SLIDE 47

Example: single precision exponential

Shift to fixed−point normalize / round

27 17 9 9 17 9 18 Kbit ROM (dual−port) DSP

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

Virtex-4 consumption

1 BlockRAM, 1 DSP, and <400 slices

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 23

slide-48
SLIDE 48

Adapting to the performance context

1 + wF 1 + wF 1 + wF 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g wE + wF + g 2 + wF + g

EC EB MB2 MC 2 X Y Z MX EZ EY EX MY MZ MA2 R

4 + wF + g

shifter sort sort squarer squarer shifter squarer add normalize/pack unpack

One operator does not fit all

Low frequency, low resource consumption

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 24

slide-49
SLIDE 49

Adapting to the performance context

1 + wF 1 + wF 1 + wF 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g wE + wF + g 2 + wF + g

EC EB MB2 MC 2 X Y Z MX EZ EY EX MY MZ MA2 R

4 + wF + g

shifter sort sort squarer squarer shifter squarer add normalize/pack unpack

One operator does not fit all

Low frequency, low resource consumption Faster but larger (more registers)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 24

slide-50
SLIDE 50

Adapting to the performance context

1 + wF 1 + wF 1 + wF 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g wE + wF + g 2 + wF + g

EC EB MB2 MC 2 X Y Z MX EZ EY EX MY MZ MA2 R

4 + wF + g

shifter sort sort squarer squarer shifter squarer add normalize/pack unpack

One operator does not fit all

Low frequency, low resource consumption Faster but larger (more registers) Combinatorial

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 24

slide-51
SLIDE 51

Frequency-directed pipelining

The good interface to pipeline construction

“Please pipeline this operator to work at 200MHz”

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 25

slide-52
SLIDE 52

Frequency-directed pipelining

The good interface to pipeline construction

“Please pipeline this operator to work at 200MHz” Not the choice made by the early core generators of FPGA vendors ...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 25

slide-53
SLIDE 53

Frequency-directed pipelining

The good interface to pipeline construction

“Please pipeline this operator to work at 200MHz” Not the choice made by the early core generators of FPGA vendors ...

Better because compositional

When you assemble components working at frequency f , you obtain a component working at frequency f .

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 25

slide-54
SLIDE 54

Conclusion about operator parameterization

Designing heavily parameterized operators is a lot more work,

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 26

slide-55
SLIDE 55

Conclusion about operator parameterization

Designing heavily parameterized operators is a lot more work, but it is the easy part Chosing the value of the parameters is the difficult part

Error analysis needed ... context-specific implicit knowledge

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 26

slide-56
SLIDE 56

Conclusion about operator parameterization

Designing heavily parameterized operators is a lot more work, but it is the easy part Chosing the value of the parameters is the difficult part

Error analysis needed ... context-specific implicit knowledge

Parameterization is useful

at the application level, but also when designing compound components.

Shift to fixed−point normalize / round Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

1 + wF + g wF + g − k wF + g + 2 − k MSB wF + g + 2 − k wF + g + 1 − k MSB wF + g + 1 − 2k 1 + wF + g wE + wF + g + 1 wE + 1 wE + wF + g + 1 wE + wF + g + 1 k

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 26

slide-57
SLIDE 57

Conclusion about operator parameterization

Designing heavily parameterized operators is a lot more work, but it is the easy part Chosing the value of the parameters is the difficult part

Error analysis needed ... context-specific implicit knowledge

Parameterization is useful

at the application level, but also when designing compound components.

Fancy situations will occur

example: the multiplier by log(2):

◮ small input (12 bits for FP64) ◮ large output (69 bits for FP64)

Shift to fixed−point normalize / round Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

1 + wF + g wF + g − k wF + g + 2 − k MSB wF + g + 2 − k wF + g + 1 − k MSB wF + g + 1 − 2k 1 + wF + g wE + wF + g + 1 wE + 1 wE + wF + g + 1 wE + wF + g + 1 k

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 26

slide-58
SLIDE 58

Operator specialization

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 27

slide-59
SLIDE 59

Specializing an operator to its context

First idea: design a specific architecture when one input is constant multiplier by a constant more efficient than inputting the constant to a standard multiplier

xxxxx × 11001 xxxxx 00000 00000 xxxxx xxxxx .yyyyyyyyyy

xxxxx × 11001 xxxxx xxxxx xxxxx .yyyyyyyyyy

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 28

slide-60
SLIDE 60

Specializing an operator to its context

First idea: design a specific architecture when one input is constant multiplier by a constant more efficient than inputting the constant to a standard multiplier

xxxxx × 11001 xxxxx 00000 00000 xxxxx xxxxx .yyyyyyyyyy

xxxxx × 11001 xxxxx xxxxx xxxxx .yyyyyyyyyy

two competitive well-researched techniques, tens of publications (well beyond what synthesis tools would optimize out – details later)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 28

slide-61
SLIDE 61

Specializing an operator to its context

First idea: design a specific architecture when one input is constant multiplier by a constant more efficient than inputting the constant to a standard multiplier

xxxxx × 11001 xxxxx 00000 00000 xxxxx xxxxx .yyyyyyyyyy

xxxxx × 11001 xxxxx xxxxx xxxxx .yyyyyyyyyy

two competitive well-researched techniques, tens of publications (well beyond what synthesis tools would optimize out – details later)

divider by 3 much more efficient than inputting 3 to a standard divider

and even more efficient than multiplying by 1/3 (technique shown later) Here, we use a completely different algorithm

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 28

slide-62
SLIDE 62

Specializing an operator to its context

First idea: design a specific architecture when one input is constant multiplier by a constant more efficient than inputting the constant to a standard multiplier

xxxxx × 11001 xxxxx 00000 00000 xxxxx xxxxx .yyyyyyyyyy

xxxxx × 11001 xxxxx xxxxx xxxxx .yyyyyyyyyy

two competitive well-researched techniques, tens of publications (well beyond what synthesis tools would optimize out – details later)

divider by 3 much more efficient than inputting 3 to a standard divider

and even more efficient than multiplying by 1/3 (technique shown later) Here, we use a completely different algorithm

(addition of a constant doesn’t save much on an FPGA in general)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 28

slide-63
SLIDE 63

Specializing an operator to its context

Second idea: shared inputs squarer more efficient than multiplier

each digit-by digit product is computed twice in a squarer 2321 × 2321 2321 4642 6963 4642 5387041

2321 × 2321 2321 464 69 4 5387041

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 29

slide-64
SLIDE 64

Specializing an operator to its context

Second idea: shared inputs squarer more efficient than multiplier

each digit-by digit product is computed twice in a squarer 2321 × 2321 2321 4642 6963 4642 5387041

2321 × 2321 2321 464 69 4 5387041

Same idea works for x3, etc ...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 29

slide-65
SLIDE 65

More subtle operator specialization (1)

truncated multiplier in fixed point

.10101 × .11001 10101 00000 00000 10101 10101 .0100001101 .01000 rounded to

.10101 × .11001 10101 00000 00000 10101 101011 .0100001 .01000 rounded to

same accuracy with truncated(n+1) as with standard(n) almost half the cost

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 30

slide-66
SLIDE 66

More subtle operator specialization (2)

Floating-point addition of two numbers of the same sign

This happens in sum of squares, etc – or when physics tells you!

  • ne leading-zero counter and one shifter can be saved:

λ

LZC/shift

p + 1 p + 1 p + 1 p + 1 2p + 2 p p p + 1 p

x y z

  • exp. difference / swap

rounding,normalization and exception handling

mx ex +/– c/f ex − ey

close path

c/f ex ez my

shift |mx − my|

my 1-bit shift ex ez mx

far path

mz, r mz, r

sticky

s g r

prenorm (2-bit shift)

s

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 31

slide-67
SLIDE 67

More subtle operator specialization (3)

Fixed-point large accumulator of floating-point values

... when the physics tells you so (to be detailed later)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 32

slide-68
SLIDE 68

More subtle operator specialization (3)

Fixed-point large accumulator of floating-point values

... when the physics tells you so (to be detailed later)

Elementary functions that work only on a smaller range

... when the physics tells you so

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 32

slide-69
SLIDE 69

More subtle operator specialization (3)

Fixed-point large accumulator of floating-point values

... when the physics tells you so (to be detailed later)

Elementary functions that work only on a smaller range

... when the physics tells you so

...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 32

slide-70
SLIDE 70

Conclusion on operator specialization

Look at your equations, they are full of operations waiting to be specialized

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 33

slide-71
SLIDE 71

Operator fusion

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 34

slide-72
SLIDE 72

x

  • x2 + y 2 really more complex than x/y ?

From the hardware point of view: same black box From the mathematical point of view: both are algebraic functions

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 35

slide-73
SLIDE 73

A simpler example: floating-point sum of squares

x2 + y2 + z2 (not a toy example but a useful building block)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 36

slide-74
SLIDE 74

A simpler example: floating-point sum of squares

x2 + y2 + z2 (not a toy example but a useful building block) A square is simpler than a multiplication

half the hardware required

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 36

slide-75
SLIDE 75

A simpler example: floating-point sum of squares

x2 + y2 + z2 (not a toy example but a useful building block) A square is simpler than a multiplication

half the hardware required

x2, y2, and z2 are positive:

  • ne half of your FP adder is useless
  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 36

slide-76
SLIDE 76

A simpler example: floating-point sum of squares

x2 + y2 + z2 (not a toy example but a useful building block) A square is simpler than a multiplication

half the hardware required

x2, y2, and z2 are positive:

  • ne half of your FP adder is useless

Accuracy can be improved:

5 rounding errors in the floating-point version (x2 + y 2) + z2 : asymmetrical

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 36

slide-77
SLIDE 77

A simpler example: floating-point sum of squares

x2 + y2 + z2 (not a toy example but a useful building block) A square is simpler than a multiplication

half the hardware required

x2, y2, and z2 are positive:

  • ne half of your FP adder is useless

Accuracy can be improved:

5 rounding errors in the floating-point version (x2 + y 2) + z2 : asymmetrical

Operator fusion

provide the floating-point interface

  • ptimize a fixed-point architecture

ensure a clear accuracy specification

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 36

slide-78
SLIDE 78

A floating-point adder

λ

LZC/shift

p + 1 p + 1 p + 1 p + 1 2p + 2 p p p + 1 p

x y z

  • exp. difference / swap

rounding,normalization and exception handling

mx ex +/– c/f ex − ey

close path

c/f ex ez my

shift |mx − my|

my 1-bit shift ex ez mx

far path

mz, r mz, r

sticky

s g r

prenorm (2-bit shift)

s

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 37

slide-79
SLIDE 79

A floating-point sum-of-product architecture

1 + wF 1 + wF 1 + wF 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g 2 + wF + g wE + wF + g 2 + wF + g

EC EB MB2 MC 2 X Y Z MX EZ EY EX MY MZ MA2 R

4 + wF + g

shifter sort sort squarer squarer shifter squarer add normalize/pack unpack

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 38

slide-80
SLIDE 80

Savings

A few (old) results for floating-point sum-of-squares on Virtex4: (classic: assembly of classical FP adders and multipliers, custom: the architecture on previous slide) Simple Precision area performance LogiCore classic 1282 slices, 20 DSP 43 cycles @ 353 MHz FloPoCo classic 1188 slices, 12 DSP 29 cycles @ 289 MHz FloPoCo custom 453 slices, 9 DSP 11 cycles @ 368 MHz Double Precision area performance FloPoCo classic 4480 slices, 27 DSP 46 cycles @ 276 MHz FloPoCo custom 1845 slices, 18 DSP 16 cycles @ 362 MHz all performance metrics improved, FLOP/s/area more than doubled Plus: custom operator more accurate, and symmetrical

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 39

slide-81
SLIDE 81

Second fusion example: the floating-point exponential

Everybody knows FPGAs are bad at floating-point

Versus the highly optimized FPU in a processor, basic operations (+, −, ×) are 10x slower in an FPGA This is the inavoidable overhead of programmability.

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 40

slide-82
SLIDE 82

Second fusion example: the floating-point exponential

Everybody knows FPGAs are bad at floating-point

Versus the highly optimized FPU in a processor, basic operations (+, −, ×) are 10x slower in an FPGA This is the inavoidable overhead of programmability.

If you lose according to a metric, change the metric.

Peak figures for double-precision floating-point exponential Software in a PC: 20 cycles / DPExp @ 4GHz: 200 MDPExp/s FPExp in FPGA: 1 DPExp/cycle @ 400MHz: 400 MDPExp/s Chip vs chip: 6 Pentium cores vs 150 FPExp/FPGA Power consumption also better Single precision data even better (Intel MKL vector libm, vs FPExp in FloPoCo version 2.0.0)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 40

slide-83
SLIDE 83

Not all FLOPS are equal

SPICE Model-Evaluation, cut from Kapre and DeHon (FPL 2009)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 41

slide-84
SLIDE 84

Tabulation of pre-computed values

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 42

slide-85
SLIDE 85

We have seen it already

Shift to fixed−point normalize / round

27 17 9 9 17 9 18 Kbit ROM (dual−port) DSP

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 43

slide-86
SLIDE 86

We have seen it already

Shift to fixed−point normalize / round

27 17 9 9 17 9 18 Kbit ROM (dual−port) DSP

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

Other examples: The KCM constant multiplication technique

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 43

slide-87
SLIDE 87

We have seen it already

Shift to fixed−point normalize / round

27 17 9 9 17 9 18 Kbit ROM (dual−port) DSP

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

Other examples: The KCM constant multiplication technique The state of the art division by 3

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 43

slide-88
SLIDE 88

We have seen it already

Shift to fixed−point normalize / round

27 17 9 9 17 9 18 Kbit ROM (dual−port) DSP

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

Other examples: The KCM constant multiplication technique The state of the art division by 3 Computing A × B mod N as 1 4((A + B)2 − (A − B)2 mod N where X 2 mod N is tabulated ...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 43

slide-89
SLIDE 89

Conclusion: the FloPoCo project

Anti-introduction: the arithmetic you want in a processor Operator parameterization Operator specialization Operator fusion Tabulation of pre-computed values Conclusion: the FloPoCo project

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 44

slide-90
SLIDE 90

Summing up: not your PC’s exponential

multiplier generic polynomial truncated precomputed ROM Constant multipliers evaluator

Shift to fixed−point normalize / round Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 45

slide-91
SLIDE 91

Summing up: not your PC’s exponential

Never compute 1 bit more accurately than needed! multiplier generic polynomial truncated precomputed ROM Constant multipliers evaluator

Shift to fixed−point normalize / round Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

1 + wF + g wF + g − k wF + g + 2 − k MSB wF + g + 2 − k wF + g + 1 − k MSB wF + g + 1 − 2k 1 + wF + g wE + wF + g + 1 wE + 1 wE + wF + g + 1 wE + wF + g + 1 k

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 45

slide-92
SLIDE 92

Summing up: not your PC’s exponential

Never compute 1 bit more accurately than needed! multiplier generic polynomial truncated precomputed ROM Constant multipliers evaluator

Shift to fixed−point normalize / round

generator Need a

Fixed-point X SX EX FX A Z E E

×1/ log(2) × log(2) eA eZ − Z − 1

Y R

1 + wF + g wF + g − k wF + g + 2 − k MSB wF + g + 2 − k wF + g + 1 − k MSB wF + g + 1 − 2k 1 + wF + g wE + wF + g + 1 wE + 1 wE + wF + g + 1 wE + wF + g + 1 k

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 45

slide-93
SLIDE 93

Hey, but I am a physicist !

... I don’t want to design all these fancy operators !

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 46

slide-94
SLIDE 94

Hey, but I am a physicist !

... I don’t want to design all these fancy operators !

You don’t have to, it is my job

And it is a very comfortable niche An infinite list of operators to keep me busy until retirement small arithmetic objects, relatively technology-independent

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 46

slide-95
SLIDE 95

The FloPoCo project

http://flopoco.gforge.inria.fr/

e

x

x2+y2+z2

πx

s i n

e

x+ y n

  • i=0

xi

√x

logx A generator framework

written in C++, outputting VHDL

  • pen and extensible
  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 47

slide-96
SLIDE 96

The FloPoCo project

http://flopoco.gforge.inria.fr/

e

x

x2+y2+z2

πx

s i n

e

x+ y n

  • i=0

xi

√x

logx A generator framework

written in C++, outputting VHDL

  • pen and extensible

Goal: provide all the application-specific arithmetic operators you want (even if you don’t know yet that you want them)

  • pen-ended list, about 50 in the stable version, and a few others in

“obscure branches” integer, fixed-point, floating-point, logarithm number system all operators fully parameterized flexible pipeline for all operators

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 47

slide-97
SLIDE 97

The FloPoCo project

http://flopoco.gforge.inria.fr/

e

x

x2+y2+z2

πx

s i n

e

x+ y n

  • i=0

xi

√x

logx A generator framework

written in C++, outputting VHDL

  • pen and extensible

Goal: provide all the application-specific arithmetic operators you want (even if you don’t know yet that you want them)

  • pen-ended list, about 50 in the stable version, and a few others in

“obscure branches” integer, fixed-point, floating-point, logarithm number system all operators fully parameterized flexible pipeline for all operators

Approach: computing just right

Interface: never output bits that are not numerically meaningful Inside: never compute bits that are not useful to the final result

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 47

slide-98
SLIDE 98

Where do we stop?

My own personal definition of an arithmetic operator

An arithmetic operation is a function (in the mathematical sense)

few well-typed inputs and outputs no memory or side effect

◮ (even filters are defined by a transfer function)

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 48

slide-99
SLIDE 99

Where do we stop?

My own personal definition of an arithmetic operator

An arithmetic operation is a function (in the mathematical sense)

few well-typed inputs and outputs no memory or side effect

◮ (even filters are defined by a transfer function)

An operator is the implementation of such a function

... mathematically specified in terms of a rounding function e.g. IEEE-754 FP standard: operator(x) = rounding(operation(x))

→ Clean mathematic definition, even for floating-point arithmetic

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 48

slide-100
SLIDE 100

Where do we stop?

My own personal definition of an arithmetic operator

An arithmetic operation is a function (in the mathematical sense)

few well-typed inputs and outputs no memory or side effect

◮ (even filters are defined by a transfer function)

An operator is the implementation of such a function

... mathematically specified in terms of a rounding function e.g. IEEE-754 FP standard: operator(x) = rounding(operation(x))

→ Clean mathematic definition, even for floating-point arithmetic

An operator, as a circuit...

... is a direct acyclic graph (DAG): easy to build and pipeline easy to test against its mathematical specification

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 48

slide-101
SLIDE 101

One small problem

FloPoCo can generate an infinite number of operators, I don’t want to test them all...

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 49

slide-102
SLIDE 102

One small problem

FloPoCo can generate an infinite number of operators, I don’t want to test them all...

Solution

Each operator comes with its testbench generator expected outputs built from the mathematical specification, not by emulating the operator architecture!

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 49

slide-103
SLIDE 103

Here should come a demo

Command line syntax: a sequence of operator specifications Options: target frequency, target hardware, ... Output: synthesizable VHDL. FloPoCo is open-source and freely available from http://flopoco.gforge.inria.fr/

  • F. de Dinechin

FPGAs computing Just Right: Application-specific arithmetic 50