Pure Bend examples for algorithms that want thousands of lightweight threads.
BendKernels is a small benchmark and learning repo for Bend, a high-level language that exposes parallelism from ordinary recursive structure. The goal is not to replace Rust, C, or CUDA for every workload. The goal is to show the kinds of programs where Bend's compiler/runtime can find a lot of independent work without explicit threads, locks, atomics, or GPU kernels.
Most parallel examples hide the interesting part behind a framework. Bend makes the parallel shape visible in the program itself:
- balanced recursion
- tree folds
- divide-and-conquer algorithms
- sorting networks
- independent map/reduce kernels
The exact same .bend file can be run on the reference runtime, parallel CPU runtime, or CUDA runtime when supported by the machine.
| Example | Pattern | What it demonstrates |
|---|---|---|
examples/parallel_sum.bend |
tree generation + fold | balanced reduction over independent branches |
examples/tree_map_reduce.bend |
map/reduce | independent leaf kernels with a final checksum |
examples/bitonic_sort.bend |
sorting network | compare/swap structure that maps well to parallel execution |
examples/fibonacci_modes.bend |
branching vs sequential recursion | parallelism is not the same as algorithmic efficiency |
examples/ai/tiny_mlp.bend |
neural-network inference | independent hidden neurons and batch samples |
examples/ai/minimax_tree.bend |
game-tree search | independent child-position evaluation |
examples/ai/ensemble_vote.bend |
ensemble inference | independent weak-learner votes over a batch |
See docs/ai-kernels.md for the AI-focused examples.
cargo install hvm
cargo install bend-lang
bend --versionFor GPU execution, install the NVIDIA CUDA toolkit supported by Bend/HVM, then use bend run-cu.
Reference runtime:
bend run-rs examples/parallel_sum.bend -sParallel CPU runtime:
bend run-c examples/parallel_sum.bend -sCUDA runtime, on supported NVIDIA systems:
bend run-cu examples/parallel_sum.bend -sRun the full smoke set locally:
bend run-rs examples/parallel_sum.bend
bend run-rs examples/tree_map_reduce.bend
bend run-rs examples/bitonic_sort.bend
bend run-rs examples/fibonacci_modes.bend
bend run-rs examples/ai/tiny_mlp.bend
bend run-rs examples/ai/minimax_tree.bend
bend run-rs examples/ai/ensemble_vote.bend
bend run-c examples/parallel_sum.bendbend run-rs examples/parallel_sum.bendResult: 8386560
Run the same source on the parallel CPU runtime:
bend run-c examples/parallel_sum.bendResult: 8386560
With Bend's stats flag, you can compare runtime behavior. Numbers vary by machine, but the checksum should match:
bend run-rs examples/parallel_sum.bend -s
bend run-c examples/parallel_sum.bend -sExample output from one local run:
Result: 8386560
- ITRS: 360395
- TIME: 0.01s
- MIPS: 28.19
Result: 8386560
- ITRS: 352203
- TIME: 0.01s
- MIPS: 55.38
bend run-rs examples/tree_map_reduce.bendResult: 2064384
bend run-rs examples/bitonic_sort.bendResult: 32640
bend run-rs examples/fibonacci_modes.bendResult: 13530
This example intentionally includes both a branching recursive Fibonacci and a tail-recursive Fibonacci. It is a reminder that more parallel structure does not automatically mean a better algorithm.
bend run-rs examples/ai/tiny_mlp.bendResult: 426312
This runs a fixed integer neural-network forward pass over a synthetic batch and returns the batch-score checksum.
bend run-rs examples/ai/minimax_tree.bendResult: 745
This evaluates a synthetic ternary game tree with alternating min/max layers.
bend run-rs examples/ai/ensemble_vote.bendResult: 2024
This evaluates several independent decision stumps across a synthetic batch and returns the positive-class count.
Bend currently uses 24-bit numeric types, so large integer examples may wrap modulo 2^24. The examples return checksums rather than printing arrays or images, because Bend's IO ecosystem is still young and benchmark-style programs are easier to compare across runtimes.
When comparing runtimes, look at Bend's -s output:
bend run-rs examples/bitonic_sort.bend -s
bend run-c examples/bitonic_sort.bend -s
bend run-cu examples/bitonic_sort.bend -sGood Bend candidates usually have lots of independent subproblems. Bad candidates are "helplessly sequential": each step depends on the exact result of the previous step.
- matrix multiplication checksum
- Mandelbrot / fractal checksum
- N-body simulation checksum
- prefix scan
- larger AI inference/search kernels
- benchmark result tables across CPU and GPU machines
MIT