[CS61C FA20] Lecture 27.1 - Caches IV: Set-Associative Caches — Transcript
Full transcript
- 0:00and welcome back in this final series of
- 0:03lectures
- 0:03let's learn a little bit about initially
- 0:06what a set associative cache is
- 0:08it's the cache that lives somewhere in
- 0:10the middle between a fully associated
- 0:11cache where you can sit anywhere
- 0:13and a direct map cache we have a ticket
- 0:14for your seat and you sit exactly there
- 0:16so somewhere in the middle where you
- 0:17might sit in first class business class
- 0:19and coach
- 0:20within those areas you might sit
- 0:22anywhere but you're kind of set into a
- 0:24set that's the idea
- 0:26so an n way set associative cache means
- 0:29n
- 0:29means the number of blocks that are in a
- 0:31set so
- 0:32you have a tag as before you have an
- 0:34offset as before offsets the number
- 0:36what column you're in what byte or what
- 0:37board you're getting the index now
- 0:39points to the correct what we call quote
- 0:41unquote row
- 0:42or a set so that set has n items so it's
- 0:45two ways
- 0:46two way set associated would mean
- 0:47there's exactly two blocks that live in
- 0:49that set
- 0:51that's the idea each set contains
- 0:53multiple blocks once we're in that set
- 0:55they're fully associated within a set
- 0:57and we have to then check
- 0:59all the tags in some kind of parallel
- 1:00comparator to do that but
- 1:02at small scale that's doable at a large
- 1:03scale that's hard to do hard to build
- 1:05so the overall size of a cache
- 1:08is the number of rows what's the rows
- 1:10now the number of rows is
- 1:12the number of sets so the index bits
- 1:15tells you the number of sets
- 1:16and then times n where n is the number
- 1:19of blocks per set
- 1:20you multiply sets times blocks per set
- 1:22you get blocks that's the number of rows
- 1:24total right the number of blocks that
- 1:27times the width which is the offset bits
- 1:30and the two to the offset bits and
- 1:31that's your that's your cache size so
- 1:33very same similar before but just now
- 1:35each rather than directly going to a
- 1:37spot
- 1:38you're going to a set and you're in
- 1:39you're fully associative within that set
- 1:42so here's a two-way set associative
- 1:46cache example notice we have here red
- 1:49and green and zero one zero you know
- 1:52zero one two three four there and now if
- 1:54you watch
- 1:56any red can go to any one of the two red
- 1:59positions so if i happen to
- 2:00want in this exact perfect example the
- 2:02whole ping-pong effect
- 2:04in the direct map example when i copied
- 2:06from zero to four
- 2:07if you remember zero and four i can grab
- 2:09my pin here if you remember zero and
- 2:11four
- 2:11used to be used to be the same color it
- 2:14was blue
- 2:15so if i were copying if i only had let's
- 2:17say a set that had one block
- 2:20if i were copying from zero to four i
- 2:21wouldn't be taking advantage of my cache
- 2:23at all
- 2:23because i'd be kicking it out here's
- 2:25zero and then here's four and then
- 2:26here's zero and four
- 2:27and i wouldn't ever be kind of making
- 2:28use of it if i were walking along let's
- 2:30say it's a really long block a really
- 2:32wide block so my cache is
- 2:34small but wide the aspect ratio was like
- 2:36that and i were kind of streaming across
- 2:38copying from one array to the other very
- 2:39common piece of code copy from this you
- 2:41know duplicate an array very common
- 2:42thing to do
- 2:44i'd be killed if i weren't able to
- 2:46somehow capture
- 2:47both the red areas if both of them were
- 2:49blue i wouldn't be able to have both
- 2:51blue and my cache at the same time
- 2:53if you imagine a really big one that's
- 2:54terrible here even a two-way set
- 2:57associative solves that problem so
- 2:59two sets two blocks in the set we're
- 3:01really happy with this i didn't even say
- 3:02it this particular doesn't say
- 3:03picture doesn't say how wide what the
- 3:05block size is but
- 3:06we don't care we're just talking about
- 3:08how how it works
- 3:10the basic idea again cache is direct map
- 3:13with respect to the sets the index tells
- 3:16me exactly what set i'm in
- 3:17within that i'm fully associative within
- 3:19the end blocks in that
- 3:21set for an n-way set associative cache
- 3:23so again let's do it
- 3:25find a correct set using the index value
- 3:27compare the tags with everybody in there
- 3:28because now
- 3:29i'm pretending to be fully associative
- 3:31i'm in here if a match occurs great
- 3:33otherwise i have a miss um and
- 3:36finally again as always grab the offset
- 3:38bits to figure out what word or what
- 3:39bite i'm requesting
- 3:40easy so it's great i think i kind of
- 3:43mentioned this even a two-way set
- 3:44associative
- 3:45handles all those conflict misses that
- 3:47copying from a blue to a blue
- 3:49is great now in the earlier case copying
- 3:51from a red to red or green or green i
- 3:52can fit both reds or both greens there
- 3:54so that kind of
- 3:55copy from one to the other really help
- 3:57even more for two-way even just
- 3:59moderately allowing for two-way just a
- 4:00little dribble here's direct mapped
- 4:03one step over is two-way by the way n
- 4:05almost universally is a power of two
- 4:07it's four away eight-way
- 4:0816-way in general okay and again
- 4:10hardware isn't that bad only need
- 4:11n comparators so two comparators which
- 4:13is great so
- 4:15sorry i couldn't hear what you said
- 4:17thank you so much siri
- 4:18well i said what i'm saying is if it's
- 4:20direct
- 4:21it's a one-way set associated just make
- 4:23sure i tell you that if it's if
- 4:25if so here's this knob and this knob
- 4:27says um
- 4:28if i turn the knob all the way for m for
- 4:32m
- 4:32blocks let's say i have m blocks total m
- 4:34blocks
- 4:35well one way if i say i'm
- 4:39one way set associative that really
- 4:41means direct mapped
- 4:42so one way set associative is direct
- 4:44mapped and
- 4:46m way means that m blocks can occur in
- 4:49m slots that's fully associative so that
- 4:52knob really goes if i have total m
- 4:54the total height of my catch is m when
- 4:56the knob goes this way it's
- 4:58one and therefore i'm direct mapped goes
- 5:00all the other way it's now
- 5:01m i'm now fully associative that makes
- 5:03sense and so
- 5:04these are these are both special cases
- 5:06of the more general case which is this
- 5:08so this is actually more general case
- 5:09which is kind of nice
- 5:10and this is the dynamic slide this is
- 5:13the last slide on this
- 5:14this lecture i love this slide let's do
- 5:17it together let's walk it through
- 5:18together i think i did this earlier
- 5:19but this is great for a four-way set
- 5:21associative cache here's how that works
- 5:23how do we start i don't know how to
- 5:25start divide it up into the fields
- 5:28tag offset uh uh tag index offset to
- 5:31don't remember teodan
- 5:32grab my index and tell me what
- 5:36set i'm in not what row i'm in in terms
- 5:38of okay no not one block i'm in
- 5:40what set i'm in and here i've drawn here
- 5:42has drawn rather than kind of draw red
- 5:44red green green
- 5:45you know whatever i do this way i draw
- 5:47them across so
- 5:48this here these four guys
- 5:51there is my set that's my four in my set
- 5:55and now this happens in parallel watch
- 5:58what happens
- 5:59well let's do our same thing we've seen
- 6:00this before we've seen our tag
- 6:02and and valid bit comparison all that's
- 6:06done
- 6:06and this is what's really fun about this
- 6:08if we kind of we can even i think i can
- 6:09even do this
- 6:10i can even zoom in let me try that
- 6:13i can even zoom in look at this on this
- 6:17and let's see what's happening at the
- 6:18bottom here this is fun
- 6:21so what's happening at the bottom is
- 6:23each of these is did it match
- 6:24so each of those are comparators did it
- 6:26match does the tag match and is it valid
- 6:28because we didn't remember don't forget
- 6:30the valid bit you could have garbage
- 6:31there that happens to match the tag
- 6:32that's that would be really uncool
- 6:34now do i have a hit sure it's an or
- 6:37of all four of those lines so that makes
- 6:40sense
- 6:41now here's the interesting thing this is
- 6:42let me zoom back a little bit
- 6:44this is the actual data if you remember
- 6:46the data used to go through a mux
- 6:48being chosen by whatever uh whatever
- 6:51bits
- 6:52of the of the whatever
- 6:55bits of the offset were being used to
- 6:59grab the particular
- 7:00the particular um word i think it was
- 7:03the word i was grabbing at the time do
- 7:04you remember that
- 7:05um so that was there in a four it was a
- 7:07mux that chose those two bits to choose
- 7:09what word i was grabbing
- 7:11here this data is coming through
- 7:14and it goes to a four to one mux but
- 7:16rather than being driven by
- 7:17two signals it's going to be driven by
- 7:21four signals and those four signals
- 7:23we're going to call let me zoom back
- 7:24fully
- 7:25we're going to call that one hot and one
- 7:28hot is exactly as you might imagine it's
- 7:30a set of lines
- 7:31n lines in which i promise you the spec
- 7:34is on this one hot system
- 7:36only one of those will ever be one at a
- 7:38time they'll all be zeros by default
- 7:40and when when you want to drive the
- 7:43second one then this would go high but
- 7:44everyone else would go quiet
- 7:46so only one is ever hot or one ever
- 7:49and if that's the case and you by the
- 7:50way i really encourage you to think
- 7:52about how you might wire a four to one
- 7:53comparator
- 7:54if i did this so rather than having two
- 7:55bits that select that i have this one
- 7:58hop model in which whenever
- 8:02one of those lines goes hot which means
- 8:04it is both valid
- 8:05and the tags matched that's what chooses
- 8:08so let's say it's
- 8:09the rightmost one let's make this one
- 8:10here well when that goes high it says
- 8:13well
- 8:13probably that came what are that line
- 8:14frame from that came from the rightmost
- 8:17guy
- 8:17that means that matched well then that
- 8:20means that means
- 8:21this would get passed through to the
- 8:24output
- 8:25okay and similarly for the other four so
- 8:27the idea of a one hot
- 8:30signal line for my mux is just another
- 8:32way to drive the mux
- 8:33and i do encourage you to be able to sit
- 8:34back how about it might be on a final
- 8:36exam
- 8:37where you might have a situation i want
- 8:39to show you tell me how to build a one
- 8:41hot um signal line for uh
- 8:44two to one mux or four to one mux or
- 8:46eight to one mux think about how you do
- 8:48that if i have
- 8:49a one by the way just in general if i
- 8:51have a one hot line i have to have the
- 8:52number of
- 8:53signal lines at the control lines equal
- 8:55to the number of input lines
- 8:57so notice i have four here four to one
- 8:59and i have
- 9:00four of these because only one of them
- 9:01is going to be hot and that one drives
- 9:03the guy that ends up
- 9:04driving the the bridge we always talk
- 9:06about this being a bridge and it's like
- 9:07four roads converging on one bridge
- 9:09because the bridge is out or they're
- 9:10repairing a side of it so
- 9:11that's the idea okay so that's n-way set
- 9:15associative in this particular example
- 9:16for
- 9:17the hardware the actual circuits of
- 9:20block diagrams of a four-way set
- 9:22associative
- 9:22we'll talk about other set associativity
- 9:25and other components of caches in the
- 9:26next lectures see you there
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 27.1 - Caches IV: Set-Associative Caches by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,981 words across 307 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.