Skip to content

A histogram bench: bend-parallel's parallel histogram over one shared Array<U32>, with C, TS and Lean twins - #1278

Merged
Lorenzobattistela merged 1 commit into
bendlang:mainfrom
nicolas-abril:bench-histogram
Oct 2, 2026

Conversation

@nicolas-abril

Copy link
Copy Markdown
Collaborator

The bench

bench/runtime/histogram: a parallel histogram over one flat Array<U32>. It's the suite's first shared-array, multi-pass case: every other bench is one fork tree over tree-shaped data or independent items.

  • The library: bend-parallel's histogram.bend at 45a161a (Apache-2.0, the same license as Bend). It's ported as is, except that its sort-only path (sc, ins.go) is dropped and Scan.half is inlined. The header credits it.
  • What a run does: 128 rounds. Each round:
    • refills 2^24 keys (64 MB) in parallel with a new seed;
    • counts them into 256 buckets with bend-parallel's two passes: per-block rows of a 2^11 × 256 table, then column sums;
    • folds that round's counts into the checksum, so every round is checked.
  • Buffers: sized once, outside the !, and handed from round to round as the library intends.
  • Twins: main.c, main.ts and main.lean, single-threaded and doing the same steps, including the two-step column pass the library uses from 2^12 rows up.
  • Unsafe code: the lanes share the keys and the table through Base's @unsafe Array.fork and Array.join, as bend-parallel does. Bend has no safe way to give lanes disjoint slices of one array. So --check-only lists the 13 defs that rely on them and exits 1. bend main.bend -o main, which the perf gate runs, builds and runs normally.

Correctness

size checksum agrees across
small: 2^10 keys, B = 4, 2 rounds 3825188900 Bend (interpreter; 1 and 16 threads; GPU), the C, TS and Lean twins, an independent Python histogram
2^12 keys, B = 12, 3 rounds (the two-step pass) 1974811180 Bend, the C and Lean twins, Python
big: 2^24 keys, B = 11, 128 rounds 122845198 Bend at 1 and 16 threads and on the GPU, the three twins

Pins

apple_m4.txt gains the histogram row. It was measured with the perf gate's own cell script for this bench only, three runs a cell, medians, the same way --pin takes them; the other rows are untouched.

COMPILER SEQ-CPU PAR-CPU PAR-GPU OUTPUT
1.033 s 1.717 s, 67.7M 0.367 s, 74.8M 1.481 s, 80.0M 122845198

apple_m4_max.txt (the record pins, from gen_pins.ts on the M4 Max) has no row yet, so the bench is not on the charts until that machine repins.

Against C

On the cluster, single-threaded: Bend 1.72 s, the C twin 1.07 s. On 16 threads: Bend 0.367 s, against 0.248 s for a pthreads C version (per-thread private histograms, written for the comparison and not in the tree). Both scale about 4.6–4.7x, and both are near the minis' memory bandwidth.

Most of the single-thread gap is in two places:

Gates

Not run

  • CUDA, Linux and x86.

🤖 Generated with Claude Code

… Array<U32>, 128 fresh batches of 2^24 keys into 256 buckets with every round checksummed, with C, TS and Lean twins and its apple_m4 pins

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants