Computer Assignment 2
代做project | assignment – , 该题目是值得借鉴的assignment代写的题目
Fall 2022 (Upload it to Gradescope.)
Here are some general guidelines: YoushoulddoallyourworkintheC++programminglanguage.Yourcodeshould bewrittenusingonlythestandardlibraries.Youmayormaynotdecidetouse classesand/orstructs towrite yourcode.Regardless ofthedesign,yourcode should be modular with well-defined functions and clear comments. Youarefreetouseasmanyhelperfunctions/class/definitionsasneededinyour project. Thereisnorestrictiononwhatdatatype(e.g.,int,string,array,vector,etc.)you want to use for each parameter. Unfortunately,experiencehasshownthatthereisaveryhighchancethatthere areerrorsinthisprojectdescription.Theonlineversionwillbeupdatedaserrors are discovered, or if something needs to be described better. It is your responsibilitytocheckthewebsiteoftenandreadnewversionsofthis project description as they become available. Sharing of code between students is viewed as cheating and will receive appropriate action in accordance with University policy. You areallowed to compareyourresultswithothersordiscusshowtodesignyoursystem.Youare alsoallowedtoaskquestionsandhavediscussionsonCampuswireaslongasno code is shared. Youhavetofollowthedirectionsspecifiedinthisdocumentandturninthefiles and reports that are asked for.
Project Description
Overview
In computer assignment 2,we want to design a cache/memory controller.You are responsible for designing the memory controller.
Theinputtoyourmemoryisa32-bitaddress.Yourcodeisresponsibleforloadingthe datafromthememory(ifitisanLW)orstoringthevalueatthecorrectaddressifitis anSW.Askeletoncode(memory_driver.cpp)isprovidedtoyouforinitializingthe variables, creating the cache objectand main memory array, reading a trace, and passingtherelevantinformationtoyourmemoryhierarchy.Youarefreetochangethis skeleton as you see fit!
(Changes to this file will be shown in red.)
Yourmemoryhierarchy hastwolevelsofcacheandthemainmemory (i.e.,thesame array/vector you used in Project 1).
YourL1cacheshouldbeadirect-mappedcachewith 1 blockperlinewithatotalof 16 lines/sets. Each block in our cache should be 4 bytes (i.e., an int). It is your responsibility to correctly calculate the index, block offset, and tag in your code.
YourL2cacheshouldbean8-wayset-associativecache.Eachblockshouldbestill 4 bytesandthereshouldbe 1 blockperline(sameasL1).Thereshouldbe 16 setsforL2. Sameasabove,yourcodeshouldcorrectlycomputetag,index,andblockoffset. Your main memory has 4096 lines each one 4 bytes.
SinceL2isusingSAcache,youshould use LRUreplacementpolicy (L1isDM,sono replacement policy is needed).
Your cache design should beexclusive/write-no-allocate/write-through. You should assume that your cache is initially randomly initialized with all valid bits equal to zero.
Trace
Eachlineinatracehasfourvalues(MemR, MemW, adr, data).Thefirsttwoare eitherzerooroneindicatingwhetherthisisaLOADinstructionorSTORE(alwaysonly oneofthemwillbeequaltoone).Theaddressisanumberbetween 0 and 4095 (youcan safelyassumethis),andthedataisasignedintegervalue.Thecodealreadyreadthe trace line by line and stores the values in an array calledmyTrace.
In the main loopof thedriver code, eachentry isread one-by-oneandshouldbe handled by your memory hierarchy.
Asmentionedbefore,youcanassumethatyourcacheandmemoryareinitiallyempty (with random values) and we first store things before reading anything.
Wehaveprovidedonesimpletracefile,butwewilladdmoresoon.SameasCA1,your code will be tested with multiple different traces on Gradescope. We strongly recommend creating your own traces and testing your code using those.
(Changes to this file will be shown in red.)
Design
Theentryforyourcodeisyourmemorycontroller(controller)whichiscalledina loopinthemain functionofmemory_driver.cpp.Foreachiteminthetrace,this controllerfunctionshouldbecalled,andappropriateactionsshouldbetaken.Apart from these actions, you should also update stats in this controller. We strongly recommendaddingmorefunctionstoyourcacheobjectforeachaction(e.g.,search, update, evict, etc.)
Thecontrollershouldfirstcheckwhetherthisrequestisloadorstoreandthenfollow analgorithmforeach.Forload,thecontrollershouldfirstsearchL1,thenL2.Ifdatais notfoundineither,datashouldbebroughtfrommemory(rememberthatthereisno miss inmainmemoryandtheaddressprovidedinthetraceistheindexforthemain memory array).
Oncedataisfound,youshouldmakesureto (1) Updatethestatsforeachcache,and (2) Update data, tag, and LRU positions if needed.
IfdataisinL1,youjustneedtoupdateLRUandstats.IfitisinL2,youshouldbring datatoL1(andremoveitfromL2)andupdateLRU,data,andtag.Ifitisinneither,data shouldbebroughtfrommemoryandinstalledinL1(updateLRU,tag,data),theevicted datafromL1shouldbeplacedinL2(shouldbeputasmostrecentlyused),andevicted data from L2 should be removed.
If it is a store, you should do similar things, but remember that we use a write-no-allocatewrite-through strategy(i.e.,ifdataisinbothcacheandmemory,both should be updated. If it is not in the cache, only memory should be updated.) Remember that you need to search both caches for the store same as the load.
Cache Driver Code and Benchmarks:
Theentrypointofyourprojectismemory_driver.cpp.Theprogramshouldrun like this: ./memory_driver <inputfile.txt>,
Yourprogramshouldprintthemiss-rateforL1andL2,aswellastheaverageaccess time(AAT)ofthesystemintheterminal.ForAAT,youcanassumethatthehittimefor L1is 1 cycle,forL2is 8 cycles,andformainmemoryis 100 cycles.Youarefreetoadd more stats in your code if needed.
(Changes to this file will be shown in red.)
We will provide an additional trace file (or maybe two) with the ground truth.
Sameasthepreviousproject,itisyourchoicehowyouwanttostructureyourcode (e.g., whether you want to have separate objects for each class, or you want to instantiateanobjectwithinanotherclass,orevennotuseanyclassatallandutilize functions and structs, etc.).
What to submit.
You need to submit the following files on Gradescope.
- Yourwell-commentedcode(allthefilesDONOTputitunderafolder).Note thatwewillusedifferenttracestotestyourcodescorrectness.Yourcodeshould becompiledwiththefollowingcommand:g++*.cpp-omemory_driver.Ifthe codefailstocompile,youwilllosepoints.Yourcodeshouldproducetheresults exactlyashard-codedinyourskeletoncode.Failingtocreatethatformatwill result in losing points.