boonzy00/var
No description provided.
GPU for narrow. CPU for broad. Auto-routed by query volume.
const var = @import("var");
const router = var.VAR.init(null);
const decision = router.route(query_volume, world_volume);
VAR is a single-function decision engine that tells you whether a spatial query should run on the CPU or GPU, based on how much of the world it touches.
if (query_volume / world_volume < threshold) {
return .gpu;
} else {
return .cpu;
}
That’s it.
| Query Type | Expected Hits | Best Processor | Why |
|---|---|---|---|
| Narrow (frustum, point, small box) | < 100 objects | GPU | Parallelism wins |
| Broad (proximity, physics, large region) | > 1,000 objects | CPU | Memory bandwidth wins |
Manual routing = bugs, tuning, inconsistency.
VAR = one line, zero tuning, deterministically correct.
VAR routes correctly based on selectivity, optimizing for parallelism (GPU) vs. memory bandwidth (CPU).
Validated with comprehensive unit tests covering edge cases.
Use VAR any time you:
Examples:
Install
zig fetch --save https://github.com/boonzy00/var/archive/v0.1.0.tar.gz
Basic
const var = @import("var");
const router = var.VAR.init(null);
const world_vol = 1000.0 * 1000.0 * 1000.0; // 1km³
const query_vol = 10.0 * 10.0 * 10.0; // 10m box
const decision = router.route(query_vol, world_vol);
// → .gpu
With Your Own Volume Logic
fn boxVolume(size: @Vector(3, f32)) f32 {
return size[0] * size[1] * size[2];
}
const query_vol = boxVolume(.{10, 10, 10});
const decision = router.route(query_vol, world_vol);
const router = var.VAR.init(.{
.gpu_threshold = 0.005, // More aggressive GPU usage
.cpu_cores = 16, // Adjusts threshold slightly
.gpu_available = true, // Set false on CPU-only systems
});
selectivity = query_volume / world_volume
if (selectivity < threshold) {
return .gpu;
} else {
return .cpu;
}
| Case | Behavior |
|---|---|
| world_volume == 0 | → .cpu |
| gpu_available = false | → .cpu |
| Negative volumes | → clamped to 0 |
| Infinite / NaN | → .cpu |
Run the official benchmark script for reproducible, statistically rigorous results:
cd bench
./run_bench.sh
This generates bench-results.md with raw hyperfine output including mean, standard deviation, range, and system info.
Latest results (AMD Ryzen 7 5700, Zig 0.15.1):
bench/bench-results.md Full benchmark report: bench-results.md
zig build test
For performance benchmarks:
cd bench && ./run_bench.sh
MIT