Video
Đăng bởi Quản trị viên OpenER ·
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ả.
PROFESSOR
And welcome back. Now let's actually think about what happens under the hood. So we talked about the software level.
So we're talking about parallelism in many ways, and now we're saying, okay, we've handled the C part. We know how to do OMP, OpenMP. You know how to handle race conditions.
You know what deadlock is and how to grab semaphores in locks. What actually happens with the issue of level one, level two, level three caches. Level 3 is maybe shared.
Memory is shared. Level one and level two are separate. What happens when you have shared memory in caches. This gets a little bit more complicated.
So let's actually look at the hardware side of this, what's actually happening. So this is on a chip. I've got my CPUs, my cores. Each of them has a memory bus.
I've got other devices. I've got main memory.
And in a model that is symmetric multiprocessor — so this is a memory of a multicore machine, two or more identical cores — I've got a single shared coherent memory.
So again, each of these guys above this line, above the memory bus, are my cores, and the below the line is the memory that I'm sharing, and each one might have various levels of caches that are shared or not shared, depending.
This is a general question for any computing system, any multiprocessor system. This isn't just this particular one CPU how to do this.
It might be how do I have two different chips, and how do they communicate. It might be worker bees doing something. Question one is how do they share data.
How do these guys share data back and forth? How do they coordinate their operations, and how many processes can be supported. How big can we go?
How wide can I go in terms of the number of helpers I have? In SMP, or shared memory multiprocessors, what we've been talking about all along, I have a shared address space.
So we mentioned that before. The first slide, I showed you memory is shared.
0 to 4 GB if shared among all of them, and they're going to communicate via these shared variables in memory via loads and stores. That's the only way for me to work.
You have to then synchronize that some way, and we talked about hardware synchronization, or locks, to be able to make sure you're not having to people think that they have write control over that, and that's great.
And all multicore computers now are SMP, or shared memory multiprocessors. Caches. So caches becomes the really interesting thing. You knew that memory was a performance bottleneck.
That's not new information. Memory was going to Sacramento. Even with one processor, that was a trouble.
We brought in caches to reduce that pain and to reduce the bandwidth demands on main memory, which is nice.
Even back in the olden days, we had two data instruction caches so that both of them could be hit at once, and that's great. It's almost like you're parallelizing using this.
You're being able to have them both be used in the same clock cycle. We've learned that.
The PC can be looking up some new value, the rising edge of the clock, and you go grab a new — what's the new instruction? I don't know.
Where is it? Well, go point in memory. Well, do I have to go to Sacramento? No, because it's in my instruction level one cache.
Great, boom. At the same time, I might be asking, I'm doing a load word. I'm reading from data cache, the same exact instruction. I'm doing those at the same time.
Great.
I might be at the fourth stage of doing a load word, and I'm at the first stage of the next guy, and they are the same line, and they both can happen at the same time.
We already know that you can sometimes split caches to be able to work at the same time without having a resource bottleneck. We've seen that already.
Each core has a private cache. We've known that already. We know that already.
Only when you have a miss do you need to go past the cache to go into the shared space. You're in your local stuff. We know at least L1, L2.
I'm here, and only when I miss that do I need to go, and maybe there's some more complexity of a shared L3. Forget L3 for a moment. I need to worry about memory.
For now, we're just going to say this, one local cache and then there's one memory. Let's make it easy.
The same problems come up with L1, and L2, and L3, but let's talk about just having one cache and memory, and only when I miss my cache will I need to go to memory, and now it's this shared space.
So think about this. Here's the simplest case. Everybody has their own cache.
Again, maybe the L1 and L2 here, and I don't remember the L3 for now, and they all have to go through the interconnected memory to get to the shared space of memory.
So that's all the same. So now let's actually do a simple case. Processor 1 and 2. Just reads for now, easy, easy, easy.
Processor 1 and 2 read memory location 100, and they want to get the value 20. So let's actually animate this. This is kind of fun. So here's processor 1.
Address is 1000, memory value of 1000. So there we go. Is it in my cache? No, it's not.
So I go to memory. I grab it. What's its value? 20.
I come on back, and I go back and I put it in my cache for future reference, and I remember that at 1000, I've got a 20, and we're good.
Processor 2 does the same thing. You can already see that there might be an optimization where processor 2 could look in processor 1's cache, but we don't have that place.
Then we have to go through memory. That's the only way to communicates for now. So the same thing happens. Processor 1 says, I want to read the value memory of 1000.
I think it's a 20, but I don't know. I want to get the value. Again, check the cache. It's not there.
Go to memory, grab it, and come on back, and 20 is there, and I remember it's 1000. So good. So far, so good. Everything is fine, and each one has a copy.
So this is the issue. Each one now has a copy. There wasn't an issue before.
Before, it was an issue of do we do a write back or write through in terms of keeping our cache and memory synchronous? We allowed it to be asynchronous.
So that allowed it to get kind of stale. We have a dirty bit for that.
But now you've got an issue that both of them have a copy, which is fine as long as it's the same value. What happens if they change?
So now what happens if processor 0 comes around and writes memory 1000 with a 40? Here we go. Let's try it. So we've got 1000.
Is it in the cache? Nope, not there. So write it in the cache, and in this particular situation, we're going to have a write through.
So we're going to actually have to write it all the way through. We're not going to write back where we keep them stale and have it be dirty.
I'm going to say write through. So now there's my 1000 40. That's great. Note that processor 1 and 2 have their 20, which is the wrong value.
And then, yoink, I write it through. You told me to write it through. I'm processor 0. What do you want from me over here?
I write it through. Can you see a problem? Anybody see a problem? Wait, let's just pause here.
Everyone should see a problem here. Processor 0 says, hey, the value at 1000 is 40. Processor 1 and 2 say, nope, it's 20. That's a really big deal.
That's the end of this lecture. I love the cliffhanger. That's kind of a cliffhanger approach like Mandalorian. What happens to Baby Yoda?
So with that, we're staring at the cliffhanger here. What happens? How do we resolve this? That's the next lecture.
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.