Pipelining Flashcards

1
Q

What is the canonical processor pipeline?

A

Fetch Read/Decode ALU Memory Write

Fetch: Use program counter (PC) to get instruction from instruction memory
Read/Decode: Read registers and decode instruction
ALU: Perform arithmetic and logical operations on info read from registers, using logic decoded from instruction
Memory: If instruction was a load or store, ALU will return address and we’ll load/store from that address in data memory
Write: Write result to register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would CPI be greater than 1 in a pipeline?

A
  • Initial filling of the pipeline, though this becomes negligible as # of instructions grows large
  • Pipeline stalls! (the real answer)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why might there be a stall in the pipeline?

A
  • Branches/jumps: e.g., when you have a jump instruction, you can’t load the correct subsequent instructions until after the jump has been decoded and processed by the ALU. So when jump gets to the ALU, you have to flush all instructions earlier in the pipeline.
  • Data dependencies: An early stage in the pipeline might need the result of an instruction later in the pipeline to execute correctly, like the Decode stage waiting on the ALU to load something from memory to a particular register.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a control dependence?

A

When execution of instructions depends on the behavior of a branch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What two factors determine how control dependence will affect CPI in a pipeline?

A
  • Branch misprediction penalty: the # of pipeline stages that come before the stage where a branch is decided
  • Branch prediction: If you can accurately predict branches, you can avoid the penalty!

The deeper the pipeline, the better your branch prediction needs to be!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Types of data dependencies

A

RAW (read after write): When an instruction needs to read from a register that a previous instruction is writing to, it can’t move forward until the previous one completes. Also called a “flow” or “true” dependence.

WAW (write after write): When an instruction needs to write to a register that previous instruction is writing to (if they go out of order, the wrong item will be in the register). Also called an “output” dependence.

WAR (write after read): When an instruction needs to write to a register after another reads from it. Order matters so that the earlier instruction reads the correct data. Also called “anti” dependence because it reverses the order of RAW.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which data dependencies are “true” and which “false”?

A

True: RAW (also called “flow” or “true” dependence)

False: WAW and WAR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Another name for “false” dependence

A

Name dependence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is RAR (read after read) a dependence?

A

Nope! It doesn’t matter what order instructions read in as long as no one is writing to that register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Dependencies vs Hazards

A

Dependencies are a property of the program alone. Not all dependencies are hazards (just RAW I guess?)

Hazards are a property of the program and pipeline! If an instruction has a data dependency on an earlier instruction, but the earlier one leaves the pipeline before it reads the register, there’s no hazard! Also, false dependencies are never(?) hazards.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we handle hazards?

A
  1. Flush dependent instructions. For branches, this is the only option.
  2. Stall dependent instructions. This works for data dependencies.
  3. Fix values read by dependent instructions. This works for SOME data dependencies. As long as the correct value exists somewhere in the pipeline, we can “forward” it to where it’s needed. It doesn’t need to be written to register first.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does the number of stages affect performance?

A

As number of stages increases, the number of hazards increase (and so does misprediction penalty), increasing CPI.

But the work needed per stage decreases, decreases clock time per cycle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to choose number of stages to optimize performance?

A

Best performance is achieved by adding more stages so that we decrease work needed per stage (clock time), without adding so many stages that we significantly increase hazards. The graph of execution time vs # stages is an upward facing parabola.

In modern processors, the minima is around 30-40 stages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Should we optimize pipelines strictly for performance?

A

No! Consider power consumption too. Power consumption increases linearly with number of stages, so we choose the point where this intersects the performance optimization parabola.

On modern processors, this is around 10-15 stages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly