Skip to content

test(bench): establish reproducible Criterion host baseline (#22) - #51

Merged
code-tc merged 2 commits into
mainfrom
tembo/issue-22-benchmark-baseline
Jul 28, 2026
Merged

test(bench): establish reproducible Criterion host baseline (#22)#51
code-tc merged 2 commits into
mainfrom
tembo/issue-22-benchmark-baseline

Conversation

@tembo

@tembo tembo Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Establishes a reproducible Criterion benchmark baseline on main for the host/Rayon platform, ahead of the CubeCL HAL migration. Host-only, built against the current public API with --no-default-features. No public API or default features are changed. Draft PR per the issue execution contract (draft_pr_only: true, completion authority: human).

Changed files

  • Cargo.toml — add criterion dev-dependency (default-features = false, cargo_bench_support) and the host_benchmarks [[bench]] target (harness = false).
  • benches/host_benchmarks.rs — the six benchmark categories over the documented shape matrix (harness = false, custom main prints the environment block).
  • tests/benchmark_support/mod.rs — shared deterministic fixture + environment-recording utility (included via #[path] by both the bench and the determinism test).
  • tests/bench_determinism.rs — verifies the fixture is deterministic, in range, seed-distinct, and that environment probing succeeds.
  • docs/benchmarking/README.md — inventory, local execution, environment recording, comparison rules, and how Introduce backend abstraction and minimal CubeCL backend #34[Validation] Add reproducible CubeCL CPU and accelerator conformance runner #50 should add comparable CubeCL groups without changing these host baselines.
  • docs/benchmarking/initial-results.md — initial result artifact + exact environment identity.
  • .github/workflows/benchmarks.yml — CI step compiling benchmarks with cargo bench --no-run --no-default-features (no timing on shared CI), plus fmt check and host-only tests.
  • README.md — replaced the stale benchmark-branch instructions with a pointer to the new baseline.

Cargo.lock is intentionally not committed (the repo gitignores it for a library).

Benchmark inventory and operation mapping

ha-ndarray ops are lazy; operation-only benchmarks build deterministic input data once outside the measured region, build a cheap borrowed view per iteration in the untimed iter_batched setup, and measure op construction + materialization via NDArrayRead::buffer. criterion::black_box is used throughout. construct_convert is the only intentionally end-to-end group (includes allocation + copy).

# Category Public API Benchmark group
1 construction ArrayBuf::convert(&data, shape) (alloc + copy) construct_convert
2 unary elementwise NDArrayUnary::exp unary_exp
3 binary elementwise NDArrayMath::add (same-shape) binary_add
3 binary (broadcast) NDArrayTransform::broadcast + NDArrayMath::add binary_add_broadcast
4 reduction NDArrayReduceAll::sum_all reduce_sum_all
5 matrix multiply MatrixDual::matmul matmul
6 non-contiguous view NDArrayTransform::transpose (materialized) transpose

Substitution note: axis-reduction (NDArrayReduce::sum) requires an owned 'static accessor via the public reduce_axes path (Accessor::from(A) has a B: 'static bound), so sum_all (available on borrowed inputs) is used as the representative reduction. No product functionality was added to make a benchmark possible.

Shape matrix: elementwise/reduction/transform use [16,16] (latency), [256,256] (medium), [1024,1024] (throughput); matmul uses [16,16], [96,96], [256,256]. IDs encode dtype/shape (e.g. matmul/f32/256x256).

Exact commands executed

cargo fmt --all -- --check
cargo test --no-default-features
cargo bench --no-run --no-default-features
cargo bench --no-default-features

Environment / toolchain identity

rustc: rustc 1.96.0 (ac68faa20 2026-05-25)
cargo: cargo 1.96.0 (30a34c682 2026-05-25)
os: linux
arch: x86_64
cpu_model: Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz
logical_cores: 2
physical_cores: 2
feature_set: no-default-features (host-only, Rayon)

Benchmark compilation result

cargo bench --no-run --no-default-features succeeds in a clean checkout (Finished \bench` profile [optimized]`).

Initial Criterion result artifact

All 21 benchmarks; Criterion reports [lower mean upper]. Full machine-readable output is in target/criterion/<group>/<bench>/new/estimates.json (not committed); see docs/benchmarking/initial-results.md for the complete table. Highlights:

Benchmark Mean
construct_convert/f32/1024x1024 345.59 µs
unary_exp/f32/1024x1024 2.3161 ms
binary_add/f32/1024x1024 857.92 µs
binary_add_broadcast/f32/1024x1024 9.8600 ms
reduce_sum_all/f32/1024x1024 623.98 µs
matmul/f32/256x256 14.574 ms
transpose/f32/1024x1024 12.435 ms

These numbers are specific to the machine above and are a baseline, not a threshold.

Total benchmark duration

cargo bench --no-default-features (21 benchmarks, sample_size=10, warm_up_time=1s, measurement_time=3s): 103 s wall time.

Test results

cargo test --no-default-features — all host-only tests pass, including the 5 new bench_determinism tests (arithmetic 2, bench_determinism 5, compare 7, cond 1, construct 3, linalg 2, reduce 3, transform 9).

Known limitations / unavailable validation

Implements #22.

Comment thread .github/workflows/benchmarks.yml Outdated
@code-tc
code-tc marked this pull request as ready for review July 28, 2026 12:08
@code-tc
code-tc self-requested a review July 28, 2026 12:08
@code-tc
code-tc merged commit 76bbf1f into main Jul 28, 2026
@code-tc
code-tc deleted the tembo/issue-22-benchmark-baseline branch July 28, 2026 12:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c80103fe81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +70 to +71
fn input_view(data: &[f32], shape: Shape) -> ArrayBuf<f32, &[f32]> {
ArrayBuf::new(data, shape).expect("construct input view")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pin the host benchmarks to the host platform

When this target is compiled with --features opencl or --all-features—which the documented future accelerator groups will require—ArrayBuf uses the top-level Platform, whose select implementation in src/platform.rs dispatches inputs of at least GPU_MIN_SIZE to OpenCL. Consequently, these supposedly stable host groups (including construction at line 87) will benchmark OpenCL for the medium and large cases while still reporting host-only, Rayon, corrupting the intended host-versus-accelerator comparison. Use explicitly host-backed array types or otherwise prevent these groups from being built on the feature-dependent top-level platform.

Useful? React with 👍 / 👎.

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.

1 participant