A discrete-event simulation (DES) framework for hardware architecture,
with a cycle-accurate DRAM timing model — Ramulator — embedded as the
Dram component.
The simulator kernel uses the classic next-event time-advance mechanism:
time jumps from event to event and never steps through empty cycles.
Components (a 1 GHz accelerator, a DDR4 controller, a 500 MHz HBM ...)
each own a Clock and schedule work as events; the DRAM ticks only
while requests are in flight, so an idle memory costs zero events.
- DES kernel —
Simulatorwith next-event time advance, deterministic event ordering (priority, then FIFO at equal time), zero-delay delta events, event cancel,next_timepeeking, per-component event counts, andstep/run/run_until_idledrivers - Hardware primitives —
Clock(integer-ps periods),Componentbase class, bounded combinationalFIFO, fixed-latencyPipestages with bounded occupancy and consumer backpressure (stall/retry) - Cycle-accurate DRAM timing — DDR3/4, LPDDR3/4, GDDR5, WideIO/2, HBM, SALP, with channel/rank scaling and per-standard timing (JEDEC timing parameters via Ramulator 1.x)
Dramcomponent — non-blockingread/write/reads/writeswith backpressure, read completions delivered as events at the DRAM tick time, optional wall-clockidle_refresh,flush()write barrier, per-instance Ramulator statistics (170+ counters) and derived metrics- Unmodified Ramulator — only its public API is used, exactly like
gem5's
Gem5Wrapper; Ramulator is a pinned git submodule - Fast — empty in-flight DRAM cycles with no other pending simulator
events tick in C++ (
tick_until_progress); completions stay Python events at the cycle that made progress. ~150K req/s sustained with per-request callbacks - Helpers — address-stream generators, one-call benchmarks, capacity estimation, theoretical bandwidth
Build from source (requires Python >= 3.10 and a C++17 compiler; pybind11 and CMake are resolved automatically):
git clone --recurse-submodules https://github.com/chenshih1/pyramulator.git
cd pyramulator
pip install .Ramulator is an external dependency pinned at third_party/ramulator
(a git submodule). If it is missing, the build downloads the pinned
source tarball automatically — with retries and a configurable mirror
(-DPYRAMULATOR_RAMULATOR_TARBALL_URL=..., disable with
-DPYRAMULATOR_FETCH_RAMULATOR=OFF) — so no manual git submodule update --init is needed.
from pyramulator import Simulator, Dram, Config
sim = Simulator()
dram = Dram(sim, Config(standard="DDR4", speed="DDR4_2400R", org="DDR4_4Gb_x8"))
completed = []
dram.read(0x1000, callback=lambda info: completed.append(info))
sim.run_until_idle() # completions arrive as events
print(completed[0]) # RequestInfo(addr=4096, type=READ, arrive_cycle=.., depart_cycle=.., core_id=0)
print(completed[0].latency) # latency in DRAM clock cyclesThe kernel is a classic event-scheduling discrete-event simulation
with next-event time advance (the Banks / Law-Kelton model): a
future-event list ordered by time, deterministic simultaneous-event
rules, and zero-delay delta events. Time is an integer count of
picoseconds. The Simulator never advances time past an event without
processing it — a run that only touches the DRAM in cycle 0 and cycle
4000 advances straight from 0 to 4000:
sim = Simulator()
sim.schedule(4000, lambda: print("t=4000")) # 4000 ps from now
sim.schedule(0, lambda: print("t=0"), priority=-1) # same time, earlier priority
sim.run() # processes every event- Events at the same time run in priority order (lower value first), then insertion order (FIFO) — fully deterministic.
- Callbacks may schedule zero-delay delta events at the current time; they run after already-queued events at that time.
schedule(delay, ...)/at(time, ...)return an event id;cancel(id)removes a pending event.next_timepeeks at the next event's time without running anything.step()processes one event,run(until=...)processes events up to an absolute time (inclusive),run(max_events=...)bounds the count.event_countsreports how many events each named source scheduled (Component.schedule_*attributes its events to the component) — handy for profiling which part of the architecture generates load.
from pyramulator import Clock, Component, Dram, FIFO, Pipe
host = Clock(1000, "host") # 1 GHz; Dram owns a second clock at tCK
class MyCore(Component):
def __init__(self, sim, clk, dram: Dram, name="core"):
super().__init__(sim, clk, name)
self.dram = dram
self.issue_q = FIFO(sim, clk, capacity=16)
self.pipe = Pipe(sim, clk, latency_cycles=4, slots=2,
consumer=self._on_pipe_out)
def _on_pipe_out(self, addr) -> bool:
if not self.issue_q.put(addr):
return False # stall the pipe; retried next cycle
self._pump()
return True
def _pump(self) -> None:
while self.issue_q.can_get():
addr = self.issue_q.peek()
if not self.dram.read(addr, callback=self._on_complete):
break # DRAM queue full; a completion re-pumps
self.issue_q.get()
def _on_complete(self, info) -> None:
self._pump() # DRAM made roomClock(period_ps, name)—clk.cycles(n)converts cycle counts to simulator time. Independent clocks (a 1 GHz core and a DDR4 tCK) share oneSimulator; time is integer picoseconds.FIFO(sim, clk, capacity)— bounded, combinational (state changes immediately when the owning component processes an event);put/get/peek/can_put/can_get/clear. There is no implicit wakeup: drain the FIFO from aPipeconsumer and from DRAM completions (seeexamples/pipe_fifo_dram.py).Pipe(sim, clk, latency_cycles, slots, consumer)— a fixed-latency pipeline stage with bounded occupancy;putreturns False when full and delivers items to the consumer exactlylatency_cycleslater. A consumer returningFalsestalls the last stage: the item stays put and delivery is retried every cycle until accepted (any other return value, includingNone, accepts — existing consumers are unaffected). Use that stall to backpressure into a fullFIFOor aDram.writethat returns False.
Dram embeds the Ramulator engine behind events:
- It owns a clock at the DRAM tCK (rounded to integer ps) and ticks the engine only while requests are in flight — an idle DRAM schedules nothing.
read(addr, callback=None, core_id=0)/write(...)/reads(addrs)/writes(addrs)are non-blocking with backpressure (False = queue full); accepted requests are counted indram.pending.- Read completions are delivered as events at the DRAM tick time, with
RequestInfo.latencyin DRAM clock cycles.completion_prioritycontrols their order relative to other same-time events. - Write completion: Ramulator has no upstream write-completion
callback (writes never enter its
pendinglist), so write callbacks fire upon acceptance — with zero latency. Usedram.flush()as a barrier when writes must be truly serviced before proceeding:
for i in range(64):
dram.write(i * 64)
dram.flush() # blocks until the DRAM queue is emptycore_idis validated againstnum_cores(Ramulator indexes per-core statistic arrays withcoreid; out-of-range ids would corrupt the C++ heap silently).
Components driven purely by completions (each _on_complete re-issues)
never poll — the DRAM's tick chain is the only recurring event source:
mem = Dram(sim, cfg)
done = [0]
def on_complete(info): # your completion handler (runs as an event)
done[0] += 1
issued = 0
addr = 0
while done[0] < NUM_REQUESTS:
# 1. keep the request queue full (backpressure: read returns False
# when the queue is full — retry on the next completion)
while issued - done[0] < 32 and issued < NUM_REQUESTS:
if mem.read(addr, callback=on_complete):
issued += 1
addr += 64
else:
break
# 2. advance time to the next event (a DRAM tick or completion)
sim.step()
mem.flush() # drain remaining reads AND writesBy default an idle DRAM schedules nothing, so Ramulator's refresh timer
only advances while requests are in flight. For studies where idle
refreshes must contend with wall-clock time (e.g. long idle gaps before
a latency-sensitive burst), construct the component with
Dram(sim, cfg, idle_refresh=True): a coarse idle clock (one event per
idle_batch_cycles, default 1024) keeps refresh advancing like the
reference integration. With idle refresh enabled the DRAM never goes
idle, so drive the simulator with run(until=...) rather than
run_until_idle().
Per-instance Ramulator counters and derived metrics:
dram.reset_stats() # per simulation phase
for i in range(32): # 32 reads fit the queue; all accepted
dram.read(i * 64)
sim.run_until_idle()
stats = dram.get_stats() # 170+ raw Ramulator counters
print(stats["read_requests"], stats["read_latency_sum_0"])
print(dram.metrics()) # derived summary dict:
# {'read_requests': 32.0, 'write_requests': 0.0, 'dram_cycles': 223.0,
# 'avg_read_latency_cycles': 130.0, 'avg_read_latency_ns': 108.3,
# 'row_hit_rate': 0.97, 'bandwidth_gbs': 11.0}The channel/bank/row interleaving scheme is selectable via mapping
(Ramulator honors it for DDR3):
cfg = Config(standard="DDR3", speed="DDR3_1600K", org="DDR3_2Gb_x8",
mapping="cacheline_interleaving") # row_interleaving, *_randomized, defaultmappingConfig also validates itself (cfg.validate()), and the bundled
reference configurations are available via config_dir().
Configuration helpers:
from pyramulator import (
estimate_capacity, theoretical_bandwidth,
supported_standards, supported_speeds, supported_orgs,
)
estimate_capacity("DDR4", "DDR4_4Gb_x8", channels=2) # bytes
cfg = Config(standard="DDR4", speed="DDR4_2400R", org="DDR4_4Gb_x8")
theoretical_bandwidth(cfg) # GB/s
supported_standards() # ['DDR3', 'DDR4', 'LPDDR3', ...]
supported_speeds("DDR4") # speed grades valid for DDR4
supported_orgs("DDR4") # organization/density optionsfrom pyramulator import benchmark_latency, benchmark_bandwidth, address_stream
benchmark_latency(cfg, num_requests=256, mode="random", seed=42)
benchmark_bandwidth(cfg, num_requests=256)
benchmark_all(cfg, num_requests=256) # both in one call
addrs = address_stream("sequential", 256, cacheline=64) # or "strided" / "random"
# split a stream into reads and writes by probability
reads, writes = split_read_write(addrs, write_fraction=0.25, seed=1)DDR3, DDR4, LPDDR3, LPDDR4, GDDR5, WideIO, WideIO2, HBM, SALP-1, SALP-2, SALP-MASA
The DRAM model itself is simulated at C++ speed (~3.6M DRAM cycles/s on a
single channel DDR4). Sustained request throughput with per-request Python
callbacks is ~150K req/s; callbacks are delivered in batches (no per-event
GIL round-trip). Measured latency and bandwidth across standards are
reported by benchmarks/bench.py.
examples/pipe_fifo_dram.py— copy engine that composesPipe+FIFO+Dramon two clocks: issue-pipe backpressure into a bounded FIFO, FIFO pump intoDram.read, compute-pipe stall onDram.writebackpressure, drained withrun_until_idle()(no nestedflush()). Run withpython examples/pipe_fifo_dram.py.examples/spmm_hbm.py— a naive single-PE SpMM accelerator streaming the dense matrix from an HBM timing model as DES components (event-driven issue loop with a bounded in-flight window, validated against numpy, reports cycles/bandwidth/row hits). Run withpython examples/spmm_hbm.py [channels].examples/accel_sim.py— multi-lane vector accelerator with a LOAD / COMPUTE / STORE pipeline per tile: event-driven load pumping, backpressure, write-acceptance semantics and theflush()barrier.
Build, test and check inside a local virtualenv:
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]" # includes test, ruff, mypy, pytest-cov
pytest # 193 tests
ruff check pyramulator/ tests/ benchmarks/ examples/
mypy pyramulator/
python benchmarks/bench.pySee CONTRIBUTING.md for the full workflow.
See CHANGELOG.md.
cpp/bindings.cpp— pybind11 bindings (the only C++ in this project)pyramulator/— the DES framework__init__.py— public API exportssim.py—Simulatorkernel (event queue, next-event time advance)hardware.py—Clock,Component,FIFO,Pipedram.py—Dramcomponent (Ramulator behind events)_engine.py— internal cycle-stepped engine (Ramulator wrapper)configs.py— standards/speed/org tables, capacity & bandwidth estimationmetrics.py— derived performance metricsworkload.py— address-stream generatorsbenchmark.py— one-call latency/bandwidth benchmarks
examples/— runnable architecture examples (Pipe+FIFO+Dram composition, SpMM, vector accelerator)benchmarks/— cross-standard latency/bandwidth benchmark scripttests/— pytest suite (engine, DES kernel, components)third_party/ramulator— Ramulator as a git submodule (pinned commit), used unmodified- Ramulator is not vendored; see
git submodule statusand https://github.com/CMU-SAFARI/ramulator
MIT — see LICENSE. Ramulator itself is MIT-licensed (Copyright 2015 SAFARI Research Group, Carnegie Mellon University).