Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
DAN GARCIA
And welcome back. Up till now, all we understand is you've got a core. You've got a single hardware thread on that. That's all you know.
Let's actually talk about the idea of what multithreading is, and maybe you could have more than one thread per core. How would that even work? Let's think about that.
So typical scenario — active thread, you're working, and you've got a cache miss. Oh, we're going to Sacramento. You got to wait 1,000 cycles to go to DRAM.
So we know this already. We'll switch this out. A different thread's going to now run until the data is available. We've seen that already.
But what do we have? We got to save the current thread state and load a new thread state. PC, registers — it could be a lot.
The AVX could be a lot of registers, to say that. And you have to perform that switch in 1,000 cycles. You've got to be able to perform that switch in 1,000 cycles.
How does that even work? Can hardware help?
Can hardware somehow help the fact that I've got to switch threads in less than 1,000 cycles when the previous memory request came in and going to Sacramento to do a load or store word?
Here it is — hardware-assisted software multithreading. That's the title here, and here's the big idea. This is a really big idea, a very clever idea. You got one core.
Remember, one core. I'm fine, right? One core. Two threads.
Two hardware threads in one core. How would you make this happen? We'll take a look. I could have two different PCs.
Two different PCs, two separate registers. One ALU. Look at that. Transistors are cheap.
So I have copies of my PC and registers inside. This looks identical. Here's the key — from the software point of view, this looks like two different hardware threads.
It's one core. This is one core. It looks like two different hardware threads, okay? Pretty neat.
We call this, or actually, Intel came up with this name — Intel called it hyperthreading, because both threads can be active simultaneously.
And again, we still have one memory, but I have two threads in there, okay? Two hardware threads on one core.
Here's a slide from an — it's an Intel PR video explaining how this worked. In this picture, blue his idle. Just here, blue.
All these things that are blue, if you like blue, all these things here are blue are idle. So nothing's happening there.
And I've got, in the olden days, logically, in terms of physical processors, I still have one physical core — processor, one physical core, okay?
Logical processor is visible to the OS, if I just have one, and I have two threads, a red thread here and a green thread — then this is the red one, and this is the green one, if you're having trouble with color.
Here is the red one being loaded in, and here, oh, look, these resources. Maybe you have some resource can be used, two of them at the same time.
We've seen that before. Okay, now I've got this, and I'll be able to compute the red guy first. All that thread has to finish before the green guy finishes.
Here's the idea — could you actually run both at the same time if I have multiple resources? Maybe one's doing a load store, maybe one is doing the ALU.
That's two different parts of the same CPU. Couldn't you somehow run both of them at the same time? So that's the idea.
I'm going to have logically visible to the OS, there are two of them. And they're both being active at the same time. And sometimes, the resources are able to happen at the same time.
So all this blue — this is all the blue area that's idle. Notice there's less. All that time, basically the green guy's filling in some of those spots.
That's really, really neat. And what you see, the throughput is much, much higher in terms of throughput.
So in this model of simultaneous multithreading — multithreading means at the same time, two threads are working on one core — you have the number of logical CPUs greater the number of physical CPUs.
CPU means core here. So I've got one core, one physical CPU, maybe two logical CPUs, done, okay? So run multiple threads at the same time per core.
Each thread has its own state, PC, registers, et cetera, and we can share some resources, cache, instruction unit, execution units, and there's a whole group at University of Washington that has talked about simultaneous multithreading at the SMT group there.
So check that out. So here is multithreading, logical threads. A little bit more hardware, most of the same hardware, right? The ALU is the same ALU.
Well, I'll add some registers, add a PC. That's very little, and all of a sudden, I can have on one core two different hardware threads, pretty powerful.
Arguably, 10% or more better performance, because sometimes I'm kind of filling in the gaps when this guy is idle, or during one resource, I can fit another guy in there.
A lot of clever engineering has gone into it to figure out how to make these as efficient as possible.
So separate registers, and we saw that, but I'm sharing the datapath, I'm sharing the ALUs, and sharing the caches. But from the point of view of software, I don't care about that.
I still just see two different logical CPUs. We call them logical now to distinguish them from physical CPUs. So multicore is duplicate processors, 50% more. So that's the logical threads.
Multicore means, now, that's in one CPU. What if I had multiple cores there?
Well, that's every time I have core, I'm sharing L3, I'm sharing memory, but I'm distributing L1 and L2 differently, and the ALUs are different as well.
So a duplicate processor is maybe double performance, but not. We're certainly not going get to double, but the logical threads, the hyperthreading gives me about 10% better performance.
Multicore gives me arguably up to 2 times better performance. And modern machines do both. Modern Intel pieces of hardware, Intel architectures, do both — multiple cores with multiple threads per core.
So here's my laptop. You go to the laptop. You say sysctl hw, and you get this [BLOWING RASPBERRIES] list.
And if you grep on these two lines, you see it says, hardware dot physicalcpu — 4. Physical, I got four cores. Hardware logical CPU, eight.
Nice. And if you bring up Activity Monitor — and I encourage you to do this on a Mac. Bring up Activity monitor.
You will see eight bars that tell you whether you're processing — well, in fact, let me do this now.
I'm going to go rogue and try this, and I'll probably have to edit this out here. But let me go and see if I can bring up Activity Monitor, Activity Monitor here.
And let's see what happens. This is a floating window from my Activity Monitor, which shows eight different bars. Those eight bars are the eight logical CPUs.
So even though I only have four cores in my machine, I have eight bars in my Activity Monitor, all up and down and all as I — were to run a big QuickTime and then maybe process this video using Premiere Pro.
All of them are going to be kind of pinned. But it's really fun to watch this to make sure, to see what the status of the eight logical CPUs you have.
So again, four cores, but eight hardware threads total. Neat. Okay, let's now take a look at the Intel highest end as of this printing, as of this recording, which is the fall of 2020.
The Intel W-3275M Processor. It's a very expensive device. This is several multithousands of dollars. You buy this thing.
It's $2,000-plus to buy this upgraded CPU. One of the things that we're going to look at on this — number of cores, 28 cores.
Number of threads, 56. There's hyperthreading in action. And what's our thermal design power? How much power does this use?
200 watts. And what's the description? "The power dissipates when under an Intel-defined, high-complexity workload."
So pounding on this with some big QuickTime or video processing, something where all 56 threads are all kicking in, and you're using 200 watts.
Imagine, this little guy, this little teeny guy, using 200 watts. How to cool that is certainly a design challenge for the Intel team. Neat. So here's an example.
Here's six cores, 24 logical threads, each of those with hyperthreads. Imagine a core with four times hyperthreading. There's no reason you couldn't have a design like that. And so four logical threads per core.
This would be presented to the user as 24 logical threads that you could actually process with. Pretty neat. So we're almost done with this lecture.
Definitions — a thread is a sequence of instructions with its own program counter and processor state, register files, and maybe a lot more registers than just the standard 32 we have.
Within the space of multicore, a physical CPU is, at the older days, is a one-at-a-time, one thread at a time at CPU, and the software is going to be multiplexing, bringing that back in, typically resolve to an I/O event, a stall, some kind of blocking.
You pull that in. A logical CPU says you can now have, perhaps, more logical CPUs than physical CPUs. So the idea of this, the bullet below says, hyperthreading model.
There's hyperthreading. We saw two for Intel. There's no reason you couldn't have four or more if you're very clever in your engineering to have simultaneous multithreading.
That means multiple threads, multiple hardware threads on one core running at the same time. Pretty remarkable architectural feat to make that happen. In conclusion, sequential software, execution speed is limited.
2005, it basically flattened. They're not turning the clock speed up anymore. They're putting more transistors on the chip, but nothing's helping me in my sequential app performance line.
So what do I got to do? I better go parallel. Parallelism's the only other path to higher performance. We saw SIMD.
High-performance CPUs all have SIMD. You're all going to see that. You're going to be able to have much wider vectors that you're operating on these floating-point units.
Partially supported by compilers — this is something we're trying to get the compiler folks to get around to it, and that doubles it with roughly every three to four years, so that's great.
So for the computer science folks, they're like, yes, go SIMD. MIMD is the idea of thread-level parallelism, which we're talking about in these set of lectures, multicore processors.
It is supported by the OS very cleanly, unlike the SIMD work as well, because each of those is a different particular technique to do it, but MIMD is more traditional.
It needs programmer intervention, as SIMD did. You've got to jump in there with pragmas for the SIMD. You've got to figure out how to do this with MIMD, how to do this cleverly.
And roughly, you're seeing a jump of about two cores every two years, which is quite interesting. And I mentioned the Intel W-3275 has 28 cores and 56 threads.
Amazing. And by the way, we do both of them.
We turn our clock as much as — and by the way, just FYI, normally, if you look at the scale of the recent Intel Xeon processors, when you go to the 28-core model, they turn their clock speed down to 2.5 gigahertz.
If you go to a 20-core model, it's a higher gigahertz. If you go to an 8-core model, it's even higher. So they're trading off fewer cores with higher clock speed.
But once you get to 28 cores, it's the lowest clock speed of them all, partly because can't get the heat off of that.
You can't have high clock speed with 28 cores all chunking at the same time. You got to give in a little bit.
And so as you have more cores, you bring the clock speed down.
So if you're on if you're on a Mac, and you'll only be running a single core ever, a single thread ever — well, you want to run different programs, certainly.
But if you're never going to make use of that parallelism, it might actually make sense for you to have fewer cores but a higher clock speed for the particular applications you're doing.
If you're living large in the parallel space, then go crazy with the 28-core machine with a lower overall clock speed, which is a very interesting thing, okay?
So here's the key idea before we take you home with this last lecture. The challenge is, how do you craft parallel programs with high performance on multiprocessors as the number of processors increase?
What software help can I have?
Boy, if I only had a lecture that would teach me how to be able to make use of all — this is all about hardware, this lecture, not about software.
But how do I — and from the software programming, from C — let's go back to the first lecture, second lecture. In C, can you help me, Dan?
Can you help me learn how to program these multiple-core machines? How do you even deal with how to control threads myself? And the answer is, thankfully, yes.
There's some wonderful libraries that have come around to make that easy. And we're going to teach you that in the next series of lectures, and we'll see you there.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.