ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao...
Transcript of ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao...
![Page 1: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/1.jpg)
ARQUITETURA DE COMPUTADORESDEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG
Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding
![Page 2: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/2.jpg)
Pipelining: É Natural! Lavanderia 4 pessoas A, B, C e D
possuem 4 sacolas de roupa para lavar, secar e dobrar
Lavar leva 30 minutos
Secar leva 40 minutos
Dobrar leva 20 minutos
A B C D
![Page 3: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/3.jpg)
Lavanderia Sequencial
Lavanderia sequencial leva 6 horas para terminar Se eles conhecessem computação, quanto tempo levaria?
A
B
C
D
30 40 20 30 40 20 30 40 20 30 40 20
6 7 8 9 10 11 Meia-noite
Tarefas
seq
Tempo
![Page 4: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/4.jpg)
Lavanderia com Pipelining: Início da Tarefa ASAP
Lavanderia com pipelining leva 3.5 horas !!!
A
B
C
D
6 7 8 9 10 11 Meia-noite
Tarefas
seq
Tempo
30 40 40 40 40 20
![Page 5: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/5.jpg)
Lições Aprendidas Pipelining não melhora a
latência de uma única tarefa, mas melhora o throughput do trabalho todo
Taxa de inserção de tarefas é limitada pela tarefa mais lenta
Existem múltiplas tarefas sendo executadas em um dado instante
SpeedUp potencial = número de estágios
Tempo para encher o pipeline e tempo de dreno reduzem o speedup
A
B
C
D
6 7 8 9
Tarefas
seq
Tempo
30 40 40 40 40 20
![Page 6: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/6.jpg)
Pipelining Múltiplas instruções podem ser
executadas a cada instante
Leva em consideração o paralelismo existente entre instruções
Chave para implementação eficiente em qualquer processador moderno
![Page 7: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/7.jpg)
Implementação do MIPS
![Page 8: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/8.jpg)
Implementação de Pipeline
InstruçãoREG
REG
Comb.
RESULTADO
Clock
Comb.Comb.
1 2 3
/ 1 2 3
/ 1 2 3max( , , )
s pipe
c pipe
t
t
![Page 9: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/9.jpg)
Equação do Pipeline
/
/ max( )
s pipe ii
c pipe i
t
t
1/
n
ii
c pipetn
![Page 10: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/10.jpg)
Decodificação local para uma instrução em cada fase do pipeline
Implementação do MIPS com Pipeline
![Page 11: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/11.jpg)
Visualização do Pipeline
![Page 12: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/12.jpg)
Representação Esquemática do Pipeline
Instrução 1 2 3 4 5 6 7 8 9i IF ID EX MEM WB
i+1 IF ID EX MEM WBi+2 IF ID EX MEM WBi+3 IF ID EX MEM WBi+4 IF ID EX MEM WB
Entretanto, pipeline ainda não funciona
![Page 13: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/13.jpg)
Por que Pipelines são Difíceis em Computadores
Limites da arquitetura: Hazards não deixam próxima instrução executar no próximo ciclo Structural hazards: conflito de hardware (mais de
uma instrução quer utilizar a mesma unidade funcional)
Data hazards: instrução depende de um resultado de uma instrução que ainda não completou
Control hazards: Pipelining de branches e outras insruções que modificam o PC
Solução comum: Stall o pipeline (inserção de uma “bolha”) até o
hazard ser resolvido.
![Page 14: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/14.jpg)
Structural Hazard Porto de Memória Único
![Page 15: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/15.jpg)
Structural Hazard Porto de Memória Único
![Page 16: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/16.jpg)
Diagrama Esquemático do Pipeline
Instrução 1 2 3 4 5 6 7 8 9Load IF ID EX MEM WB
Instr. 1 IF ID EX MEM WBInstr. 2 IF ID EX MEM WB
Stall - - - - -Instr. 3 IF ID EX MEM WB
Instrução 1 2 3 4 5 6 7 8 9Load IF ID EX MEM WB
Instr. 1 IF ID EX MEM WBInstr. 2 IF ID EX MEM WBInstr. 3 - IF ID EX MEM WB
Representação alternativa (preferível)
![Page 17: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/17.jpg)
/
/
/ /
/ /
/ /
/ /
/
s pipeline
c pipeline
s pipeline s pipeline
c pipeline c pipeline
s pipeline s pipeline
c pipeline c pipeline
s pipelineideal
ideal
ExecTimeSpeedup
ExecTime
CPI
CPI
CPI
CPI
CPICPI num estagios
CPI numSpeedup
/
/ /
s pipeline
c pipeline c pipeline
estagios
CPI
Equação de SpeedUp para Pipelining
![Page 18: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/18.jpg)
Equação de SpeedUp para Pipelining
/
/
/
/
1
pipeline ideal
s pipelineideal
ideal c pipeline
s pipeline
c pipeline
CPI CPI stalls
CPI num estagiosSpeedup
CPI sta
num estagiosSpeedup
stalls
lls
![Page 19: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/19.jpg)
Exemplo: Dois Portos de Memória vs. Porto Único
Máquina A: Dois portos de memória Máquina B: Um porto de memória, mas a
implementação do pipeline é 1.05 vezes rápida do que A
CPI Ideal = 1 para A e B Loads ocorrem com freq. de 40%
SpeedUpA = Pipeline Depth/(1 + 0) x (clockunpipe/clockpipe) = Pipeline Depth
SpeedUpB = Pipeline Depth/(1 + 0.4 x 1) x (clockunpipe/(clockunpipe / 1.05)
= (Pipeline Depth/1.4) x 1.05 = 0.75 x Pipeline Depth
SpeedUpA / SpeedUpB = Pipeline Depth/(0.75 x Pipeline Depth) = 1.33
Máquina A é 1.33 vezes mais rápida
![Page 20: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/20.jpg)
Data Hazard no MIPS
![Page 21: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/21.jpg)
Tipos de Data Hazards
InstrI precede InstrJ
Read After Write (RAW) InstrJ tenta ler operando antes de InstrI
escrever resultado
![Page 22: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/22.jpg)
Tipos de Data Hazards
InstrI precede InstrJ
Write After Read (WAR) InstrJ tenta escrever resultado antes que InstrI
leia operando
Não ocorre no pipeline do MIPS porque: Todas as instruções levam 5 ciclos, Leitura de operandos ocorrem no estágio 2, Escrita de resultados ocorre no estágio 5
![Page 23: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/23.jpg)
Tipos de Data Hazards
InstrI precede InstrJ
Write After Write (WAW) InstrJ tenta escrever resultado antes que InstrI escreva Deixa resultado errado
Não ocorre no pipeline do MIPS porque : Todas as instruções levam 5 ciclos, Escrita de resultados ocorre no estágio 5
WAR e WAW aparecerão em variações posteriores do MIPS
![Page 24: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/24.jpg)
Tipos de Data Hazards
InstrI precede InstrJ
E Read After Read (RAR) ???InstrJ tenta ler resultado antes que InstrI leia operando
NÃO CAUSA PROBLEMA ! ! !
Só existem três tipos: RAW, WAW, WAR (pelo menos uma escrita tem que existir)
![Page 25: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/25.jpg)
Forwarding para Evitar Hazards de Dados
![Page 26: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/26.jpg)
Forwarding para Evitar Hazard de Dados
![Page 27: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/27.jpg)
Forwarding para Evitar Hazard de Dados
![Page 28: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/28.jpg)
Mudança do Hardware para Permitir Forwarding
![Page 29: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/29.jpg)
Produza o código mais rápido para
a = b + c;
d = e – f;
assumindo que a, b, c, d ,e, f estão na memória.
Código lento:
LW Rb,b
LW Rc,c
ADD Ra,Rb,Rc
SW a,Ra
LW Re,e
LW Rf,f
SUB Rd,Re,Rf
SW d,Rd
Escalonamento de SW para Evitar Load Hazards
Código rápido:LW Rb,bLW Rc,cLW Re,e ADD Ra,Rb,RcLW Rf,fSW a,Ra SUB Rd,Re,RfSW d,Rd
![Page 30: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/30.jpg)
Sucesso dos Compiladores para Evitar Load Stalls
0 20 40 60 80
gcc
spice
tex
unscheduled scheduled
% loads stalling pipeline
25%
65%
14%
42%
31%
54%
![Page 31: ARQUITETURA DE COMPUTADORES DEPT. DE CIÊNCIA DA COMPUTAÇÃO - UFMG Aula 06: Introdução ao Pipelining, Hazards Estruturais e Forwarding.](https://reader036.fdocumentos.com/reader036/viewer/2022062404/552fc101497959413d8bd34a/html5/thumbnails/31.jpg)
Resumo: Pipelining Se tarefas são independentes, é só executar as
sub-tarefas concorrentemente (overlap) Speed Up e Pipeline Depth; se CPI Ideal é 1,
então:
Hazards limitam a performance dos computadores: Structural: é necessário alocar mais recursos de HW Data: necessita de forwarding, e escalonamento de
instruções pelo compilador Control: a ser discutido
Speedup =Pipeline Depth
1 + CPI stallsX
Clock Cycle Unpipelined
Clock Cycle Pipelined