[CS61C FA20] Lecture 33.4 - Thread-Level Parallelism I: Multithreading — Transcript
Full transcript
- 0:00and welcome back up till now all we
- 0:03understand
- 0:03is you've got a core you've got a single
- 0:05hardware thread on that that's all you
- 0:06know
- 0:08let's actually talk about the idea of
- 0:10what multi-threading is and maybe you
- 0:11could have more than one
- 0:13thread per core how would that even work
- 0:15let's think about that
- 0:17so typical scenario active thread you're
- 0:19working and you've got a cache miss
- 0:21oh we're going to sacramento you got to
- 0:23wait a thousand cycles to go to dram
- 0:25so we know this already we'll switch
- 0:26this out and different thread is going
- 0:27to now run
- 0:28until the data is available we've seen
- 0:29that already but what do we have we got
- 0:31to save the current thread state and
- 0:33load a new thread state
- 0:34pc registers could be a lot the avx
- 0:37could be a lot of registers to save that
- 0:38and you got to perform you have to
- 0:39perform that switch in a thousand cycles
- 0:41you've got to be able to perform that
- 0:42switch in a thousand cycles how does
- 0:43that even work
- 0:44can hardware help can hardware somehow
- 0:47help
- 0:48the fact that i've got to switch threads
- 0:50in less than a thousand cycles when the
- 0:51when the previous memory request came in
- 0:53going to sacramento to do a load or
- 0:55store word
- 0:57here it is hardware assisted software
- 1:01multi-threading that's that's the title
- 1:02here and here's the big idea there's a
- 1:04really big idea a very clever idea
- 1:07you got one core remember one core i'm
- 1:09fine right one core
- 1:12two threads two hardware threads and one
- 1:15core
- 1:16how would you make this happen i'll take
- 1:17a look
- 1:19i could have two different pcs
- 1:22two different pcs two separate registers
- 1:26one aou look at that transistors are
- 1:30cheap
- 1:30transistors are cheap so i two copies of
- 1:33my pc and registers inside
- 1:35this looks identical here's the key
- 1:38from the software point of view this
- 1:41looks like this looks like
- 1:42two different hardware threads it's one
- 1:46core
- 1:46this is one core it looks like two
- 1:49different hardware threads
- 1:51okay pretty neat
- 1:55we call this or actually intel came up
- 1:56with this name intel called it
- 1:58hyper threading okay because both
- 2:01threads can be active simultaneously and
- 2:03again we still have one memory
- 2:05but i have two threads in there
- 2:09okay two hardware threads on one core
- 2:13here's a slide from an is an intel pr uh
- 2:16pr video explaining how this worked in
- 2:19this picture blue is idle
- 2:21just here blue all these things that are
- 2:22blue if you're light blue or all these
- 2:23things here blue
- 2:24are idle so nothing's happening there
- 2:26and i've got in the olden days
- 2:29logically in terms of physical
- 2:31processors i still have one physical
- 2:33core
- 2:33processor one physical core okay logical
- 2:37processors visible to the os
- 2:38if i just have one and i have two
- 2:40threads a red thread here
- 2:42and a green thread then this is the red
- 2:45one and this is the green one
- 2:47if you're having trouble with the color
- 2:49here is the red one being loaded in
- 2:51and here oh look these resources maybe
- 2:53you have some resource can be used
- 2:54two of them at the same time we've seen
- 2:56that before okay now i've got this and
- 2:57i'll be able to able to
- 2:58compute the red guy first all that
- 3:00thread is to finish before the green guy
- 3:01finishes
- 3:03here's the idea could you actually run
- 3:06both at the same time if i have multiple
- 3:08resources maybe one's doing a load store
- 3:10maybe one's doing the alu
- 3:12that's two different parts of the same
- 3:13cpu couldn't you somehow run both of
- 3:15them at the same time
- 3:16so that's the idea i'm going to have
- 3:18logically visible to the os
- 3:20there are two of them and they're both
- 3:22being active at the same time and
- 3:24sometimes the resources are able to
- 3:26happen at the same time
- 3:27so all this blue this is all the blue
- 3:29area that's idle notice there's less all
- 3:31that time you're basically the green
- 3:33guys filling in some of those spots
- 3:35that's really really neat and what you
- 3:37see the throughput is much much
- 3:39higher in terms of throughput so in this
- 3:43model
- 3:43of simultaneous multi-threading
- 3:46multi-threading means
- 3:47at the same time two threads are working
- 3:49on one core
- 3:51you have the number of logical cpus
- 3:53greater than the number of physical cpus
- 3:56cpu means core here so i've got one core
- 3:59one
- 4:00physical cpu maybe two logical cpus
- 4:03done okay so run multiple threads at the
- 4:06same time per core
- 4:08each thread has its own state pc
- 4:10registers etc
- 4:11and we can share some resources cash
- 4:14instructional unit execution students
- 4:15and there's a whole group at university
- 4:17of washington that has
- 4:18talked about simultaneous
- 4:20multi-threading that's the smt
- 4:22group there so check that out so here is
- 4:25multi-threading logical threads
- 4:27a little bit more hardware most of the
- 4:29same hardware right the alu is the same
- 4:30aou
- 4:31well add some registers add a pc that's
- 4:33very little and all of a sudden i can
- 4:35have
- 4:35on one core two different hardware
- 4:37threads pretty powerful
- 4:39arguably ten percent or more better
- 4:40performance because sometimes like you
- 4:42know i'm kind of filling in the gaps
- 4:43when this guy's idle or do one resource
- 4:45i can fit another guy in there
- 4:46a lot of clever engineering has gone
- 4:48into it to figure out how to make these
- 4:50as efficient as possible
- 4:51so separate registers we saw that but
- 4:53i'm sharing the data path i'm sharing
- 4:54the alus and sharing the caches
- 4:58but from the point of view of software i
- 4:59don't care about that i still i just see
- 5:01two different i see two different uh
- 5:04logical cpus we call them logical now
- 5:05the distinguishment physical cpus
- 5:07so multi-cores duplicate processors 50
- 5:10more so versus
- 5:11that's the logical threads multi-core
- 5:13means now that's in one cp what if i had
- 5:15multiple cores there
- 5:16well that's every time i have core i
- 5:18have to i'm sharing l3 i'm sharing
- 5:20memory but i'm distributing l1 and l2
- 5:23differently and my
- 5:23and and the and the alus are different
- 5:25as well so duplicate processors maybe
- 5:28double
- 5:28performance but not we're certainly not
- 5:30going to get to double but only
- 5:31the logical threads the hyper threading
- 5:33gives me 10 better performance
- 5:35multicore gives me arguably up to two
- 5:37times better performance
- 5:38and modern machines do both modern intel
- 5:41pieces of hardware
- 5:42intel architectures do both multiple
- 5:44cores with multiple threads per core
- 5:47so here's my laptop you go to the laptop
- 5:50you say syscontrol
- 5:51hw and you get this list and if you grep
- 5:54on
- 5:55these two lines you see it says hardware
- 5:57dot physical cpu
- 5:59four physically i got four cores
- 6:02hardware logical cpu
- 6:04eight nice and if you bring up activity
- 6:08monitor and i encourage you to do this
- 6:09on a mac bring up opportunity monitor
- 6:10you will see
- 6:11eight bars that tell you whether you're
- 6:14processing well in fact let me do this
- 6:16now i'm gonna go go rogue and try this
- 6:17and i'll probably have to edit this here
- 6:18out here but let me go and see if i can
- 6:20bring up activity monitor
- 6:22activity monitor here and let's see what
- 6:25happens
- 6:25this is a floating window from my
- 6:27activity monitor which shows
- 6:30eight different bars those eight bars
- 6:33are
- 6:35the eight logical cpus so even though i
- 6:38only have four cores in my machine
- 6:40i have eight bars of my activity monitor
- 6:42all up and down and all as i you know
- 6:44were to run a big quick time and maybe
- 6:46process this video using premiere pro
- 6:48all of them are going to be kind of
- 6:49pinned but it's really fun to watch this
- 6:51to make sure
- 6:52to see what the status of the eight
- 6:55logical cpus you have
- 6:56so again four cores but eight hardware
- 6:59threads
- 6:59total neat okay
- 7:03let's now take a look at the intel
- 7:05highest end
- 7:06as of this printing as of this recording
- 7:09which is the fall of 2020
- 7:10the intel w3275m
- 7:14processor this is a very expensive
- 7:16device this is a several multi-thousands
- 7:18of dollars you buy this thing
- 7:20it's 2 000 2 000
- 7:23to buy this upgraded cpu what are the
- 7:26things that we're going to look at on
- 7:27this
- 7:28number of cores 28 cores
- 7:32number of threads 56 there's hyper
- 7:36threading
- 7:36in action and what's our
- 7:39thermal design power how much power does
- 7:41this use
- 7:43200 watts this is this and what's the
- 7:45description the power displays when
- 7:47um under an intel defined high
- 7:49complexity workload so
- 7:50you're pounding on this with some big
- 7:52quick time or
- 7:54video processing something where all 56
- 7:58threads are all kicking in
- 8:01and you're using 200 watts imagine this
- 8:03little guy this little teeny guy using
- 8:05200 watts how to cool that
- 8:07is certainly a design challenge for the
- 8:08intel team neat
- 8:11so here's an example here's six cores 24
- 8:14logical threads
- 8:14each of those with hyper threads imagine
- 8:16a core with
- 8:18four times hyper threading there's no
- 8:19reason you couldn't have a design like
- 8:20that
- 8:21and so four logical threads per core
- 8:23this would be presented to the user as
- 8:2524 logical threads that you could
- 8:28actually process with
- 8:29pretty neat so
- 8:32we're almost done with this lecture
- 8:33definitions a thread is a sequence of
- 8:35instructions with its own program
- 8:36counter
- 8:37and processor state registered files and
- 8:39maybe a lot more registers than just the
- 8:40standard 32 we have
- 8:42within the space of multi-core a
- 8:45physical cpu
- 8:46is at the early days is a one at a time
- 8:48one threaded time in cpu
- 8:50and the software is going to be
- 8:51multiplexing bringing that back bringing
- 8:52that back in typically result
- 8:54to an i o event a stall some kind of
- 8:56blocking you pulled it in
- 8:57a logical cpu says you can now have
- 9:00perhaps
- 9:01more logical cpus than physical cpus
- 9:03with the idea of this
- 9:05and the bullet below says hyper
- 9:07threading model this hyper threading
- 9:08we saw for two for intel you know you
- 9:10couldn't have four or more if you're
- 9:11very clever in your engineering
- 9:13to have simultaneous multi-threading
- 9:15that means multiple threads
- 9:17multiple hardware threads on one core
- 9:19running at the same time pretty
- 9:20remarkable uh architectural feat to make
- 9:22that happen
- 9:24in conclusion sequential software
- 9:28execution speed is limited
- 9:292005 it basically flattened they're not
- 9:32turning the clock speed up anymore
- 9:33they're putting more transistors on the
- 9:35chip but nothing's helping me in my
- 9:36sequential app performance line so what
- 9:39do i got to do
- 9:39i better parallel pedal isn't the only
- 9:41other path to higher performance
- 9:43we saw simdee high performance cpus all
- 9:46have cmd you're all going to see that
- 9:48you're going to be able to have
- 9:49much wider vectors that you're operating
- 9:51on this floating point
- 9:52units um partially supported by
- 9:54compilers this is something
- 9:55we try to like get the compiler folks to
- 9:57get around to it um and it doubles the
- 9:59width roughly every three to four years
- 10:00so that's great
- 10:02so for the computational science folks
- 10:03they're like yes go simdi
- 10:05mimdi is the idea of thread level
- 10:08parallelism which we're talking about in
- 10:09these set of lectures
- 10:10multi-core processors it is supported by
- 10:12the os very cleanly
- 10:14unlike the simdi work as well because
- 10:15each of those is like a different
- 10:16particular
- 10:17technique to do it but mimdi is more
- 10:19more traditional
- 10:20um it needs processor
- 10:24programmer intervention as simdee did
- 10:26you gotta you jump in there with pragmas
- 10:27for the
- 10:28for the chimney you gotta figure out how
- 10:29to do this with mindy how to do this
- 10:30cleverly
- 10:31and roughly you're seeing a jump of
- 10:33about two cores every every two years
- 10:34which is quite interesting
- 10:35and i mentioned the intel w3275 has 28
- 10:39cores and 56 threads
- 10:40amazing and by the way we do both of
- 10:43them we turn our clock as much
- 10:45and by the way just fyi normally if you
- 10:48look at the
- 10:48scale of the intel recent intel xeon
- 10:51processors
- 10:52when you go to the 28 core model they
- 10:55turn their clock speed down to 2.5
- 10:57gigahertz
- 10:58if you go to a 20 core model it's a
- 11:00higher gigahertz if you go to an eight
- 11:01core model it's even higher so they're
- 11:02trading off
- 11:04fewer cores with higher clock speed but
- 11:06once you get to 28 cores it's the lowest
- 11:08clock speed of them all
- 11:09partly because you can't get the heat
- 11:10off of that you can't have high clock
- 11:12speed with 28 cores all chunky at the
- 11:14same time
- 11:14you got to give in a little bit and so
- 11:16as you have more cores you bring the
- 11:17clock speed down so if you have if
- 11:19you're on that if you're on a mac and
- 11:20you're only running a single core ever
- 11:21a single thread ever well you want to
- 11:23run different programs certainly but if
- 11:24you're never going to
- 11:25make use of that parallelism it might
- 11:27actually make sense for you to have a
- 11:28fewer cores
- 11:29but a higher clock speed for the
- 11:30particular applications you're doing if
- 11:32you're
- 11:32living large in the parallel space then
- 11:35go crazy with the 28 core machine with a
- 11:37lower overall clock speed which is very
- 11:38interesting thing
- 11:39okay so here's the key idea before we
- 11:42take you home with this last lecture
- 11:43the challenge is how do you craft
- 11:45parallel programs with high performance
- 11:47on multi-processors
- 11:49as the number of processors increase
- 11:50what software help can i have
- 11:52boy if i only had a lecture that would
- 11:54teach me how to be able to make use of
- 11:56all this is all about hardware this
- 11:56lecture not about software
- 11:58but how do i and from the software
- 12:00programming from c
- 12:01let's go back to the first lecture
- 12:02second lecture in c can you help me dan
- 12:05can you help me learn how to program
- 12:07these multiple core machines how do you
- 12:08even deal with how to control threads
- 12:10myself
- 12:11and the answer is thankfully yes there's
- 12:12some wonderful libraries that are coming
- 12:14around to make that easy
- 12:15and we're going to teach that in the
- 12:15next series of lectures and we'll see
- 12:17you there
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 33.4 - Thread-Level Parallelism I: Multithreading by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,373 words across 401 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 translate the transcript into 100+ languages.
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, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.