Benchmarks¶
scripts/bench.py times the engines on the machine it runs on: the CPU
engine, the CUDA engine and the WGSL engine, each where it is present. It
writes one JSON Lines record per measurement, and the records of runs from
many machines read into one table for plotting and analysis.
Running it¶
python scripts/bench.py run # every workload, size small
python scripts/bench.py run --size medium --level kernel engine
python scripts/bench.py run --workload walk_pass survey --engine wgsl cuda
python scripts/bench.py load runs/*.jsonl --to table.parquet
--size is one of smoke, small, medium and large. --repeats sets
the number of timed repeats after one warm-up. The survey workload on the
CPU engine runs one checkpoint of each survey, on at most two timed seeds. Its
time per checkpoint changes by about 1% between checkpoints and between seeds,
so the shorter survey gives the same rate. Its survey results (niches, best
log-likelihood) come from that shorter survey, and do not compare with the
results of the GPU engines. The default output file is
bench-<host>-<UTC time>.jsonl in the current folder. An engine that is not
present gives a skipped record. A workload that fails gives an error
record, and the run continues with the next workload.
Each record names the commit of the checkout that holds the script. Thus the
script runs only when Python imports hifuku from that checkout. If the
environment has a different copy installed, the script stops and gives the
command that installs the checkout:
Comparing machines¶
CUDA runs on NVIDIA hardware, and Metal on Apple hardware. One machine rarely has both, so the CUDA engine and a Metal run of the WGSL engine cannot be timed side by side. The comparison therefore runs through the WGSL engine, which runs on both:
- On an NVIDIA machine, the WGSL engine (through Vulkan) and the CUDA engine run on the same hardware. The ratio of their times is the cost of the engine and its API, with the hardware held fixed.
- Across machines, the WGSL engine runs the same kernels. The calibration
workloads measure each device: its copy bandwidth, its float32 fma
throughput and the cost of one submission. Each bandwidth and throughput
submission runs as many dispatches as it needs to last a target time
(
target_seconds, with the count indispatches). This makes the cost of the submission a small part of each value. A time divided by the calibration time of the same device is a fraction of that device's own capability, which compares between devices more fairly than a raw time. - On every machine, the CPU engine is a local reference: what a GPU gains over the host on that machine.
The raw times are in every record, so an analysis can also read them as performance in practice, without any normalization.
The workloads¶
| Level | Workload | Engines | What it times |
|---|---|---|---|
| calibration | copy_bandwidth |
WGSL, CUDA | a device-to-device copy, as seconds and GB/s |
| calibration | fma_throughput |
WGSL, CUDA | float32 fma chains, as seconds and GFLOP/s |
| calibration | submission |
WGSL, CUDA | one submission, or launch, of a kernel that does nothing |
| kernel | draws, split_keys, key_search |
WGSL, CUDA | the survey primitives |
| kernel | transition_matrices |
WGSL, CUDA | the matrix rebuild, JC69 and LG |
| kernel | walker_fitness |
WGSL | the post-order, matrix and peel stages, and their total |
| kernel | walker_placement |
WGSL | the post-order and placement stages, and their total |
| kernel | walker_evaluation |
WGSL, CUDA | a walker's fitness and its place on the chart |
| kernel | walker_moves |
WGSL | the moves alone |
| kernel | pool_placement, move_tally |
WGSL, CUDA | the elite pool |
| engine | likelihood |
CPU, CUDA, WGSL | one log-likelihood, the whole call |
| engine | walk_pass |
WGSL, CUDA | one survey pass through the engine's backend; on WGSL also the longest single dispatch and its stage, against the two-second limit of a browser or of Windows |
| survey | survey |
CPU, CUDA, WGSL | whole surveys on random data of the preset's size and on the three synthetic genes with their neighbor-joining anchors: time per variation and per checkpoint, and what they found |
The WGSL workloads of transition_matrices and the survey primitives also
record compile_seconds, the time to compile their pipelines, and
pool_placement records upload_seconds, the upload of a batch, apart from
the placement. A survey record names its timed seeds in params.seeds; seed 0
is the warm-up.
A workload that names only WGSL has no CUDA counterpart that does the same
work. The CUDA engine evaluates a walker in one kernel, and its walk kernel
also evaluates every step. Those comparisons are walker_evaluation and
walk_pass.
The record¶
| Field | Content |
|---|---|
schema |
the version of this format, 1 |
run |
one id for every record of one invocation |
time |
the UTC time of the measurement |
machine |
the host, OS, CPU and memory; the Python, NumPy, Numba and wgpu versions; the git commit and dirty, which is true when the tree holds changes the commit does not; hifuku_installed, the version in the package metadata, which can name an older commit; the WebGPU adapter and its limits; the CUDA device; each null when absent |
level, workload, engine |
as in the table above |
params |
the sizes of the measurement, and size, the preset |
metric, unit |
for example seconds and s, or bandwidth and GB/s |
values |
every timed repeat |
warmup |
the warm-up values, kept apart |
status |
ok, skipped or error; the last two with reason |
timing |
what a time holds |
timing matters when two engines are compared:
host: from the submission to the end of the device work, waited on the host. This is how every WGSL time is taken. It includes the cost of the submission, which thesubmissioncalibration measures.device: from a CUDA launch to its synchronize.events: GPU time between two CUDA events, which the survey driver records around each checkpoint's work on the CUDA engine.wall: the elapsed host time of a whole call, transfers included.- null: the metric is not a time, for example the niches a survey filled.
The first WGSL call in a process runs probe kernels to choose the float-float arithmetic. The script chooses the arithmetic before it times anything, so no WGSL time holds a probe kernel. Pipeline compilation is not in a WGSL time either.
Combining runs¶
bench.py load reads any number of record files into one polars table with
one row per value. The machine and the params become columns with the
prefixes machine_ and params_. --to writes the table as Parquet, CSV or
JSON Lines. Skipped and failed measurements are left out, or with
--keep-missing kept as one row each, with a null value and their reason,
so that the table shows which engines were absent. A run that adds a field later still loads beside an older one:
the new column is null in the older rows.
Recorded runs¶
The runs collected for the comparison are in docs/benchmarks/runs/, each under
the name bench.py gave it, which holds the host and the UTC time of the run.
The summary lists them, with tables and figures that compare the
machines. To add a run:
- Copy its file into
docs/benchmarks/runs/. - Run
python scripts/bench_report.py, which rebuilds the summary page and its figures.
The test suite fails while the summary page does not match the recorded runs. To read all of the runs into one table:
Every record holds its machine and the commit it ran, so a run stays readable after the script changes.
At size small, a WGSL kernel time below about one millisecond can change by
a factor of two or three between runs on the same machine. The calibration
values and the walk pass change by less than 2%. Compare the short kernel
times across machines only with that spread in mind, or measure them at a
larger size.