首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代写program、C++程序设计代做
项目预算:
开发周期:
发布时间:
要求地区:
Lab 3: Cache Simulator
Due: Nov 3, 2023 11:59PM EST
In this lab assignment, you will implement a two-level (L1 and L2) cache simulator in C++. The
cache simulator will take in several parameters as input to configure the cache (block size,
associativity, etc.) along with a memory address trace file as input.
Cache System
Here is an example diagram of a two-level cache.
L1: Two-way set associative cache with a block size of 4 bytes.
L2: Four-way set associative cache with a block size of 4 bytes.
L1 L2
set 0 block 0 set 0
set 1 set 1 block 1
set 2 set 2
set 3 set 3
way 0 way 1 set 4
set 5
set 6
set 7
way 0 way 1 way 2 way 3
In general, a cache can be thought of as an array of sets where each set is a pointer to an array of
ways. The size of each way is determined by the block size. You can consider a direct-mapped
cache as a “one-way” set associative cache (i.e., having many sets with each set having exactly
one way) and a fully associative cache having a single set with many ways.
Here’s a closer look of block 0 (L1) using 4 Bytes per block.
Byte 0 Byte 1 Byte 2 Byte 3 tag dirty valid
We will assume L1 and L2 have the same block size.
Since we are simulating cache operations, we will not consider actual data (i.e., the Bytes in the
above figures) when testing inputs. You only need to model the accesses to capture hit and miss
behavior, tracking all data movement and updating caches (with addresses) properly.
Address
An example of an address used in the cache (MSB → LSB):
tag index offset
↔ ↔ ↔
The index is used to select a set (i.e., a row in the above table). The tag is used to decide
whether it “hits” in one of the set’s ways. The offset is used to pick a Byte out of a block.
Cache Policy to Implement
● (Exclusive) the L1 and L2 are exclusive. [Reference]
● For a W-way cache, the ways are numbered from {0,1, 2, …, W-1} for each set. If an empty
way exists (i.e., the valid bit is low), data is placed in the lowest numbered empty way.
● (Eviction) When no empty way is available, eviction is performed using a round-robin
policy. To select an eviction Way#, there is a counter initialized to 0 that counts to W-1 and
loops back to zero. The current value of the counter indicates the Way from which data is to
be evicted. The counter is incremented by 1 after an eviction occurs in the corresponding set.
Note that there is a counter for every set in the cache.
Read Miss: on a read miss, the cache issues a read request for the data from the lower level of
the cache.
● Tips for Read:
o Read L1 hit: easy case, the data is available
o Read L1 miss, Read L2 hit: first set the L2 valid bit low; the cache block is moved
from the L2 cache to the L1 cache.
▪ What if L1 is full? Evict a block from L1 to make space for the incoming data.
Evicted L1 block will be placed to L2. What if L2 is full? Similarly evict a
block from L2 before placing the data.
▪ “first set the L2 valid bit low”:
1. At first the hit block is kicked out from L2 (thus it gives us an empty
space of L2); after that you can continue to check if L1 is full (and if L2
is full).
o Read L1 miss, Read L2 miss: read request for main memory; data fetch to be used and
stored in L1. Again, what if L1 is full? Eviction.
Eviction follows the round-robin policy mentioned above.
● Tips for Eviction:
o Evicting from L1: evicted data must be placed into L2 (this might trigger an L2
eviction!)
o Evicting from L2 for incoming data: check L2 dirty bit first
▪ if the dirty bit is high, evict L2 data to main memory
▪ otherwise, no need to write main memory; simply overwrite L2 with incoming
data
Write Hit: both the L1 and L2 caches are write-back caches.
Write Miss: both the L1 and L2 caches are write no-allocate caches. On a write miss, the write
request is forwarded to the lower level of the cache.
the cache.
● Tips for Write:
o Write Hit L1: set the dirty bit high in the L1 cache
o Write Miss L1, Write Hit L2: set the dirty bit high in the L2 cache
o Write Miss L1, Write Miss L2: write data directly to main memory
Configuration File (cacheconfig.txt):
The parameters of the L1 and L2 caches are specified in a configuration file. The format of the
configuration file is as follows.
● Block size: Specifies the block size for the cache in bytes. This should always be a
non-negative power of 2 (i.e., 1, 2, 4, 8, etc.). Block sizes will be the same for both
caches in this lab.
● Associativity: Specifies the associativity of the cache. A value of "1" implies a
direct-mapped cache, while a "0" value implies fully-associative. Should always be a
non-negative power of 2.
● Cache size: Specifies the total size of the cache data array in KiB.
An example config file is provided below. It specifies a 16KiB direct-mapped L1 cache with 8
byte blocks, and a 32KiB 4-way set associative L2 cache with 8 byte blocks.
Sample configuration file for L1 and L2 Cache (cacheconfig.txt):
L1:
8
1
16
L2:
8
4
32
In the above example, the L1 cache will have 2048 sets each with one way. The L2 cache will
have 1024 sets each with 4 ways. The skeleton code provided reads the config file and
initializes variables for the L1 and L2 cache parameters.
Trace File (trace.txt):
Your simulator will need to take as input a trace file that will be used to compute the output
statistics. The trace file will specify all the data memory accesses that occur in the sample
program. Each line in the trace file will specify a new memory reference. Each line in the trace
cache will therefore have the following two fields:
● Access Type: A single character indicating whether the access is a read (R) or a write
(W).
● Address: A 32-bit integer (in unsigned hex format) specifying the memory address that is
being accessed.
Fields on the same line are separated by a single space. The skeleton code provided reads the
trace file one line at a time in order. After each access, your code should emulate the impact of
the access on the cache hierarchy.
Given a cache configuration and trace file, your cache simulator should be called as follows:
>>> ./cachesimulator.out cacheconfig.txt trace.txt
Simulator Output (trace.txt.out):
For each cache access, your simulator must output whether the access caused a read/write,
hit/miss, or not accessed in the L1 and L2. Additionally, you must also output whether the
current access caused a write to main memory. Each event is coded with a number, as defined in
the skeleton code. Codes 0-4 are for the caches. Codes 5 and 6 are for main memory.
0: No Access
1: Read Hit
2: Read Miss
3: Write Hit
4: Write Miss
5: NO Write to Main Memory
6: Write to Main Memory
Familiarize yourself with the codes and make sure you understand each scenario below along
with what your simulator output should be.
For example, if a write access misses in both L1 and L2, we must write the data directly to main
memory so your cache simulator should output:
4 4 6
where the first number corresponds to the L1 cache event and the second to the L2 cache event,
and the third to the main memory.
What you need to submit:
Similar to the previous labs, we will use GradeScope.
You must upload ONLY one file on Gradescope: “cachesimulator.cpp”. Do not zip the file
or upload any other file.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!