02 Principle of Locality

background image

University  of  Washington  

Sec3on  7:  Memory  and  Caches  

¢

Cache  basics  

¢

Principle  of  locality  

¢

Memory  hierarchies  

¢

Cache  organiza3on  

¢

Program  op3miza3ons  that  consider  caches  

 

Caches  and  Locality  

background image

University  of  Washington  

¢

Locality:

 Programs  tend  to  use  data  and  instruc3ons  with  

addresses  near  or  equal  to  those  they  have  used  recently  

¢

Temporal  locality:      

§

Recently  referenced  items  are  

likely  

 

to  be  referenced  again  in  the  near  future

 

¢

Spa3al  locality:      

§

Items  with  nearby  addresses  

tend  

 

to  be  referenced  close  together  in  7me  

§

How  do  caches  take  advantage  of  this?  

 

Why  Caches  Work  

block  

block  

Caches  and  Locality  

background image

University  of  Washington  

Example:  Locality?  

sum = 0;

for (i = 0; i < n; i++)

sum += a[i];

return sum;

Caches  and  Locality  

background image

University  of  Washington  

Example:  Locality?  

¢

Data:  

§

Temporal:  sum  referenced  in  each  itera7on  

§

Spa7al:  array  a[]  accessed  in  stride-­‐1  paBern  

sum = 0;

for (i = 0; i < n; i++)

sum += a[i];

return sum;

Caches  and  Locality  

background image

University  of  Washington  

Example:  Locality?  

¢

Data:  

§

Temporal:  sum  referenced  in  each  itera7on  

§

Spa7al:  array  a[]  accessed  in  stride-­‐1  paBern  

¢

Instruc3ons:  

§

Temporal:  cycle  through  loop  repeatedly  

§

Spa7al:  reference  instruc7ons  in  sequence  

sum = 0;

for (i = 0; i < n; i++)

sum += a[i];

return sum;

Caches  and  Locality  

background image

University  of  Washington  

Example:  Locality?  

¢

Data:  

§

Temporal:  sum  referenced  in  each  itera7on  

§

Spa7al:  array  a[]  accessed  in  stride-­‐1  paBern  

¢

Instruc3ons:  

§

Temporal:  cycle  through  loop  repeatedly  

§

Spa7al:  reference  instruc7ons  in  sequence  

¢

Being  able  to  assess  the  locality  of  code  is  a  crucial  skill  

for  a  programmer  

 

sum = 0;

for (i = 0; i < n; i++)

sum += a[i];

return sum;

Caches  and  Locality  

background image

University  of  Washington  

Another  Locality  Example  

int sum_array_3d(int a[M][N][N])

{

int i, j, k, sum = 0;


for (i = 0; i < N; i++)

for (j = 0; j < N; j++)

for (k = 0; k < M; k++)
sum += a[k][i][j];

return sum;

}

¢

What  is  wrong  with  this  code?  

¢

How  can  it  be  fixed?  

Caches  and  Locality  


Wyszukiwarka

Podobne podstrony:
02 Principle of Locality
Principles of Sigma Delta Conversion for Analog to Digital Converters
10 Principles of Marathon Training
Chapter 2 Principles of Stratigraphic Classification
Principles Of Corporate Finance
02 Crime Of The?ntury
Berkeley A Treatise Concerning the Principles of Human Knowledge
100 Greatest Leadership Principles of All Time
SHSBC053 PRINCIPLES OF AUDITING0961
Historia filozofii nowożytnej, 16. Berkeley - a treatise concerning the principles of human knowledg
Historia filozofii nowożytnej, 16. Berkeley - a treatise concerning the principles of human knowledg
principles of glottodidactics
Principles of system administra Nieznany
Basis Principles of FT NMR
Design Guide 02 Design of Steel and Composite Beams with Web Openings
Conan Sons of Cimmeria 02 Sons of Anshan
02 Parts of Speech DVD
[Mises org]Rostan,Jeremie T A Principles of Economics Study Guide

więcej podobnych podstron