Forwarded from Accio
Pipelining (Instruction-Level Parallelism)
https://en.algorithmica.org/hpc/pipelining/
In order for a CPU to execute any instruction, it needs to follow a few steps:
Fetch machine code from memory
Decode the code and recognize instructions
Execute the instructions where some may do memory operations
Write the results to memory
Notice after an instruction is fetched, CPU can start to process the next one without waiting for it to complete. Modern CPUs take advantage of this and perform a "free" (since we are not using an extra core) parallelism. This is called Pipelining
#cpu #pipelining #parallesim
https://en.algorithmica.org/hpc/pipelining/
In order for a CPU to execute any instruction, it needs to follow a few steps:
Fetch machine code from memory
Decode the code and recognize instructions
Execute the instructions where some may do memory operations
Write the results to memory
Notice after an instruction is fetched, CPU can start to process the next one without waiting for it to complete. Modern CPUs take advantage of this and perform a "free" (since we are not using an extra core) parallelism. This is called Pipelining
#cpu #pipelining #parallesim
Forwarded from Accio
Regarding to pipe-lining, they don't always result in optimization. There are times when you might run into obstacles called Pipeline Hazards.
There are three types of pipeline hazards:
Structural Hazard: When two or more instructions need the same unit of CPU
Data Hazard: An instruction needs to wait for a previous operation to be completed
Control Hazard: CPU can’t tell which instructions it needs to execute next
The third one probably got your attention. How could CPU not know which instruction to execute next? Imagine a simple If statement. When CPU reaches this type of branching, It cannot choose future instructions with 100% certainty. That's why there a set of tricks to remove branches from your program as much as possible called Branchless-Programming.
It's worth noting that compilers do a set of optimizations in regard of removing branches as well. So knowing how your compiler acts is essential to how you optimize your code.
#CPU #Pipelining #Branchless_Programming.
There are three types of pipeline hazards:
Structural Hazard: When two or more instructions need the same unit of CPU
Data Hazard: An instruction needs to wait for a previous operation to be completed
Control Hazard: CPU can’t tell which instructions it needs to execute next
The third one probably got your attention. How could CPU not know which instruction to execute next? Imagine a simple If statement. When CPU reaches this type of branching, It cannot choose future instructions with 100% certainty. That's why there a set of tricks to remove branches from your program as much as possible called Branchless-Programming.
It's worth noting that compilers do a set of optimizations in regard of removing branches as well. So knowing how your compiler acts is essential to how you optimize your code.
#CPU #Pipelining #Branchless_Programming.
Forwarded from Accio
Regarding to pipe-lining, they don't always result in optimization. There are times when you might run into obstacles called Pipeline Hazards.
There are three types of pipeline hazards:
Structural Hazard: When two or more instructions need the same unit of CPU
Data Hazard: An instruction needs to wait for a previous operation to be completed
Control Hazard: CPU can’t tell which instructions it needs to execute next
The third one probably got your attention. How could CPU not know which instruction to execute next? Imagine a simple If statement. When CPU reaches this type of branching, It cannot choose future instructions with 100% certainty. That's why there a set of tricks to remove branches from your program as much as possible called Branchless-Programming.
It's worth noting that compilers do a set of optimizations in regard of removing branches as well. So knowing how your compiler acts is essential to how you optimize your code.
#CPU #Pipelining #Branchless_Programming.
There are three types of pipeline hazards:
Structural Hazard: When two or more instructions need the same unit of CPU
Data Hazard: An instruction needs to wait for a previous operation to be completed
Control Hazard: CPU can’t tell which instructions it needs to execute next
The third one probably got your attention. How could CPU not know which instruction to execute next? Imagine a simple If statement. When CPU reaches this type of branching, It cannot choose future instructions with 100% certainty. That's why there a set of tricks to remove branches from your program as much as possible called Branchless-Programming.
It's worth noting that compilers do a set of optimizations in regard of removing branches as well. So knowing how your compiler acts is essential to how you optimize your code.
#CPU #Pipelining #Branchless_Programming.