Coder Social home page Coder Social logo

Comments (2)

JanLJL avatar JanLJL commented on August 31, 2024

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.

JanLJL avatar JanLJL commented on August 31, 2024

Closing this issue for now, but I am happy to further discuss the topic!
Therefore, feel free to reopen.

from pycachesim.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.