Comments (2)
Hi @stettberger,
sorry for the delayed reply!
I am not sure if my suggested solution fully meets your requirements, but maybe it is a first step in the right direction.
The cleanest way would be check against cache.backend.cached
for a specific cache if a cache line ID is in the cache, but due to the fact this is a set
and quite expensive in terms of computation, I would recommend introducing another dictionary data structure like this:
from cachesim import CacheSimulator, Cache, MainMemory
import collections
import itertools
def load_and_track_cl(CacheSimulator: cs, addr, length):
cl_ids = set()
# make sure to have one address per CL in case length > cl_size
addresses = itertools.chain(range(addr, addr+length, cs.last_level.backend.cl_size), [addr+length-1])
for ad in addresses:
cl_id = ad >> cs.last_level.backend.cl_bits
if cl_id not in cs.cache_dict:
cl_ids.add(cl_id)
cs.cache_dict[cl_id] = True
# do actual load
cs.load(addr, length)
return cl_ids
mem = MainMemory()
l1 = Cache("L1", 128, 4, 32, "LRU")
mem.load_to(l1)
mem.store_from(l1)
cs = CacheSimulator(l1, mem)
# create additional data structure in CacheSimulator
cs.cache_dict = collections.OrderedDict()
print("Loaded CL_ids: {}".format(load_and_track_cl(cs, 16, 4)))
print("Loaded CL_ids: {}".format(load_and_track_cl(cs, 20, 4)))
print("Loaded CL_ids: {}".format(load_and_track_cl(cs, 32, 4)))
print("Loaded CL_ids: {}".format(load_and_track_cl(cs, 127, 4)))
print("Loaded CL_ids: {}".format(load_and_track_cl(cs, 192, 80)))
Result:
Loaded CL_ids: {0}
Loaded CL_ids: set()
Loaded CL_ids: {1}
Loaded CL_ids: {3, 4}
Loaded CL_ids: {8, 6, 7}
I checked this against your code snippet and validated it with a few hundred thousands randomly generated memory addresses and timed it, which gave me an approx. speedup of 3x.
Please keep in mind that there are cases in which this doesn't work , for example, if you have a victim cache.
I hope this helps nonetheless!
from pycachesim.
Closing this issue for now, but I am happy to further discuss the topic!
Therefore, feel free to reopen.
from pycachesim.
Related Issues (10)
- Request for Instructions on How to Feed a binary file to the simulator HOT 2
- Understanding stats: more hits than loads in L1 ?! HOT 4
- Incompatibility with 64-bit addresses HOT 2
- Segfaults with 64bit addresses HOT 1
- Circular import HOT 2
- Steps to add a feature in the C backend HOT 1
- Support for non-square associativity
- There seems to be a logic error in cache block size checks HOT 1
- Consider Write Allocate Misses not as LOADs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycachesim.