YouTube2Text

[CS61C FA20] Lecture 22.2 - Pipelining II: Pipeline Hazards — Transcript

by CS 61C Departmental · 1,503 words · 269 segments · language en · Watch on YouTube

Full transcript

  1. 0:11Hello. Welcome back to the module that
  2. 0:14deals with the pipeline processor
  3. 0:16design.
  4. 0:17So far we took our single cycle CPU and
  5. 0:21modified it
  6. 0:22to make it a pipeline processor. In that
  7. 0:25process we added some pipeline registers
  8. 0:28and move some resources around so the
  9. 0:30things look a little bit easier to
  10. 0:33design.
  11. 0:36We didn't quite design a good pipeline
  12. 0:39processor. It
  13. 0:41you know really badly suffers
  14. 0:43from some
  15. 0:45common issues that are associated with
  16. 0:48pipeline hazards.
  17. 0:50Now pipeline hazards
  18. 0:52um
  19. 0:53stands for a collection of issues that
  20. 0:55pipeline processors encounter.
  21. 0:59When we talk about pipeline processors,
  22. 1:03the basic thing that differs between a
  23. 1:05pipeline processor
  24. 1:07and a single cycle processor is that we
  25. 1:10have multiple instructions in flight.
  26. 1:12In a single cycle processor
  27. 1:16our instructions
  28. 1:18really depend only on themselves. Every
  29. 1:20instruction completes and then the next
  30. 1:23instruction
  31. 1:24um
  32. 1:25starts to execute. And there is no
  33. 1:28really dependency between them. In
  34. 1:31pipeline processors, there are multiple
  35. 1:34instructions that are simultaneously
  36. 1:35being executed.
  37. 1:37And if the results of one instruction
  38. 1:40affect the following instruction
  39. 1:43then we have an issue.
  40. 1:45The following instruction cannot
  41. 1:48proceed.
  42. 1:49There are generally three types of
  43. 1:51hazards.
  44. 1:53So it is important to understand them
  45. 1:55because they have different solutions
  46. 1:58that will
  47. 2:00um avoid
  48. 2:03running into those hazards.
  49. 2:05Um in general, why they're all called
  50. 2:07hazards because especially earlier on,
  51. 2:11it was not clear who was going to take
  52. 2:14care of these issues.
  53. 2:16They can be addressed by either a
  54. 2:18compiler or the pipeline
  55. 2:21pipeline processor designer, but
  56. 2:23somebody has to take care of these
  57. 2:25hazards. If nobody does, the processor
  58. 2:27doesn't work.
  59. 2:29Or even worse, works most of the time,
  60. 2:31but fails from time to time and it's
  61. 2:35really difficult to find out when and
  62. 2:37why it fails.
  63. 2:40So, as I said, there are three types of
  64. 2:42hazards that we can encounter and those
  65. 2:45are structural hazards, data hazards,
  66. 2:47and control hazards.
  67. 2:49It is always a situation that prevents
  68. 2:52starting a new instruction while there
  69. 2:54is another instruction that is in
  70. 2:56flight.
  71. 2:58Structural hazards
  72. 3:01appear because of contention over a
  73. 3:04resource.
  74. 3:05In most modern processors, at least
  75. 3:08these that are not that complicated like
  76. 3:11the ones that we are designing in this
  77. 3:13class, we are rarely going to run into
  78. 3:15structural hazards.
  79. 3:18And the pipeline is designed to match
  80. 3:21the ISA and ISA prevents the existence
  81. 3:24of these hazards.
  82. 3:25Then the second type are data hazards.
  83. 3:28Data hazards essentially exist because
  84. 3:32of the dependency between the
  85. 3:34instructions. So, if there is one
  86. 3:37instruction that is in flight that is
  87. 3:39going to write the result into the
  88. 3:42register file, the result that the
  89. 3:45following instruction cannot really
  90. 3:49um depend, cannot work with the same
  91. 3:53operand, that is before it gets written
  92. 3:56back into the register file.
  93. 3:59Otherwise, we will be working with an
  94. 4:01incorrect value. We're going to talk a
  95. 4:03little bit more about that just in a
  96. 4:06bit. And finally, there is a control
  97. 4:08hazard. The control hazards happen when
  98. 4:10you have branches. If the following
  99. 4:13instruction that is being executed in
  100. 4:14the pipeline is
  101. 4:18following a branch,
  102. 4:20so if there is a branch in the pipeline
  103. 4:21and there is another instruction after
  104. 4:23that, that next instruction may be
  105. 4:25invalid if the branch ends up being
  106. 4:28taken.
  107. 4:30So, let's talk about structural hazard
  108. 4:33hazards in a bit more of a detail.
  109. 4:36The simplest type of a structural hazard
  110. 4:39that we already addressed in our design
  111. 4:42even of a single cycle CPU
  112. 4:44is the contention between incrementing
  113. 4:48the program counter and performing
  114. 4:51arithmetic operations and
  115. 4:55um when addressing the memory.
  116. 4:59For example, we could have made a
  117. 5:02mistake and left out the PC plus four
  118. 5:06adder and said, "Let's use the ALUs ALU
  119. 5:09instead." So, every time we would have
  120. 5:11to add PC plus four to our instruction,
  121. 5:14we would use the ALU.
  122. 5:18Well, we have an issue there,
  123. 5:21right? Every time we
  124. 5:25need to add four to the program counter,
  125. 5:29our ALU would not be available. So, our
  126. 5:32um processor would not work very well.
  127. 5:34It would first, you know, in one cycle
  128. 5:37would add PC plus four and then in the
  129. 5:40next cycle would have to execute things.
  130. 5:42So, it was a very natural decision and
  131. 5:44we we just went through that to have a
  132. 5:47dedicated adder that increments the
  133. 5:49program counter.
  134. 5:51Um
  135. 5:52So, in general, structural hazards
  136. 5:56appear because two instructions in the
  137. 6:00pipeline compete for the same resource.
  138. 6:03There are two ways to address structural
  139. 6:05hazards. One is to stall.
  140. 6:08And that's what I've just described as a
  141. 6:10possible outcome for not having a PC
  142. 6:12plus four adder.
  143. 6:14Um essentially, the next instruction
  144. 6:17would stall until the previous
  145. 6:19instruction is not is is done is
  146. 6:22finished uh using that resource.
  147. 6:26A stall um often means introducing
  148. 6:30no-ops. We'll see that in a bit.
  149. 6:33Then more com- a more more common
  150. 6:35solution is to add more hardware to our
  151. 6:38pipeline such that all instructions can
  152. 6:41execute concurrently.
  153. 6:46So,
  154. 6:47um let's take a look at the
  155. 6:49fairly straightforward structural hazard
  156. 6:52that can exist because of the register
  157. 6:54file.
  158. 6:55So, in RISC-V ISA,
  159. 6:59our instructions can
  160. 7:02access the register file three times.
  161. 7:04There are two operands to be read and
  162. 7:06one to be written. So, our
  163. 7:09register file has to be able to support
  164. 7:12that. Otherwise, we would have an a
  165. 7:14shortage of of resources. So, our
  166. 7:17register file is designed to have two
  167. 7:19read ports
  168. 7:20and a write port.
  169. 7:23There are, remember, three addresses
  170. 7:25that go into the input of the register
  171. 7:27file.
  172. 7:28There's another subtlety um in there.
  173. 7:32In order to be able to complete all of
  174. 7:34this all of the operations in a single
  175. 7:37cycle or in a pipeline processor, we
  176. 7:40made one assumption that the register
  177. 7:42file is fairly fast. So, it is faster
  178. 7:45than many of the other units that we
  179. 7:47have in a processor. We can read the
  180. 7:49register file in a 100 picoseconds, and
  181. 7:52we can also write to a register file in
  182. 7:54a 100 picoseconds. We'll see that that's
  183. 7:56a convenient thing that allows us to
  184. 7:58both read and write the register file in
  185. 8:01a single cycle.
  186. 8:05But, the key thing here is register file
  187. 8:07has to be designed to support three
  188. 8:09accesses per cycle
  189. 8:12simultaneously.
  190. 8:15Let's take a look at another type of a
  191. 8:17structural hazard that we may have.
  192. 8:19Uh it may be there may be a memory
  193. 8:21contention.
  194. 8:23So, in
  195. 8:25pretty much every instruction needs to
  196. 8:27access the instruction memory.
  197. 8:30Um but, some instructions need to
  198. 8:34work you read or write the data to the
  199. 8:38memory.
  200. 8:40And we said that we have this unified
  201. 8:42concept of a memory that we're working
  202. 8:44with a stored program computer, so there
  203. 8:46should be just one memory.
  204. 8:47So, every time there is a load or store,
  205. 8:51it is going to contend with every other
  206. 8:53instruction for the memory access. In
  207. 8:55this case, it is shown
  208. 8:58that if you have a load word
  209. 9:01during the memory access phase, another
  210. 9:04instruction that would perhaps be trying
  211. 9:07to read an instruction if you just had
  212. 9:08one memory, this add immediate would
  213. 9:11have to stall and would have to wait
  214. 9:14until the load word is done if you just
  215. 9:17had one memory.
  216. 9:19So, a solution to this is to have two
  217. 9:23memories.
  218. 9:24But, didn't you
  219. 9:25just contradict yourself? Well, then
  220. 9:27don't we have just one memory?
  221. 9:31And what's the story about two memories?
  222. 9:33Well,
  223. 9:34we do have one main memory that lives in
  224. 9:36DRAM, but we generally have cache that
  225. 9:40is on our
  226. 9:41processor die on on our processor chip.
  227. 9:45And you're going to see that in just
  228. 9:46next module in a in a couple of
  229. 9:47lectures.
  230. 9:49Um essentially, there are pieces of of
  231. 9:52um
  232. 9:53of uh there are chunks of memory on our
  233. 9:56processor chip that
  234. 9:59have copies of the instructions that are
  235. 10:01have been copied from the main memory
  236. 10:03and copies of the data that has been
  237. 10:05copied from the main memory with two
  238. 10:07separate ways to access it. So, we don't
  239. 10:09have to contend for the main memory
  240. 10:12when we are fetching an instruction
  241. 10:15um while another instruction is
  242. 10:17completing uh a read or a write.
  243. 10:22All right.
  244. 10:24So, in summary,
  245. 10:25structural hazards can exist, but they
  246. 10:28are avoided um
  247. 10:31by typically by the
  248. 10:35by the hardware design that matches the
  249. 10:37ISA. So, we'll look through all the
  250. 10:39instructions that are in the ISA, and we
  251. 10:42make sure that our hardware is pro-
  252. 10:44provisioned to support all all of these
  253. 10:47instructions
  254. 10:48during the depth of the pipeline that
  255. 10:51can exist concurrently during the depth
  256. 10:53of a pipeline.
  257. 10:55So, what we have seen is that our
  258. 11:00register file has to support whatever
  259. 11:03um the ISA requires us to have for it
  260. 11:08and that we need to have separate
  261. 11:11instruction and data memories or at
  262. 11:13least copies of instruction and data
  263. 11:15memory so we can access them separately.
  264. 11:19That's it for structural hazards.
  265. 11:21They're relatively straightforward to
  266. 11:23understand. The next ones are data
  267. 11:25hazards, which are a little bit
  268. 11:27trickier.
  269. 11:29See you in a bit.

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 22.2 - Pipelining II: Pipeline Hazards by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,503 words across 269 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.