Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ keywords = ["computer-vision", "deep-learning", "image-processing", "onnx", "vid
[workspace.dependencies]
thiserror = "2"
rustc-hash = "2.1.3"
# Every benchmark and latency harness in the workspace installs this as its
# global allocator, so measurements are allocator-comparable across targets.
# Library crates deliberately do not — a library must leave that choice to the
# binary at the top of the dependency graph.
mimalloc = { version = "0.1", default-features = false }

[workspace.lints.rust]
unsafe_code = "deny"
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,20 @@ All hot paths have hand-tuned SIMD for three architectures with runtime CPU dete
| **Threading** | GCD dispatch_apply (~0.3µs) | std::thread::scope (~1µs) | std::thread::scope (~1µs) |
| **GPU inference** | MPSGraph | wgpu/Vulkan | wgpu/Vulkan |
| **Softmax** | Fused NEON | Fused AVX/SSE | Fused NEON |
| **Allocator** | mimalloc | mimalloc | mimalloc |
| **Bench-harness allocator** | mimalloc | mimalloc | mimalloc |

SIMD dispatch is automatic at runtime — no need for `-C target-cpu` flags (though they help: `-C target-cpu=apple-m1` or `-C target-cpu=native` for best codegen). The framework detects CPU features once through `yscv-cpu` and routes kernels through cached `host_cpu().features` gates. `yscv_kernels::runtime_dispatch_report()` exposes the typed CPU/kernel selection snapshot, while `runtime_config_report()` records active `YSCV_*` A/B overrides for reproducible benchmark logs. 570 `#[target_feature]`-gated functions total, all with scalar fallback for WASM/RISC-V/Miri.

The allocator row applies to the benchmark and latency harnesses, which all
install mimalloc so their numbers stay comparable. The library crates set no
global allocator — that is a whole-program choice, so it belongs to your
binary. If you want mimalloc in your own build, add the two lines yourself:

```rust
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
```

### Recommended release profile

For best performance, the workspace already includes an optimized release profile in `Cargo.toml`:
Expand Down
2 changes: 1 addition & 1 deletion apps/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ yscv-video = { path = "../../crates/yscv-video" }
yscv-detect = { path = "../../crates/yscv-detect" }
yscv-track = { path = "../../crates/yscv-track" }
yscv-optim = { path = "../../crates/yscv-optim" }
mimalloc = { version = "0.1", default-features = false }
mimalloc.workspace = true

[[bin]]
name = "yscv-bench"
Expand Down
3 changes: 3 additions & 0 deletions apps/bench/src/fpv_latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
//! can model a real board's timing distribution without requiring that
//! HW to be physically attached.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Duration, Instant};
Expand Down
1 change: 1 addition & 0 deletions apps/camera-face-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ thiserror.workspace = true

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
mimalloc.workspace = true

[[bench]]
name = "camera_face_runtime_ops"
Expand Down
3 changes: 3 additions & 0 deletions apps/camera-face-tool/benches/camera_face_runtime_ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use criterion::{Criterion, black_box, criterion_group, criterion_main};
use serde_json::{Value, json};
use yscv_detect::{
Expand Down
1 change: 1 addition & 0 deletions apps/llm-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror.workspace = true
rustc-hash.workspace = true
mimalloc.workspace = true

[lints]
workspace = true
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/bench_tracker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Minimal yscv tracker benchmark that uses the current workspace crates.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::path::Path;
use std::process::ExitCode;
use std::time::Instant;
Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/calib_accuracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
//! cargo run --release --bin calib_accuracy -p yscv-llm-bench
//! ```

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use yscv_onnx::quantize::{
CalibrationCollector,
derive::{QuantTarget, derive_mse_optimal, derive_percentile, derive_symmetric},
Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/compute_gap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::time::Instant;

use yscv_kernels::{
Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//! of an ONNX model. Used to detect cached-decoder protocols
//! (past_key_values.{i}.{key,value}) before wiring up the bench harness.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use yscv_onnx::load_onnx_model_from_file;

fn main() {
Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/kernel_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
//! cargo run --release --bin kernel_bench -p yscv-llm-bench
//! ```

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::time::Instant;

use yscv_kernels::{
Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/nchwc_coverage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use rustc_hash::FxHashMap;
/// NCHWc layout coverage probe — Step 0 of NCHWc-everywhere plan.
///
Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/bin/quantize_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
//! `calib_accuracy --model`. Without `--output` the QDQ save+reload step
//! is skipped — useful when iterating on the calibration count alone.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::path::{Path, PathBuf};
use std::process::ExitCode;

Expand Down
3 changes: 3 additions & 0 deletions apps/llm-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
//! See `apps/llm-bench/README.md` for end-to-end download + quantize +
//! bench instructions for TinyLlama-1.1B.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::path::PathBuf;
use std::process::ExitCode;
use std::time::Instant;
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/onnx-models/benches/onnx_models.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
use yscv_onnx::{OnnxModel, OnnxRunner, load_onnx_model_from_file, optimize_onnx_graph};
use yscv_onnx_model_bench::{asset_dir, download_assets, make_inputs, model_cases};
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/onnx-models/examples/bench_yolo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//! Set BENCH_COOLDOWN=<secs> to insert a cooldown pause between benchmarks.
//! The default is 0; callers that need thermal control must opt in.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use rustc_hash::FxHashMap;
use yscv_onnx::load_onnx_model_from_file;
use yscv_onnx_model_bench::{asset_dir, download_assets, make_inputs, model_cases};
Expand Down
19 changes: 19 additions & 0 deletions benchmarks/rust-competitors/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions benchmarks/rust-competitors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ publish = false

[dependencies]
tract-onnx = { version = "0.21", optional = true }
# Matches the allocator the yscv harnesses use, so competitor numbers are not
# a yscv-on-mimalloc vs tract-on-system-malloc comparison.
mimalloc = { version = "0.1", default-features = false }

[features]
default = ["tract"]
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/rust-competitors/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Benchmark competitor ONNX runtimes (tract, candle) against yscv.
//! Outputs JSON timing results for automated comparison.

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::time::Instant;

fn main() {
Expand Down
1 change: 1 addition & 0 deletions crates/yscv-autograd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ thiserror.workspace = true

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
mimalloc.workspace = true

[[bench]]
name = "autograd_graph_ops"
Expand Down
3 changes: 3 additions & 0 deletions crates/yscv-autograd/benches/autograd_graph_ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use criterion::{Criterion, black_box, criterion_group, criterion_main};
use yscv_autograd::Graph;
use yscv_tensor::Tensor;
Expand Down
1 change: 1 addition & 0 deletions crates/yscv-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ thiserror.workspace = true

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
mimalloc.workspace = true

[[bench]]
name = "cli_runtime_ops"
Expand Down
3 changes: 3 additions & 0 deletions crates/yscv-cli/benches/cli_runtime_ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use criterion::{Criterion, black_box, criterion_group, criterion_main};
use yscv_detect::{
BoundingBox, CLASS_ID_FACE, CLASS_ID_PERSON, Rgb8FaceDetectScratch, Rgb8PeopleDetectScratch,
Expand Down
1 change: 1 addition & 0 deletions crates/yscv-detect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustc-hash.workspace = true

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
mimalloc.workspace = true
proptest = "1"

[[bench]]
Expand Down
3 changes: 3 additions & 0 deletions crates/yscv-detect/benches/detect_heatmap_scratch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use criterion::{Criterion, black_box, criterion_group, criterion_main};
use yscv_detect::{
FrameFaceDetectScratch, FramePeopleDetectScratch, HeatmapDetectScratch,
Expand Down
1 change: 1 addition & 0 deletions crates/yscv-eval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustc-hash.workspace = true

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
mimalloc.workspace = true

[[bench]]
name = "eval_metrics_ops"
Expand Down
3 changes: 3 additions & 0 deletions crates/yscv-eval/benches/eval_metrics_ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::time::Duration;

use criterion::{Criterion, black_box, criterion_group, criterion_main};
Expand Down
Loading
Loading