The Basics: Pipelining J. Nelson Amaral University of - - PowerPoint PPT Presentation

the basics pipelining
SMART_READER_LITE
LIVE PREVIEW

The Basics: Pipelining J. Nelson Amaral University of - - PowerPoint PPT Presentation

The Basics: Pipelining J. Nelson Amaral University of Alberta 1 The Pipeline Concept 2 Bauer p. 32 Pipeline Throughput and Latency IF ID EX MEM


slide-1
SLIDE 1

The ¡Basics: ¡Pipelining ¡

  • J. ¡Nelson ¡Amaral ¡

University ¡of ¡Alberta ¡

1 ¡

slide-2
SLIDE 2

The ¡Pipeline ¡Concept ¡

Bauer ¡p. ¡32 ¡

2 ¡

slide-3
SLIDE 3

3 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX MEM WB

5 ns 4 ns 5 ns 10 ns 4 ns

Consider the pipeline above with the indicated

  • delays. We want to know what is the pipeline

throughput and the pipeline latency. Pipeline throughput: instructions completed per second. Pipeline latency: how long does it take to execute a single instruction in the pipeline.

slide-4
SLIDE 4

4 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX MEM WB

5 ns 4 ns 5 ns 10 ns 4 ns

Pipeline throughput: how often is an instruction completed?

T = 1 instr max lat(IF),lat(ID),lat(EX),lat(MEM),lat(WB)

[ ]

= 1 instr max 5ns,4ns,5ns,10ns,4ns

[ ]

= 1 instr 10ns

Pipeline latency: how long does it take to execute an instruction in the pipeline? Is this right?

slide-5
SLIDE 5

5 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX MEM WB

5 ns 4 ns 5 ns 10 ns 4 ns

Simply adding the latencies to compute the pipeline latency, only would work for an isolated instruction

IF MEM ID I1 L(I1) = 28ns EX WB MEM ID IF I2 L(I2) = 33ns EX WB MEM ID IF I3 L(I3) = 38ns EX WB MEM ID IF I4 L(I5) = 43ns EX WB We are in trouble! The latency is not constant. This happens because this is an unbalanced

  • pipeline. The solution is to make every stage

the same length as the longest one.

slide-6
SLIDE 6

6 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX MEM WB

5 ns 4 ns 5 ns 10 ns 4 ns

The slowest pipeline state also limits the latency!!

IF MEM ID I1 L(I1) = L(I2) = L(I3) = L(I4) = 50ns EX WB IF MEM ID I2 L(I2) = 50ns EX WB IF MEM ID EX WB IF MEM ID EX

10 20 30 40 50 60

I3 I4

slide-7
SLIDE 7

7 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX MEM WB

5 ns 4 ns 5 ns 10 ns 4 ns

How long does it take to execute 20000 instructions in this pipeline? (disregard bubbles caused by branches, cache misses, and hazards) How long would it take using the same modules without pipelining? What is the speedup due to pipelining?

slide-8
SLIDE 8

8 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX MEM WB

5 ns 4 ns 5 ns 10 ns 4 ns

The speedup that we got from the pipeline is: How can we improve this pipeline design? We need to reduce the unbalance to increase the clock speed.

slide-9
SLIDE 9

9 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX

MEM1

WB

5 ns 4 ns 5 ns 5 ns 4 ns

Now we have one more pipeline stage. What is the throughput now?

MEM2

5 ns

What is the new latency for a single instruction?

T = 1 instr max lat(IF), lat(ID), lat(EX), lat(MEM1), lat(MEM2), lat(WB)

[ ]

= 1 instr max 5ns, 4ns, 5ns, 5ns, 5ns, 4ns

[ ]

= 1 instr 5ns

slide-10
SLIDE 10

10 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX

MEM1

WB

5 ns 4 ns 5 ns 5 ns 4 ns

MEM2

5 ns

IF

MEM1

ID I1 EX WB

MEM1

IF

MEM1

ID I2 EX WB

MEM1

IF

MEM1

ID I3 EX WB

MEM1

IF

MEM1

ID I4 EX WB

MEM1

IF

MEM1

ID I5 EX WB

MEM1

IF

MEM1

ID I6 EX WB

MEM1

IF

MEM1

ID I7 EX WB

MEM1

slide-11
SLIDE 11

11 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX

MEM1

WB

5 ns 4 ns 5 ns 5 ns 4 ns

MEM2

5 ns

How long does it take to execute 20000 instructions in this pipeline? (disregard bubles caused by branches, cache misses, etc, for now) What is the speedup that we get from pipelining?

slide-12
SLIDE 12

12 ¡

Pipeline ¡Throughput ¡and ¡Latency ¡

IF ID EX

MEM1

WB

5 ns 4 ns 5 ns 5 ns 4 ns

MEM2

5 ns

What have we learned from this example?

  • 1. It is important to balance the delays in the

stages of the pipeline

  • 2. The throughput of a pipeline is 1/max(delay).
  • 3. The latency is N×max(delay), where N is the

number of stages in the pipeline.

slide-13
SLIDE 13

ExecuMon ¡Snapshot ¡

Bauer ¡p. ¡33 ¡

13 ¡

slide-14
SLIDE 14

Pipeline ¡with ¡Control ¡Unit ¡

Bauer ¡p. ¡34 ¡

14 ¡

slide-15
SLIDE 15

Data ¡Hazards ¡and ¡Forwarding ¡

Example ¡1: ¡ i: ¡ ¡ ¡R7 ¡← ¡R12 ¡+ ¡R15 ¡ i+1: ¡ ¡R8 ¡← ¡R7 ¡– ¡R12 ¡ i+2: ¡ ¡R15 ¡← ¡R8 ¡+ ¡R7 ¡

Read-­‑AYer-­‑Write ¡(RAW) ¡ dependencies ¡ (true ¡dependencies) ¡ Write-­‑AYer-­‑Read ¡(WAR) ¡ dependencies ¡ (anM ¡dependencies) ¡ Bauer ¡p. ¡35 ¡

15 ¡

slide-16
SLIDE 16

Data ¡Hazards ¡and ¡Forwarding ¡

v ¡ v ¡ v ¡ Bauer ¡p. ¡36 ¡

16 ¡

slide-17
SLIDE 17

Forwarding ¡

Bauer ¡p. ¡37 ¡

17 ¡

slide-18
SLIDE 18

Load-­‑ALU ¡RAW ¡Dependency ¡

Example ¡2: ¡ i: ¡ ¡ ¡R6 ¡← ¡Mem[R2] ¡ i+1: ¡ ¡R7 ¡← ¡R6 ¡+ ¡R4 ¡

The ¡data ¡from ¡the ¡load ¡is ¡not ¡available ¡unMl ¡the ¡Mem/WB ¡of ¡instrucMon ¡i, ¡ but ¡it ¡is ¡needed ¡at ¡the ¡ID/EX ¡of ¡instrucMon ¡i+1 ¡ Cannot ¡forward ¡ back ¡on ¡Mme! ¡ Bauer ¡p. ¡36 ¡

18 ¡

slide-19
SLIDE 19

Bubble ¡because ¡of ¡load ¡

Bauer ¡p. ¡38 ¡

19 ¡

slide-20
SLIDE 20

Priority ¡on ¡Forwarding ¡

Example: ¡ i: ¡ ¡ ¡R10 ¡← ¡R4 ¡+ ¡R5 ¡ i+1: ¡ ¡R10 ¡← ¡R4 ¡– ¡R10 ¡ i+2: ¡ ¡R8 ¡← ¡R10 ¡+ ¡R7 ¡ The ¡RAW ¡from ¡i+1 ¡to ¡i+2 ¡ must ¡take ¡priority ¡over ¡ ¡ the ¡RAW ¡from ¡i ¡to ¡i+2. ¡

Bauer ¡p. ¡38 ¡

20 ¡

slide-21
SLIDE 21

Forwarding ¡from ¡Mem/WB ¡to ¡Mem ¡

Example: ¡ i: ¡ ¡ ¡R5 ¡← ¡Mem[R6] ¡ i+1: ¡ ¡Mem[R8] ¡← ¡R5 ¡

Bauer ¡p. ¡39 ¡

21 ¡

AYer ¡the ¡load, ¡the ¡contents ¡of ¡the ¡Mem/WB ¡register ¡ must ¡be ¡forwarded ¡to ¡be ¡wrifen ¡to ¡memory ¡(not ¡only ¡ to ¡R5). ¡ ¡

slide-22
SLIDE 22

Pipelining ¡with ¡Forwarding ¡and ¡Stall ¡

Bauer ¡p. ¡38 ¡

22 ¡

slide-23
SLIDE 23

Control ¡Hazards ¡(branches) ¡

Bauer ¡p. ¡40 ¡

23 ¡

slide-24
SLIDE 24

Control ¡Hazards: ¡ExcepMons ¡and ¡ InterrupMons ¡

  • ExcepMons ¡can ¡occur ¡in ¡any ¡stage ¡(except ¡WB) ¡

– IF: ¡page ¡faults ¡ – ID: ¡Illegal ¡opcodes ¡ – EX: ¡arithmeMc ¡excepMons ¡ – Mem: ¡illegal ¡address, ¡page ¡faults ¡

  • InterrupMons: ¡

– I/O ¡terminaMon, ¡Mme-­‑outs ¡ – Power ¡failures ¡

Bauer ¡p. ¡40 ¡

24 ¡

slide-25
SLIDE 25

Handling ¡ExcepMons/InterrupMons ¡

Save ¡the ¡Process ¡State ¡ Schedule ¡Process ¡Restart ¡ Clear ¡ExcepMon ¡CondiMon ¡ Abort ¡Program ¡ “Correct” ¡ ExcepMon ¡ Perform ¡ Unrelated ¡Task ¡

? ¡

Bauer ¡p. ¡41 ¡

25 ¡

slide-26
SLIDE 26

Precise ¡ExcepMons ¡in ¡a ¡Pipeline ¡

  • If ¡an ¡excepMons ¡happens ¡in ¡instrucMon ¡i: ¡
  • InstrucMons ¡i-­‑1, ¡i-­‑2, ¡… ¡complete ¡normally ¡and ¡

contribute ¡to ¡the ¡saved ¡state ¡of ¡the ¡process ¡

  • InstrucMons ¡i, ¡i+1, ¡i+2, ¡… ¡become ¡no-­‑ops ¡
  • AYer ¡the ¡excepMon ¡is ¡handled, ¡execuMon ¡re-­‑starts ¡at ¡

instrucMon ¡i ¡

– The ¡PC ¡saved ¡is ¡the ¡PC ¡of ¡instrucMon ¡i. ¡

Bauer ¡p. ¡41 ¡

26 ¡

i ¡ i-­‑1 ¡ i-­‑2 ¡ i+2 ¡ i+1 ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ Complete ¡normally ¡ no-­‑op ¡ no-­‑op ¡ no-­‑op ¡ no-­‑op ¡ ExcepMon ¡happens ¡here ¡→ ¡ ←ExecuMon ¡re-­‑starts ¡here ¡

slide-27
SLIDE 27

ImplemenMng ¡Precise ¡ExcepMons ¡in ¡ the ¡Pipeline ¡

  • 1. Flag ¡the ¡pipeline ¡register ¡at ¡the ¡right ¡of ¡the ¡

stage ¡where ¡excepMon ¡was ¡detected ¡

– This ¡Flag ¡moves ¡along ¡the ¡pipeline ¡

  • 2. Set ¡all ¡control ¡lines ¡at ¡a ¡stage ¡with ¡the ¡flag ¡to ¡

transform ¡the ¡instrucMon ¡into ¡a ¡no-­‑op ¡

  • 3. Stop ¡instrucMon ¡fetching ¡
  • 4. When ¡the ¡flag ¡reaches ¡the ¡Mem/WB ¡stage, ¡

save ¡the ¡PC ¡of ¡that ¡instrucMon ¡as ¡the ¡ excep0on ¡PC ¡ ¡

Bauer ¡p. ¡41 ¡

27 ¡

slide-28
SLIDE 28

Program ¡Order ¡X ¡Temporal ¡Order ¡

divide-­‑by-­‑zero ¡excepMon ¡ page-­‑fault ¡excepMon ¡ Which ¡excepMon ¡occurs ¡first ¡in ¡Mme? ¡ Which ¡excepMon ¡should ¡be ¡handled ¡first? ¡ Bauer ¡p. ¡41 ¡

28 ¡

slide-29
SLIDE 29

Bauer ¡p. ¡38 ¡

29 ¡

Design ¡Issues: ¡

Can’t ¡avoid ¡Load/ALU ¡instr. ¡bubble ¡ Branch ¡resoluMon ¡in ¡EX ¡stage ¡→ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Two-­‑cycle ¡branch ¡penalty ¡ Mem ¡stage ¡unused ¡for ¡ALU ¡instr ¡

slide-30
SLIDE 30

AlternaMve ¡Pipelining ¡Design: ¡ Avoiding ¡the ¡load ¡latency ¡penalty ¡

Example: ¡ ¡ ¡i: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R4 ¡← ¡Mem[R8] ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡i+1: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R7 ¡← ¡R4 ¡+ ¡R5 ¡ Bauer ¡p. ¡43 ¡

30 ¡

slide-31
SLIDE 31

Avoiding ¡the ¡load ¡latency ¡penalty ¡

Example: ¡ ¡ ¡i: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R4 ¡← ¡Mem[R8] ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡i+1: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R7 ¡← ¡R4 ¡+ ¡R5 ¡ Bauer ¡p. ¡43 ¡

31 ¡

slide-32
SLIDE 32

Address ¡GeneraMon ¡Latency ¡Penalty ¡

Example: ¡ ¡ ¡i: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R5 ¡← ¡R6 ¡+ ¡R7 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡i+1: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡R9 ¡← ¡Mem[R5] ¡ Can’t ¡forward ¡from ¡ ¡

  • future. ¡Has ¡to ¡stall. ¡

Bauer ¡p. ¡43 ¡

32 ¡

slide-33
SLIDE 33

Other ¡changes ¡

AG ¡used ¡for ¡branch ¡resoluMon ¡ AG ¡unused ¡for ¡ALU ¡operaMons ¡

Bauer ¡p. ¡43 ¡

33 ¡

slide-34
SLIDE 34

Tradeoffs: ¡

Bauer ¡p. ¡43 ¡

34 ¡

Avoids ¡load/ALU ¡bubble ¡X ¡addiMonal ¡ALU ¡unit ¡ Move ¡branch ¡resoluMon ¡to ¡AG ¡→ ¡same ¡penalty ¡ AG ¡stage ¡unused ¡for ¡ALU ¡operaMons ¡ Stalls ¡for ¡ALU/Store ¡instr. ¡dependency ¡

slide-35
SLIDE 35

Which ¡one ¡is ¡befer? ¡

MIPS ¡ Intel ¡486 ¡

Bauer ¡p. ¡44 ¡

35 ¡

slide-36
SLIDE 36

Pipelining ¡FuncMonal ¡Units: ¡ ¡the ¡EX ¡stage ¡

  • Parameters ¡of ¡interest: ¡

– number ¡of ¡stages ¡ – minimum ¡number ¡of ¡cycles ¡before ¡two ¡ independent ¡(no ¡RAW) ¡instrucMons ¡of ¡the ¡same ¡ type ¡can ¡enter ¡the ¡funcMonal ¡unit ¡

Bauer ¡p. ¡44 ¡

36 ¡

slide-37
SLIDE 37

Single-­‑Precision ¡ FloaMng ¡Point ¡RepresentaMon ¡

Most ¡standard ¡floaMng ¡point ¡representaMon ¡use: ¡ ¡ ¡ ¡1 ¡bit ¡for ¡the ¡sign ¡(posiMve ¡or ¡negaMve) ¡ ¡ ¡ ¡8 ¡bits ¡for ¡the ¡range ¡(exponent ¡field) ¡ ¡23 ¡bits ¡for ¡the ¡precision ¡(fracMon ¡field) ¡

S E F

23 ¡ 8 ¡ 1 ¡

N = −1

( )

S ×1.fraction × 2exponent−127, 1≤ exponent ≤ 254

−1

( )

S × 0.fraction × 2exponent−126, exponent = 0

⎧ ⎨ ⎪ ⎩ ⎪

From: ¡Paf ¡and ¡Patel, ¡pp. ¡33 ¡ P-­‑H. ¡p. ¡245 ¡ Bauer ¡p. ¡45 ¡ exponent ¡ frac0on ¡ sign ¡

37 ¡

slide-38
SLIDE 38

Special ¡FloaMng ¡Point ¡RepresentaMons ¡

In ¡the ¡8-­‑bit ¡field ¡of ¡the ¡exponent ¡we ¡can ¡represent ¡numbers ¡from ¡0 ¡to ¡

  • 255. ¡We ¡studied ¡how ¡to ¡read ¡numbers ¡with ¡exponents ¡from ¡0 ¡to ¡254. ¡

What ¡is ¡the ¡value ¡represented ¡when ¡the ¡exponent ¡is ¡255 ¡(i.e. ¡111111112)? ¡ An ¡exponent ¡equal ¡255 ¡= ¡111111112 ¡in ¡a ¡floaMng ¡point ¡representaMon ¡ indicates ¡a ¡special ¡value. ¡ When ¡the ¡exponent ¡is ¡equal ¡255 ¡= ¡111111112 ¡and ¡the ¡fracMon ¡is ¡0, ¡ the ¡value ¡represented ¡is ¡± ¡infinity. ¡ When ¡the ¡exponent ¡is ¡equal ¡255 ¡= ¡111111112 ¡and ¡the ¡fracMon ¡is ¡ ¡ non-­‑zero, ¡the ¡value ¡represented ¡is ¡Not ¡a ¡Number ¡(NaN). ¡ Hen/Paf, ¡pp. ¡301 ¡ P-­‑H. ¡p. ¡246 ¡ Bauer ¡p. ¡45 ¡

38 ¡

slide-39
SLIDE 39

Stage ¡1 ¡ Stage ¡2-­‑3 ¡ Stage ¡4 ¡

FloaMng ¡Point ¡AddiMon ¡

(S1, ¡E1, ¡F1) ¡ (S2, ¡E2, ¡F2) ¡

E1 ¡< ¡E2 ¡

Insert ¡1 ¡to ¡leY ¡of ¡F1 ¡and ¡to ¡leY ¡of ¡F2 ¡ ¡

S1 ¡≠ ¡S2 ¡

D ¡= ¡E1 ¡– ¡E2 ¡ F2 ¡← ¡F2 ¡<< ¡D ¡ add ¡manMssas ¡ Normalize ¡and ¡round ¡off ¡ swap ¡operands ¡

yes ¡

replace ¡F2 ¡by ¡its ¡2-­‑complement ¡

yes ¡ Bauer ¡p. ¡46 ¡

39 ¡