Lesson 3 4 Cache Oblivious Algorithms: The Ideal Cache Model
Lesson 3 4 Cache Oblivious Algorithms: The Ideal Cache Model
Inacacheawarealgorithm,thevalueofLisdeterminedbythecachesize.
Q
(nzL)= (n/L)
aware
Ifthealgorithmmakesnoreferencetofastmemoryoritsparameters(z,L)thenthealgorithm
isoblivious(tofastmemory).
Q
(nzL)=O(n/L)
oblivious
Therearetwoquestionsthatneedtobeasked.
1. Howdowemodelautomaticfastmemory?
2. CananobliviousalgorithmmatchI/Operformanceofanawarealgorithm?
TheIdealCacheModel
Thisistheidealcachemodelthatwillbeusedin
thelesson.
TheListhesameasthetransfersize.
Inaprogramloadsandstoresareissuedfortheslow
memoryaddress.
Forexample:
Theprogramwantstoloadavaluefrommemorya.
Firstitcheckstoseeifthevalueofaisinfastmemory.
Ifitis,itjustusesitthisisacachehit.
Acachemissoccurswhenthevalueisnotinthe
cache.Thenitmustberetrievedfromslowmemory
andacopyisstoredinfastmemory.
Thehardwaremuststoreanentirecachelineofdata,soothermemoryvaluesaroundthe
desiredmemorylocationwillalsoberetrievedandstoredfrommemory.
Forastoreinstruction:
Ifthevalueisinthecache,itisacachehit.Thevaluewillbeupdatedinthecacheandstoredin
slowmemory.
Ifthestorevalueisnotinthecache,thisisacachemiss.
Foracachemisstheentirememorylinemustbetransferredfromslowmemorytothecache.
Theidealcacheisfullyassociative.
Thismeansthetransferfromslowmemoryisallowedtogo
toanylineinthecache.
Atsomepoint,thecachewillbefull.Sotoloadanewline,anoldlinewillhavetobeevicted
fromthecache.
Ifthelinethatistobeevictedhasnotbeenwrittentomemory,itisdirty.Adirtylinemustbe
writtenbeforeitcanbeevicted,thisiscalledastoreeviction.
Optimalreplacementevictlineorblockaccessedfurthestinthefuture.
SummaryofIdealCacheModel
1. Programissuesloadandstoreops
2. HardwaremanagesZ/Lcachelines
3. SlowmemorycachetransfersinlinesorblocksofsizeL
4. Accessingavalueincache=cachehit,otherwiseitisacachemiss
5. Cacheisfullyassociative
6. Assumeoptimalreplacementpolicy
Q(nZ,L)=#misses+storeevictions
LRUleastrecentlyused
Thisreplacementpolicylooksfortheleastrecentlyusedaddresstoevictfromthecache.
LRUwillcausemoreevictionsthatoptimalreplacement.
Howidealistheidealcache?
Keyassumptions:
1. optimalreplacement
2. twolevelsofmemory
3. Automaticreplacement
4. fullyassociative
TakeacachemodelthatusesaLRUpolicy.Compare
ittoacachethatusesanoptimalreplacementpolicy
thathasthecachesize.
Thislemmacanbeusedinthefollowingway:
Designanalgorithmonanidealmodelwithoptimalreplacement.Itshouldbeasymptotically
closetoamodelwithanLRUpolicyandtwicethecache.
Ifyoudesignanalgorithmforanideal
model,ifthemissesareregular,itwill
performinasimilarfashiontotheideal
model.
TheTallCacheAssumption
Thecacheshouldbetaller(withregardstothenumberoflinesz)thanitiswide(thesizeof
thelines,L).
Thismeansanefficientalgorithmmightbelinkedtothechoiceofdatastructure.