riscv-software-src / riscv-perf-model

Example RISC-V Out-of-Order/Superscalar Processor Performance Core and MSS Model
Apache License 2.0
130 stars 55 forks source link

Add python shell support to Olympia #53

Open ghost opened 1 year ago

ghost commented 1 year ago

The Sparta modeling framework has the beginnings of python support, although not full fleshed out. This project entails two endeavors:

  1. Resurrect the python support in sparcians/map/sparta
  2. Have a working example of the use of python in Olympia

Basics of the initial implementation:

  1. Initialize a python shell:
    ./olympia --python-shell
  2. Create an Olympia simulation object
    (python) topology = "simple"
    (python) scheduler = sparta.Scheduler()
    (python) num_cores = 1
    (python) workload = "traces/dhry_riscv.zstf"
    (python) sim = OlympiaSim(topology, scheduler, num_cores, workload)
  3. Run simulation
    (python) sim.run()

Advanced implementation (towards the other end of the project). This will allow the user to create an empty simulation container and create components/topology on the fly:

sim = OlympiaSim()

# Set up the simulation tree
top = sim.getRootTreeNode()
core_tn = sparta.ResourceTreeNode(top, "core", "RISC-V Core", sparta.TreeNode.GROUP_NAME_NONE, sparta.TreeNode.GROUP_IDX_NONE, olympia.core_factory)
fetch_tn = sparta.ResourceTreeNode(core_tn, "fetch", "Fetch Unit", sparta.TreeNode.GROUP_NAME_NONE, sparta.TreeNode.GROUP_IDX_NONE, olympia.fetch_factory)
# ... other nodes

# Set up configurations
fetch_tn.getParameters().num_to_fetch = 8
# ...other configs

# Set up simulation (instantiates Fetch, Decode, etc). (this is a made-up function)
sim.initializeComponents()

# Set up bindings
sparta.bind(top.core.fetch.ports.out_fetch_queue_write, top.core.decode.ports.in_fetch_queue_write)

# Finalize the tree
sim.finalize()

# Run it
sim.run(workload)
aarongchan commented 1 year ago

Notes from Discussion with Knute:

New Scope is to add support for Python Shell of Sparta and be able to collect data directly from Sparta into a Python DataFrame for Analysis.

sim.run()


Things we would like to do:
- sim.enable_logging(args) (args TBD)
- sim.getroot() -> Returns treenodes
- sim.getnode(str_path_to_node) -> Returns a treenode
- sim.getClocks() -> Return clock manager/python array of sparta::Clocks
- sim.getScheduler() -> Return scheduler object
- treenode.getParams() -> Returns a read only parameter tree
- treenode.getCounters() -> Returns a statset
- treenode.getPorts() -> Returns portset
- treenode.getEvents() -> Returns eventset

Additional Support for:
- On a statset, should be able to walk counters (python iteration)
- for each counter, register notifications (sparta::NotificationSource)
- on python end every time a counter is updated, it can process the broadcast and collect