Professional Documents
Culture Documents
Aditya Shah
Recitation 7: Oct 8th, 2015
1
Carnegie Mellon
2
Carnegie Mellon
Outline
Schedule
Memory organization
Caching
Different types of locality
Cache organization
Cache lab
Part (a) Building Cache Simulator
Part (b) Efficient Matrix Transpose
Blocking
3
Carnegie Mellon
Class Schedule
Cache Lab
Due this Thursday, Oct 15th.
Start now ( if you haven’t already!)
Exam Soon !
Start doing practice problems.
They have been uploaded on to the Course Website!
4
Carnegie Mellon
Memory Hierarchy
5
Carnegie Mellon
Memory Hierarchy
Registers
SRAM
We will discuss this interaction
DRAM
6
Carnegie Mellon
7
Carnegie Mellon
Locality
Temporal locality
Recently referenced items are likely
to be referenced again in the near future
After accessing address X in memory, save the bytes in cache for
future access
Spatial locality
Items with nearby addresses tend
to be referenced close together in time
After accessing address X, save the block of memory around X in
cache for future access
8
Carnegie Mellon
Memory Address
64-bit on shark machines
9
Carnegie Mellon
Cache
A cache is a set of 2^s cache sets
10
Carnegie Mellon
Address of word:
t bits s bits b bits
S = 2s sets
tag set block
index offset
v tag 0 1 2 B-1
valid bit
B = 2b bytes per cache block (the data)
11
Carnegie Mellon
4 5 6 7
8 9 10 11
12 13 14 15
12
Carnegie Mellon
Cache
Block b is not in cache:
8 9
12 14 3
Miss!
13
Carnegie Mellon
Conflict miss
Conflict misses occur when the level k cache is large enough, but multiple
data objects all map to the same level k block
E.g., Referencing blocks 0, 8, 0, 8, 0, 8, ... would miss every time
Capacity miss
Occurs when the set of active cache blocks (working set) is larger than
the cache
14
Carnegie Mellon
Cache Lab
Part (a) Building a cache simulator
15
Carnegie Mellon
16
Carnegie Mellon
17
Carnegie Mellon
If not running on the shark machines then you will need
#include <getopt.h>.
Better Advice: Run on Shark Machines !
18
Carnegie Mellon
19
Carnegie Mellon
char identifier;
unsigned address;
int size;
// Reading lines like " M 20,1" or "L 19,3"
22
Carnegie Mellon
23
Carnegie Mellon
1 2 3 4 1 5 9 13
5 6 7 8 2 6 10 14
9 10 11 12 3 7 11 15
13 14 15 16 4 8 12 16
24
Carnegie Mellon
25
Carnegie Mellon
Try different sub-matrix sizes.
26
Carnegie Mellon
j
c a b
=i *
27
Carnegie Mellon
= *
Afterwards in cache:
(schematic)
= *
8 wide
28
Carnegie Mellon
29
Carnegie Mellon
j1
c a b c
= i1 * +
Block size B x B
30
Carnegie Mellon
n/B blocks
First (block) iteration:
B2/8 misses for each block
2n/B * B2/8 = nB/4
(omitting matrix c) = *
n/B blocks
Second (block) iteration:
Same as first iteration
2n/B * B2/8 = nB/4
= *
Total misses:
Block size B x B
nB/4 * (n/B) = n /(4B)
2 3
32
Carnegie Mellon
34
Carnegie Mellon
Part (b)
Things you’ll need to know:
Warnings are errors
Header files
Eviction policies in the cache
35
Carnegie Mellon
Reasons:
Avoid potential errors that are hard to debug
Learn good habits from the beginning
36
Carnegie Mellon
Live example
man 3 getopt
37
Carnegie Mellon
38
Carnegie Mellon
Style
Read the style guideline
But I already read it!
Good, read it again.
39
Carnegie Mellon
Questions?
40