API Reference¶
Generated from the package's docstrings, including the compiled
extension's, so it describes the installed version. The examples call a
running simulator cpu.
Configuration¶
Config
dataclass
¶
Full simulator configuration with flat parameter access.
The core checks the configuration as it is built: one it cannot read
or would refuse to build raises ValueError naming the field.
Example::
from rvsim import Config, Cache, BranchPredictor, Prefetcher
cfg = Config(
width=4,
branch_predictor=BranchPredictor.Tage(),
l1i=Cache("128KB", ways=8, prefetcher=Prefetcher.NextLine(degree=2)),
l1d=Cache("128KB", ways=8, prefetcher=Prefetcher.Stride(degree=2, table_size=128)),
l2=Cache("4MB", ways=16, latency=12),
)
replace
¶
Return a new Config with the given fields overridden.
Example::
base = Config(width=4, branch_predictor=BranchPredictor.Tage())
wide = base.replace(width=8)
ooo = base.replace(backend=Backend.OutOfOrder(rob_size=128))
See Configuration for every parameter.
Cache
¶
BranchPredictor
¶
Namespace for branch predictor configurations.
Bht
¶
Rocket's branch history table: entries counters of
counter_bits bits indexed by the fetch PC, with
history_length bits of global history hashed to history_bits
bits placed above the PC bits of the index.
TageBanking
¶
TAGE-SC-L's banked tables: banks before first_long_bank
share an array of short_factor slices of table_size
entries, the rest one of long_factor; each pair of banks forms
a 2-way table, and enabled (one flag per bank) says which exist.
from_dict
classmethod
¶
The banking a core TAGE dict holds, or None.
ScGehl
¶
One statistical corrector GEHL component: a counter table per
history length (longest first), each 2**log_entries entries.
No lengths turns the component off.
from_dict
classmethod
¶
The GEHL component a core SC dict holds.
ScLocalGehl
¶
A statistical corrector GEHL over per-branch local histories:
histories of them (a power of two), a branch's at
(pc ^ (pc >> index_shift)) % histories; mix_pc XORs the
branch's pc & 15 into each update.
from_dict
classmethod
¶
The local GEHL component a core SC dict holds.
ScLTage
¶
SC-L-TAGE + ITTAGE composed predictor.
Combines TAGE (direction), Loop Predictor, Statistical Corrector, and Indirect Target TAGE into a single high-accuracy predictor.
The TAGE parameters are shared with the standalone TAGE config;
the defaults add TAGE-SC-L's own TAGE rules (use_alt_counters=16,
CBP-5 allocation and update with 1-bit useful counters, two
allocations, a reset_interval of 1024 allocation penalties,
PcBits history with a 27-bit path, TageScL hashing, and
the 64KB TAGE-SC-L's 36 banked 1024-entry tables over history
lengths 6 to 3000).
The loop predictor, SC and ITTAGE have their own sub-configs; the
loop predictor and SC defaults are Seznec's 64KB TAGE-SC-L (CBP-5).
The SC's GEHL components are BranchPredictor.ScGehl and
BranchPredictor.ScLocalGehl values; None takes the default.
MemDepPredictor
¶
Namespace for memory dependence predictor configurations.
Backend
¶
Namespace for pipeline backend configurations.
InOrder
¶
In-order issue from a FIFO onto fu_config's unit pool, a
dual-issue core's when None.
Fu
¶
Functional unit pool configuration, for either backend.
Instantiate Fu with a list of unit descriptors (the inner classes).
Any FU type omitted will be absent from the pool, so include every type
your workload exercises::
Fu([
Fu.IntAlu(count=4, latency=1),
Fu.IntMul(count=1, latency=3),
Fu.IntDiv(count=1, latency=35),
Fu.FpAdd(count=2, latency=4),
Fu.FpMul(count=2, latency=5),
Fu.FpFma(count=2, latency=5),
Fu.FpDivSqrt(count=1, latency=21),
Fu.Branch(count=2, latency=1),
Fu.Mem(count=2, latency=1),
])
IntAlu
dataclass
¶
Integer ALU: add, sub, logic, shift, compare, set-less-than.
IntMul
dataclass
¶
Integer multiplier: mul, mulh, mulhsu, mulhu.
IntDiv
dataclass
¶
Integer divider: div, divu, rem, remu. Non-pipelined.
FpAdd
dataclass
¶
FP adder: fadd, fsub, fmin, fmax, fcmp, fcvt.
FpMul
dataclass
¶
FP multiplier: fmul.
FpFma
dataclass
¶
FP fused multiply-add: fmadd, fmsub, fnmadd, fnmsub.
FpDivSqrt
dataclass
¶
FP divider/sqrt: fdiv, fsqrt. Non-pipelined.
Branch
dataclass
¶
Branch/jump unit: all conditional branches, jal, jalr.
Mem
dataclass
¶
Memory address calculation for loads and stores.
VecIntAlu
dataclass
¶
Vector integer ALU.
VecIntMul
dataclass
¶
Vector integer multiplier.
VecIntDiv
dataclass
¶
Vector integer divider.
VecFpAlu
dataclass
¶
Vector FP ALU.
VecFpFma
dataclass
¶
Vector FP FMA.
VecFpDivSqrt
dataclass
¶
Vector FP div/sqrt.
VecMem
dataclass
¶
Vector memory unit.
VecPermute
dataclass
¶
Vector permute unit.
MemoryController
¶
Namespace for memory controller configurations.
Simple
¶
Fixed-latency controller: answers latency core cycles after it
starts a request, and starts requests serialised on bandwidth_gib_s.
Ddr5
¶
Command-level DDR5 controller with JEDEC timing.
Timing comes from speed_bin ("Ddr5_4800B" or "Ddr5_5600B") and may
be overridden per field with timing={"t_rcd": 40, ...} in DRAM
command clocks. The controller runs at the DRAM clock; the core clock
is Config(cpu_clock_mhz=...).
Policies: scheduler is "FrFcfs" (default) or "Fcfs";
refresh is "AllBank" (default) or "SameBank";
address_mapping is "RoRaBaChCo" (default), "RoRaBaCoCh"
or "RoCoRaBaCh"; ecc is "None", "SecDed" or
"ChipKill". power_down_idle_ns enables rank power-down after
that many idle nanoseconds; patrol_scrub_ns enables ECC patrol
scrubbing at that interval.
Lpddr4
¶
Command-level LPDDR4 controller with JEDEC timing.
The same controller as Ddr5 with LPDDR4's organisation and
command bus: channels independent 16-bit channels (an x32
package has two), each a die of density ("Gb4", "Gb8" or
"Gb16") with eight banks, 2 KiB rows and no bank groups, moving
a 64-byte line in one 32-beat burst. Timing comes from
speed_bin ("Lpddr4_3200") and may be overridden per field
with timing={"t_rcd": 40, ...} in DRAM command clocks.
Policies: scheduler is "FrFcfs" (default) or "Fcfs";
refresh is "AllBank" (default) or "PerBank";
address_mapping as for Ddr5. power_down_idle_ns enables
power-down after that many idle nanoseconds.
Prefetcher
¶
Namespace for prefetcher configurations.
ReplacementPolicy
¶
Namespace for cache replacement policies.
Coherence
¶
Coherence fabric between the private caches, used when hart_count > 1.
HomeAgent
¶
Namespace for coherence home-agent policies (who must be snooped).
Interconnect
¶
Namespace for coherence interconnect topologies.
Every kind takes the cycles a message spends per hop and the bytes a port or link moves per cycle.
Crossbar
¶
Bases: _Kind
Any port to any port in one hop (default).
Ring
¶
Bases: _Kind
Bidirectional ring, routed the shorter way; the home is one stop.
Mesh
¶
Bases: _Kind
Square 2-D mesh with XY routing.
Torus
¶
Bases: _Kind
Square 2-D torus (mesh with wraparound) with XY routing.
Hypercube
¶
Bases: _Kind
Hypercube with dimension-order routing.
presets
¶
Built-in configuration presets.
basic— the default machine,Config(): a 6-wide out-of-order desktop core with three cache levels, every prefetcher and DDR5-5600.fast— Apple M4 P-core class: 8-wide OoO at 4.4 GHz, 630-entry ROB, 192KB L1I, 128KB L1D, 4MB L2, 36MB L3, the 64KB TAGE-SC-L with ITTAGE, 4 unified FP/SIMD pipes, and DRAM controller.linux— a multi-corefastsystem with the memory map the bundled Linux image expects, kept coherent over an interconnect, with DDR5 memory.rocket,boom— Chipyard's Rocket and Medium BOOM as their RTL builds them, the reference cores of the RTL comparison (docs/rtl-rocket.md,docs/rtl-boom.md).
Usage from the CLI::
rvsim mandelbrot.elf --preset fast
Usage from Python::
from rvsim import presets, Simulator
cfg = presets.fast()
Simulator(cfg, binary="mandelbrot.elf").run()
fast
¶
Apple M4 P-core class configuration.
Based on publicly known M4 Everest P-core microarchitecture:
- 8-wide rename/dispatch (Apple decodes up to ~10 but dispatches 8)
- 630-entry ROB, 108-entry store buffer, ~160-entry issue queues
- 6 integer pipes (4 simple ALU + 2 complex with mul/div)
- 4 unified FP/SIMD pipes (each handles add, mul, FMA)
- 2 branch units, 4 load/store AGUs (3 load + 2 store capable)
- 192KB 6-way L1I, 128KB 8-way L1D (3-cycle hit), 4MB L2, 36MB L3
- 4.4 GHz P-core clock
- Seznec's 64KB TAGE-SC-L (CBP-5) with ITTAGE (Apple's predictor is proprietary but believed to be TAGE-class)
- Non-inclusive cache hierarchy
- LPDDR5-class DRAM controller
Vector units are modeled as a RISC-V V equivalent of Apple's 4 NEON/AMX pipes — VLEN=256 with 4 lanes and chaining.
Note: the sim models FU types independently, so having count=4 for FpAdd/FpMul/FpFma slightly overstates mixed-FP throughput vs the real M4 (which has 4 unified pipes). The 8-wide dispatch width naturally limits total throughput to realistic levels.
linux
¶
linux(harts: int = 8, *, memory: str = 'Ddr5', speed_bin: str = 'Ddr5_5600B', interconnect: str = 'Mesh', real_time: bool = True, core: Config | None = None) -> Config
core (the fast preset by default) in a system that boots the
bundled Linux image: its memory map, harts, coherence and memory
replace the core config's.
harts harts boot through OpenSBI's HSM into an SMP kernel; with
more than one, the private caches are kept coherent by a snoop-filter
home agent over interconnect (Crossbar, Ring, Mesh,
Torus or Hypercube). memory is Ddr5 (JEDEC
command-level timing at speed_bin, four channels) or Dram (the
core config's own memory controller).
With real_time the CLINT ticks at the device tree's timebase, so
the guest's clock keeps time with the modelled one. Without it the
CLINT ticks every cycle: guest time runs cpu_clock_mhz * 10**6 /
timebase_hz times fast, which shortens a boot's sleeps and timeouts
but floods measurements with timer interrupts.
rocket
¶
Rocket as Chipyard 1.14.0's RocketConfig builds it: 1-wide
in-order, 32 KiB L1s with a blocking L1D, 512 KiB L2.
The structure comes from the RTL (rocket-chip 55bcad0 under Chipyard
1.14.0); every latency the source does not state was measured on it
with tools/diag/rtl_probe.py (see docs/rtl-rocket.md):
WithNHugeCores(rocket/Configs.scala):MulDivParams(mulUnroll = 8, mulEarlyOut, divEarlyOut),FPUParams(minFLen = 16)with the defaultsfmaLatency = 3,dfmaLatency = 4; Zba, Zbb, Zbs. Measured: a dependent multiply delivers in 10 cycles, a 48-bitdivuin about 53 (the divider skips leading zeros, so wider operands take up to 64), a dependentfadd.din 5.- 32 KiB 8-way L1I (
ICacheParams(nSets = 64, nWays = 8),latency = 2) and 32 KiB 8-way L1D (DCacheParams(nSets = 64, nWays = 8, nMSHRs = 0), a blocking cache). Measured load-to-use: 2 cycles from the L1D, 18 from the L2, 24 to 29 from Chipyard's zero-latency memory model. - 28-entry BTB and 6-entry return stack (
BTBParams); a 512-entry BHT of 1-bit counters indexed by the fetch PC with 8 bits of global history hashed to 3 bits above the PC bits (BHTParams,BHT.index). Measured: a mispredict costs 3 cycles. - 32-entry fully associative L1 TLBs and a 512-entry direct-mapped L2
TLB (
nTLBWays,nL2TLBEntries); misaligned accesses trap. - 512 KiB 8-way inclusive L2 (
WithInclusiveCachedefaults). - CSR accesses, exceptions, xRETs and the flush after a CSR write act in
WB and redirect fetch the same cycle (
csr.io.rwandtake_pc_wbinrocket/RocketCore.scala): no trap latency. Measured: the handler's first instruction retires 6 cycles after the instruction before a trapping ECALL, the instruction after an MRET 5 cycles after it, the one after a flushed CSR write 5, and the one after a FENCE.I 21; a CSR read's dependent retires 3 cycles after it.
boom
¶
BOOM as Chipyard 1.14.0's MediumBoomV4Config builds it: 2-wide
out-of-order, 64-entry ROB, 16 KiB L1s, 512 KiB L2.
The structure comes from the RTL (riscv-boom 5223e44c under Chipyard
1.14.0); every latency the source does not state was measured on it
with tools/diag/rtl_probe.py (see docs/rtl-boom.md):
WithNMediumBooms(v4/common/config-mixins.scala):fetchWidth = 4,decodeWidth = 2,numRobEntries = 64, issue queues of 12 (memory, 2-wide), 12 (unique), 20 (ALU, 2-wide) and 12 (FP) entries,numIntPhysRegisters = 80,numFpPhysRegisters = 64,numLdqEntries = 16,numStqEntries = 16,maxBrCount = 12,FPUParams(sfmaLatency = 4, dfmaLatency = 4). Measured: a dependent multiply delivers in 7 cycles, a 48-bitdivuin about 55, a dependentfadd.din 5.- 16 KiB 4-way L1I (
ICacheParams(nSets = 64, nWays = 4)) and 16 KiB 4-way L1D (DCacheParams(nSets = 64, nWays = 4, nMSHRs = 2, nTLBWays = 8)). Measured load-to-use: 5 cycles from the L1D, 27 from the L2, 33 to 46 from Chipyard's zero-latency memory model. - TAGE-L (
WithTAGELBPD): six tagged tables of 128 or 256 sets by the 4-wide fetch bank with histories 2, 4, 8, 16, 32 and 64 and tags of 7, 7, 8, 8, 9 and 9 bits, useful bits reset every 2048 updates (BoomTageParams), over a 2048-set bimodal table (BoomBIMParams); a 128-set 2-way BTB (BoomBTBParams) and a 32-entry return stack (numRasEntries). Measured: a mispredict costs 11 cycles. - 8-way L1 DTLB, 512-entry direct-mapped L2 TLB (
nL2TLBEntries); misaligned accesses trap. - 512 KiB 8-way inclusive L2 (
WithInclusiveCachedefaults). - Measured: the handler's first instruction retires 14 cycles after a trapping ECALL, the instruction after an MRET 13 cycles after it, the one after a CSR access 13 to 14, after a FENCE 13 and after a FENCE.I 33.
Running a binary¶
Environment
dataclass
¶
Immutable description of a simulation run for reproducibility.
config
class-attribute
instance-attribute
¶
Config or dict. If None, uses Config() defaults.
load_addr
class-attribute
instance-attribute
¶
Load address for the binary.
args
class-attribute
instance-attribute
¶
The program's command line after its name, for a Linux user program
run in SE mode (its argv[0] is binary's file name).
env
class-attribute
instance-attribute
¶
The program's environment as NAME=value entries, for SE mode;
empty by default.
mode
class-attribute
instance-attribute
¶
"se" to run a Linux user program with its syscalls served by the
simulator, "bare" for a bare-metal image; None decides from the
ELF (an entry below RAM with no tohost symbol is a user program).
script
class-attribute
instance-attribute
¶
The file the program's readfile pseudo-operation reads.
outdir
class-attribute
instance-attribute
¶
The directory the program's writefile pseudo-operation writes into, created if missing.
run
¶
Run the simulation and return a Result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quiet
|
bool
|
Suppress exceptions and return error Result instead. |
True
|
limit
|
int | None
|
Max cycles to simulate. |
None
|
Example::
env = Environment(binary="software/bin/benchmarks/qsort.bin")
result = env.run()
print(result.stats["ipc"], result.stats["cycles"])
Result
dataclass
¶
Structured result of a single run.
stats
class-attribute
instance-attribute
¶
All stats as a Stats object.
wall_time_sec
class-attribute
instance-attribute
¶
Wall-clock time of the run in seconds.
compare
staticmethod
¶
compare(results: dict[str, Any], *, metrics: list[str] | None = None, baseline: str | None = None, col_header: str = '') -> None
Print a comparison table for experiment results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, Any]
|
Either |
required |
metrics
|
list[str] | None
|
Specific metric names to show. If None, shows a default set. |
None
|
baseline
|
str | None
|
Config name to normalize against (shows speedup ratios). |
None
|
col_header
|
str
|
Label for the config-name column (e.g. "size", "width"). |
''
|
The simulator¶
Simulator
¶
Bases: Simulator
Native simulator.
programs runs several static Linux user programs under SE mode at
once, one per hart from hart 0 up, sharing the memory system, as gem5's
se.py -n N --cmd "a;b" does; the run ends when the last of them
exits, with the first non-zero exit code in program order, and
exit_codes holds each program's.
A user program in binary gets args as its whole command line,
argv[0] included, or by default its file name alone; either way
its /proc/self/exe names the binary on the host.
script names the file the guest's readfile pseudo-operation reads
and outdir the directory its writefile pseudo-operation writes
into, as gem5's --script and m5out.
Example::
sim = Simulator(Config(width=4), binary="qsort.elf")
exit_code = sim.run(limit=10_000_000)
sim = Simulator(presets.linux(harts=1), kernel="Image", disk="disk.img")
sim.run()
Program
dataclass
¶
A static Linux user program for SE mode: its binary, its command
line after its name, and its environment as NAME=value entries.
Its argv[0] is the binary's file name.
Pseudo-operations¶
A program marks regions, dumps or resets the stats, stops the host's run,
ends it, or exchanges files with the host with
pseudo-operations: gem5's m5op instruction, which
software/include/rvsim.h wraps as rvsim_dump_stats,
rvsim_reset_stats, rvsim_break, rvsim_exit, rvsim_read_file and
rvsim_write_file. The dumps come back through
Simulator.stats_dumps, the stops through run_to and the Session
API's markers; the files come from Simulator(script=...) and go to
Simulator(outdir=...).
Debugging¶
Simulator.gdb(port) serves GDB's remote protocol until the debugger
detaches, kills the run, or the guest exits; python -m rvsim prog.elf
--gdb PORT does the same before a run (Debugging with GDB).
Instruction
¶
One retired instruction, returned by Simulator.step.
PipelineSnapshot
¶
Point-in-time contents of every inter-stage latch; each stage is a
list of slot dicts (length at most width).
Sessions¶
Session
¶
A workload run in phases on one or more configurations.
Example::
s = Session.linux(harts=8)
s.fast_forward(until=Session.LOGIN_SHELL) # cached after the first time
s.switch(presets.linux(harts=8, core=my_core))
s.warm_up(command="coremark 0x0 0x0 0x66 20 7 1 2000")
r = s.measure("coremark 0x0 0x0 0x66 20 7 1 2000")
print(r.ipc, r.stats["core0.bp.committed.accuracy"], r.exit_code)
The session runs on config. Fast-forwards run on
fast_forward_config (config unless given) and return to
config at their stop, so what a session measures always runs on the
configuration it was given or last switched to. Direct changes made
through sim are not part of the history cache keys are made
of; fast-forward with cache=False after them.
linux
classmethod
¶
linux(config: ConfigLike | None = None, *, harts: int | None = None, image_dir: str | None = None, kernel: str | None = None, firmware: str | None = None, disk: str | None = None, **kwargs: Any) -> Session
A session on the bundled Linux image (built by make linux).
config defaults to presets.linux(harts). Fast-forwards run
on presets.linux with its timer ticking every cycle, which
compresses the boot's sleeps, and with config's RAM, VLEN and
ISA options, so the cached boot is shared by every core
configuration of the same system.
resume
classmethod
¶
A session continuing from a checkpoint save wrote, on
config (the configuration it was saved on by default).
Raises ValueError if the workload's files changed since.
run
¶
run(until: Stop | None = None, *, every: int | None = None, on_every: Callable[[Session], None] | None = None) -> Stopped
Runs until until holds (the workload's end by default),
calling on_every(session) every every cycles on the way.
fast_forward
¶
Gets to until quickly: restores it from the cache when this
history has reached it before, else runs to it on the fast-forward
configuration (and caches it). Either way the session continues
from the stop's checkpoint on its own configuration, with caches,
TLBs and predictors cold, so what follows does not depend on
whether the cache held the stop.
Raises WorkloadEnded if the workload ends first.
switch
¶
Continues on config, which must show the guest the same
system (harts, RAM, memory map, VLEN and ISA options). Caches,
TLBs and predictors start cold.
warm_up
¶
Runs unmeasured to until, or through a shell command, to
warm caches and predictors before measuring.
measure
¶
measure(command: str | None = None, *, until: Stop | None = None, name: str | None = None) -> Region
Measures a shell command (Linux) or the run to until.
A command runs under the guest's rvsim run, which snapshots the
stats just before it starts and just after it exits; the region is
the difference, so the session's whole-run stats stay intact.
expect
¶
Runs until the console prints pattern and returns the match.
Raises WorkloadEnded if the workload ends first.
save
¶
Saves the session's state to path (with its console and
history beside it in path.json) for resume.
Saving drains the pipelines first, as gem5 does, so this session
continues a few cycles later than it would have; a session resumed
from path starts with caches, TLBs and predictors cold.
fork
¶
Continues from this point once per configuration: yields
(name, session) pairs, each an independent session on its
config. This session is left as it was.
Region
dataclass
¶
Stopped
dataclass
¶
Where a run stopped, and which stop ended it.
instructions
instance-attribute
¶
Instructions retired by every hart since the system started.
exit_code
class-attribute
instance-attribute
¶
The workload's exit code, when it ended.
label
class-attribute
instance-attribute
¶
The guest's label, for a Marker.
match
class-attribute
instance-attribute
¶
The console match, for a Console or LoginShell.
WorkloadEnded
¶
Bases: RuntimeError
The workload ended before the run reached its stop.
Stop points¶
A run ends the moment one of its stops holds; a | b stops at whichever
comes first. Counts are relative to the run's start, and every run also
ends if the workload does.
Stop
¶
Where a run stops.
key
¶
A stable description of the stop for checkpoint-cache keys, or
None when it has none (a predicate, say).
Marker
dataclass
¶
Bases: Stop
When guest software asks the host to stop: rvsim break LABEL in
Linux, rvsim_break(label) from rvsim.h on bare metal. Any
label stops the run when label is None.
Console
dataclass
¶
Bases: Stop
When console output the session has not yet matched matches
pattern, a regular expression; the match consumes the output up to
its end. The run stops on the cycle the matching output is written.
When
dataclass
¶
Bases: Stop
When predicate(session) returns true, checked every every
cycles. Give it a name to let a fast-forward to it be cached; the
name stands for the predicate, so it must change when the predicate
does.
LoginShell
dataclass
¶
Bases: Stop
At a Linux shell: waits for the login prompt, logs in as
user (with password if the image asks for one), and stops once
the shell prompt appears.
LOGIN_SHELL is LoginShell() with the image's defaults.
rvsim bench¶
The benchmark suite inside Linux from the command line:
rvsim bench # every benchmark, fast core, 8 harts
rvsim bench coremark stream --warm # warm each benchmark before measuring it
rvsim bench --config my_core.py --harts 4 --json results.json
rvsim bench --list
It boots once per system (cached), places the core in the Linux system
with presets.linux(core=...), and prints each benchmark's cycles,
instructions, IPC and branch, L1D, L2 and LLC misses per thousand
instructions.
Sweeps¶
Sweep
¶
Run multiple configs x binaries in parallel across CPU cores.
Example::
from rvsim import Sweep, Config
results = Sweep(
binaries=["qsort.elf", "dhrystone.elf"],
configs={
"baseline": Config(width=2),
"wide": Config(width=4),
},
).run(parallel=True, limit=100_000_000)
results.compare()
run
¶
run(*, parallel: bool = True, limit: int | None = None, max_workers: int | None = None) -> SweepResults
Execute all (binary, config) combinations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel
|
bool
|
Use multiple processes. |
True
|
limit
|
int | None
|
Maximum cycles per run. |
None
|
max_workers
|
int | None
|
Max parallel workers. |
None
|
Returns:
| Type | Description |
|---|---|
SweepResults
|
|
SweepResults
dataclass
¶
Structured results from a sweep run.
Organised as results[binary_name][config_name] = Result.
compare
¶
compare(*, metrics: list[str] | None = None, baseline: str | None = None, col_header: str = '') -> None
Print a comparison table across all configs and binaries.
Statistics¶
Stats
¶
Bases: dict[str, float]
Dict-like simulation statistics with querying and comparison.
Keys are the simulator's stat paths (core0.cache.l1d.misses,
core0.bp.committed.accuracy, hart0.retired_insts), plus the
run-level cycles, instructions_retired and ipc.
Example::
result.stats["ipc"]
result.stats["core0.pipeline.stalls.data"]
result.stats.query("miss_rate")
from_core
classmethod
¶
Flatten the native stats object into path-keyed entries.
Every registered path (core0.cache.l1d.hits, system.retired_insts)
becomes a key, and the run-level cycles, instructions_retired
and ipc are added under their short names.
query
¶
The statistics whose path pattern, a case-insensitive regex,
matches anywhere in. An invalid regex raises re.error.
tabulate
staticmethod
¶
Build a comparison table from labeled Stats objects.
Each Stats is typically a .query() result, so all share similar
keys. Columns are the sorted union of all keys across the provided
Stats objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
dict[str, Stats]
|
|
required |
title
|
str
|
Optional table title rendered above the header. |
''
|
Returns:
| Type | Description |
|---|---|
Table
|
|
compare
¶
Print a two-column comparison table (self vs other) to stdout.
Table
¶
Rendered comparison table. Created by tabulate, displayed via
print() or REPL auto-repr.
ISA utilities¶
reg and csr¶
Register and CSR lookups: constants, name lookup, and the reverse.
from rvsim import reg, csr
reg.A0 # 10
reg("a0") # 10
reg.name(10) # "a0"
csr.MSTATUS # 0x300
csr("mstatus") # 0x300
csr.name(0x300) # "mstatus"
Disassemble
¶
Fluent disassembler for RISC-V binaries and raw bytes.
Usage::
Disassemble().binary("software/bin/programs/qsort.bin").print()
Disassemble().binary("qsort.bin").at(0x80000024, count=10).print()
Disassemble().bytes(data).print()
Disassemble().inst(0x00a00513) # single instruction -> str