Lesson34CacheObliviousAlgorithms
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
[Link]
andacopyisstoredinfastmemory.
Thehardwaremuststoreanentirecachelineofdata,soothermemoryvaluesaroundthe
desiredmemorylocationwillalsoberetrievedandstoredfrommemory.
Forastoreinstruction:
Ifthevalueisinthecache,[Link]
slowmemory.
Ifthestorevalueisnotinthecache,thisisacachemiss.
Foracachemisstheentirememorylinemustbetransferredfromslowmemorytothecache.
Theidealcacheisfullyassociative.
Thismeansthetransferfromslowmemoryisallowedtogo
toanylineinthecache.
Atsomepoint,[Link],anoldlinewillhavetobeevicted
fromthecache.
Ifthelinethatistobeevictedhasnotbeenwrittentomemory,[Link]
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
[Link]
ittoacachethatusesanoptimalreplacementpolicy
thathasthecachesize.
Thislemmacanbeusedinthefollowingway:
[Link]
closetoamodelwithanLRUpolicyandtwicethecache.
Ifyoudesignanalgorithmforanideal
model,ifthemissesareregular,itwill
performinasimilarfashiontotheideal
model.
TheTallCacheAssumption
Thecacheshouldbetaller(withregardstothenumberoflinesz)thanitiswide(thesizeof
thelines,L).
Thismeansanefficientalgorithmmightbelinkedtothechoiceofdatastructure.