Skip to content

CPU vs GPU

Every number on this page comes from one run of benchmarks/run_benchmarks.sh on a single machine:

CPU AMD Ryzen 9 3950X 16-Core Processor (32 logical cores, torch using 16 threads)
GPU 0 NVIDIA GeForce RTX 3090
GPU 1 NVIDIA GeForce RTX 3080
PyTorch 2.10.0+cu128 / CUDA 12.8
torchtsetlin 0.7.0
Python 3.10.11
measured 2026-11-08 11:20:01

How to read these

Each point is the median of three timed blocks of steady-state calls, after a warm-up, with the device synchronised once per block. The micro-benchmarks use synthetic Boolean data at 20 % density, resident on the device unless stated otherwise. Reproduce — or replace these numbers with your own hardware's — with:

./benchmarks/run_benchmarks.sh          # ~20-25 min, rewrites this page

These are the numbers of torchtsetlin 0.7.0. Benchmark history puts the same suites side by side for every earlier version.

Throughput vs batch size

Throughput vs batch size Throughput vs batch size

One update() call touches every automaton in the machine, so its cost depends far more on the size of the machine than on how many examples are in the batch. Feeding the GPU more examples per call is therefore nearly free: training throughput rises from 4,031 examples/s at batch 1 to 249,073 at batch 4096. At batch 256 the same model trains 139,188 examples/s on the GPU against 3,905 on the CPU (36×).

The Noisy-XOR scale machine in the bottom row is the counter-example: 20 clauses over 12 features is less work than a kernel launch, so only past batch 1 does the GPU pull ahead. Small machines belong on the CPU.

Batch size — MNIST scale (784 features, 500 clauses/class)
batch CPU train ex/s GPU train ex/s train speedup CPU infer ex/s GPU infer ex/s infer speedup
1 225 4,031 17.9× 556 3,875 7.0×
2 545 7,665 14.1× 2,287 7,717 3.4×
4 797 16,170 20.3× 4,267 15,420 3.6×
8 876 31,433 35.9× 4,672 30,802 6.6×
16 1,309 60,008 45.8× 8,545 61,359 7.2×
32 1,883 112,329 59.7× 13,671 124,002 9.1×
64 2,319 200,348 86.4× 17,768 251,979 14.2×
128 2,276 297,589 130.7× 27,588 501,384 18.2×
256 3,905 139,188 35.6× 32,747 982,760 30.0×
512 4,881 207,829 42.6× 52,307 1,975,241 37.8×
1,024 5,421 278,420 51.4× 51,315 2,421,505 47.2×
2,048 6,311 309,807 49.1× 31,769 2,414,376 76.0×
4,096 515 249,073 483.6× 30,876 2,521,657 81.7×
Batch size — Noisy-XOR scale (12 features, 10 clauses/class)
batch CPU train ex/s GPU train ex/s train speedup CPU infer ex/s GPU infer ex/s infer speedup
1 890 4,339 4.9× 8,627 3,970 0.5×
4 3,076 17,259 5.6× 30,259 15,875 0.5×
16 11,995 70,193 5.9× 116,475 62,771 0.5×
64 46,409 278,789 6.0× 443,445 249,983 0.6×
256 148,050 206,397 1.4× 1,503,227 1,002,328 0.7×
1,024 326,535 826,193 2.5× 4,363,726 4,010,677 0.9×

How much the GPU buys you

How much the GPU buys you How much the GPU buys you

The speedup is not one number. It grows with batch size because the CPU pays the per-clause cost serially while the GPU hides it, peaks at about 484× around batch 4096, and holds from there. Inference behaves differently again: the CPU forward pass is already cheap, so the gap there tops out at 82× — worth having, but not the same kind of difference.

Throughput vs model size

Throughput vs model size Throughput vs model size

Both axes cost the same thing — the update is n_clauses × 2 × n_features element-wise work — so both curves fall roughly as 1/x. The CPU falls off immediately; the GPU stays flat until the machine is big enough to fill it, which is why the gap widens with model size: 36× at 50 clauses/class against 43× at 4000; 19× at 128 features against 34× at 8192. Big machines are exactly the ones worth moving to a GPU.

Clause budget (784 features, batch 256)
clauses/class CPU train ex/s GPU train ex/s train speedup CPU infer ex/s GPU infer ex/s infer speedup
50 5,460 195,700 35.8× 243,556 979,627 4.0×
100 11,864 187,060 15.8× 156,753 998,623 6.4×
250 5,640 158,336 28.1× 64,086 997,053 15.6×
500 3,888 143,801 37.0× 34,817 993,030 28.5×
1,000 1,674 91,596 54.7× 14,958 1,013,655 67.8×
2,000 798 47,954 60.1× 5,776 630,410 109.1×
4,000 556 24,180 43.5× 2,001 262,502 131.2×
Feature count (500 clauses/class, batch 256)
features CPU train ex/s GPU train ex/s train speedup CPU infer ex/s GPU infer ex/s infer speedup
128 9,965 188,356 18.9× 90,189 969,794 10.8×
256 9,386 180,257 19.2× 66,429 1,013,269 15.3×
512 5,119 158,938 31.0× 42,099 997,063 23.7×
1,024 3,180 131,877 41.5× 24,237 982,130 40.5×
2,048 1,484 77,297 52.1× 13,558 975,955 72.0×
4,096 846 42,867 50.7× 7,780 606,706 78.0×
8,192 633 21,845 34.5× 3,734 330,901 88.6×

The model zoo

The model zoo The model zoo

Weighted and coalesced variants cost about what the plain machine costs: they change the output layer and the feedback policy, not the per-clause work that dominates. The convolutional models are the outlier at 6× the cost of the flat machine per example — a 10×10 patch over a 28×28 image is 361 patches, and every patch is evaluated against every clause.

Model zoo (784 features, batch 128)
model CPU train ex/s GPU train ex/s train speedup CPU infer ex/s GPU infer ex/s infer speedup GPU peak memory
TsetlinMachine 2,255 275,431 122× 27,768 490,389 18× 55 MB
TsetlinMachine (weighted) 2,979 291,915 98× 27,059 450,997 17× 56 MB
CoalescedTsetlinMachine 1,930 197,180 102× 22,869 490,858 21× 64 MB
RegressionTsetlinMachine 3,235 312,991 97× 26,172 516,131 20× 56 MB
ConvTsetlinMachine 630 48,580 77× 632 56,779 90× 167 MB
ConvCoalescedTsetlinMachine 505 47,277 94× 633 56,698 90× 167 MB

Where an update goes

Where an update goes Where an update goes

apply_feedback — the stochastic increment/decrement of the whole (n_clauses, 2F) automaton state — is the expensive part of an update: on the CPU it is 25 % of the 57.3 ms call; on the GPU it is 28 % of the 1.9 ms call. A standalone torch.binomial draw of the same (C, 2F) shape costs 267.70 ms on the CPU and 0.21 ms on the GPU — the single most expensive op in the commit. Everything before the commit (encoding, clause evaluation, the vote sums and the feedback count matmuls) is comparatively cheap. That is also why batching pays: a batched update draws once per commit, a sequential one draws once per example.

Update cost breakdown (5 000 clauses, 784 features, batch 256)
stage cpu (ms) cuda:0 (ms)
encode 0.063 0.039
evaluate 7.495 0.108
votes+select 7.483 0.439
feedback_counts 15.419 0.670
accumulator_alloc 3.691 0.117
coerce_targets 0.009 0.053
apply_feedback 14.205 0.534
refresh_include 15.515 0.226
commit 29.730 0.813
torch.binomial (C x 2F) 267.704 0.209
update() total 57.298 1.882

CPU thread scaling

CPU thread scaling CPU thread scaling

More CPU threads buy surprisingly little in training: 2.5× going from 1 to 32 threads. The batched update is a chain of large element-wise ops over the state, and the binomial draw that dominates it does not thread. Inference scales much better (6.5× over the same range): the forward pass is one big matmul-shaped reduction. If a CPU run is too slow, the lever is the clause budget or the batch size, not torch.set_num_threads.

CPU thread scaling (5 000 clauses, 784 features, batch 256)
threads train ex/s infer ex/s
1 742 4,703
2 1,586 9,067
4 2,131 11,250
8 3,952 24,998
16 4,817 34,143
32 1,818 30,741

Batched vs sequential feedback

Batched vs sequential feedback Batched vs sequential feedback

feedback_mode="sequential" is the exact per-example algorithm: it commits once per example, so a mini-batch of 32 pays 32 commits instead of one. Measured at batch 32 that is 7-393× slower than the batched update, depending on the model scale and the device. Batching is the default for that reason — but it is an approximation, and its fidelity degrades as the batch grows. See Batched vs sequential feedback for the accuracy side of this trade.

Batched vs sequential feedback
scale feedback_mode batch device examples/s ms / update call
mnist-1k batch 1 cpu 461 2.17
mnist-1k batch 1 cuda:0 4,332 0.23
mnist-1k batch 32 cpu 3,054 10.48
mnist-1k batch 32 cuda:0 139,652 0.23
mnist-1k batch 256 cpu 17,457 14.66
mnist-1k batch 256 cuda:0 189,512 1.35
mnist-1k sequential 1 cpu 403 2.48
mnist-1k sequential 1 cuda:0 1,326 0.75
mnist-1k sequential 32 cpu 446 71.77
mnist-1k sequential 32 cuda:0 18,568 1.72
xor batch 1 cpu 883 1.13
xor batch 1 cuda:0 4,395 0.23
xor batch 32 cpu 23,785 1.35
xor batch 32 cuda:0 140,583 0.23
xor batch 256 cpu 132,340 1.93
xor batch 256 cuda:0 208,458 1.23
xor sequential 1 cpu 982 1.02
xor sequential 1 cuda:0 358 2.79
xor sequential 32 cpu 880 36.38
xor sequential 32 cuda:0 357 89.51

Where the data lives

Keeping the Boolean dataset in host memory and copying each mini-batch across costs at most 2 % of throughput here — the update is long enough to hide the transfer. So stream a dataset that does not fit in VRAM without worrying, but do hand the model a device tensor: see Choosing a device for the one copy that does bite (Booleanization encoders keep their thresholds on the CPU).

Host- vs device-resident data (training, 784 features, 500 clauses/class)
device batch dataset lives on examples/s ms / update
cpu 32 device 1,806 17.72
cpu 32 host 1,819 17.60
cpu 256 device 3,941 64.97
cpu 256 host 3,872 66.11
cpu 2048 device 5,806 352.75
cpu 2048 host 5,765 355.24
cuda:0 32 device 100,936 0.32
cuda:0 32 host 115,839 0.28
cuda:0 256 device 140,647 1.82
cuda:0 256 host 140,793 1.82
cuda:0 2048 device 308,890 6.63
cuda:0 2048 host 303,539 6.75

Dense segmentation

Dense segmentation Dense segmentation

Dense prediction evaluates one patch per pixel, so throughput is quoted in pixels per second rather than examples per second — one 32×32 image is 1 024 examples.

  • A 3×3 dense model on 32×32 inputs runs at 20,713 px/s training and 1,058,131 px/s predicting on CPU — prediction is roughly 51× cheaper, because it never draws feedback or touches the automata.
  • patches_per_commit is the price of fidelity: committing once per batch reaches 46,876 px/s against 20,713 at the default 128, a 2.3× speedup that costs real accuracy (see the segmentation guide's ablation).
Dense segmentation (4 planes, 4 classes, batch 8 images)
configuration patches/commit CPU train px/s GPU train px/s train speedup CPU infer px/s GPU infer px/s infer speedup
dense 3x3 32px 128 20,713 113,834 5× 1,058,131 22,406,410 21×
dense 5x5 32px 128 12,507 113,547 9× 882,200 22,388,035 25×
dense 3x3 64px 128 20,797 114,915 6× 724,351 54,309,173 75×
dense 3x3 32px + position 128 17,578 114,749 7× 1,046,080 19,168,325 18×
dense 3x3 32px 400 clauses 128 10,299 114,679 11× 192,331 15,647,621 81×
dense 3x3 32px ppc=32 32 9,618 28,527 3× 1,141,517 22,597,269 20×
dense 3x3 32px ppc=512 512 45,400 444,916 10× 1,140,143 22,649,781 20×
dense 3x3 32px ppc=None all 46,876 5,549,894 118× 3,089,103 22,590,177 7×

3D convolution

3D convolution 3D convolution

A 3D convolutional machine evaluates every clause at every window position of a volume, so the cost scales with the number of positions P = Pd·Ph·Pw. Throughput is quoted in volumes per second.

  • On GPU (RTX 3090), a cardiac-sized 12×64×64 volume with a 3×7×7 window has 33,640 window positions and trains at 1,288.3 volumes/s; an in-plane stride of 2 cuts that to 8,410 positions and runs at 1,168.4 volumes/s (0.9×).
  • With 2 000 clauses one such volume no longer fits max_chunk_elements, so the patch axis is split automatically into blocks of 18,982 positions: peak memory 247 MB at 305.96 volumes/s, against 268 MB at 347.91 volumes/s when it is forced into one block. The output is identical (the OR over patches and the random-patch draw are exact under the split); with fewer clauses, ordinary batch chunking already respects the budget and blocking buys nothing.
3D convolution (1 plane; 2 x 100 clauses, batch 4 — or 10 x 200, batch 2)
configuration patches P patches per block CPU train vol/s GPU train vol/s train speedup CPU infer vol/s GPU infer vol/s infer speedup GPU peak memory (train)
8x32x32, 3x5x5 4,704 4,704 157.2 1,755.8 11× 197.4 2,373.5 12× 60 MB
16x32x32, 3x5x5 10,976 10,976 62.1 776.4 13× 70.2 1,026.7 15× 142 MB
12x64x64, 3x7x7, stride (1,2,2) 8,410 8,410 66.0 1,168.4 18× 67.7 1,835.8 27× 170 MB
12x64x64, 3x7x7 33,640 33,640 12.1 1,288.3 107× 12.3 127.5 10× 360 MB
12x64x64, 3x7x7, 2000 clauses, one block 33,640 33,640 4.4 347.9 79× 4.5 127.3 28× 268 MB
12x64x64, 3x7x7, 2000 clauses, auto blocks 33,640 18,982 4.2 306.0 73× 4.7 427.0 91× 247 MB
12x64x64, 3x7x7, 2000 clauses, patches_per_chunk=2048 33,640 2,048 5.4 199.9 37× 6.0 353.2 59× 266 MB

End to end: MNIST

End to end: MNIST End to end: MNIST

Synthetic micro-benchmarks flatter whichever device wins the micro-benchmark, so here is the whole thing end to end, Trainer.fit included:

  • ConvTsetlinMachine 200/class 10x10 — 0.2 s/epoch on the GPU vs 16 s on the CPU (65×), 82.8% test accuracy
  • TsetlinMachine 500/class — 0.4 s/epoch on the GPU vs 12 s on the CPU (34×), 95.4% test accuracy

Accuracy matches across devices to within run-to-run noise, as it should — only the wall clock moves. These are short runs at a modest clause budget; see Benchmarks for what longer runs reach.

End-to-end MNIST
model device train examples epochs s / epoch examples/s test accuracy GPU peak memory
ConvTsetlinMachine 200/class 10x10 cpu 10,000 1 16.15 619 0.8200 —
ConvTsetlinMachine 200/class 10x10 cuda:0 10,000 1 0.25 40,182 0.8280 474 MB
TsetlinMachine 500/class cpu 60,000 3 12.45 4,820 0.9541 —
TsetlinMachine 500/class cuda:0 60,000 3 0.37 161,690 0.9541 236 MB

Reproducing

./benchmarks/run_benchmarks.sh                  # every suite, cpu + cuda:0
./benchmarks/run_benchmarks.sh --quick          # ~1 min smoke test
./benchmarks/run_benchmarks.sh -s batch models  # a subset
./benchmarks/run_benchmarks.sh --plots-only     # re-render from existing results

The raw records live in benchmarks/results/versions/0.7.0/cpu_vs_gpu.json (one folder per library version); benchmarks/plot_benchmarks.py turns them into the figures above and writes this page.