use proptest::prelude::*;
fn bandwidth_ceiling(effective_bw_gb_s: f64, model_bytes: u64) -> f64 {
effective_bw_gb_s / (model_bytes as f64 / 1e9)
}
fn compute_ceiling(effective_gflops: f64, ops_per_token: u64) -> f64 {
effective_gflops * 1e9 / ops_per_token as f64
}
fn model_bytes(total_params: u64, bits_per_weight: u32) -> u64 {
total_params * u64::from(bits_per_weight) / 8
}
proptest! {
#[test]
fn prop_ceiling_positive(
bw_gb_s in 1.0f64..2000.0, gflops in 1.0f64..1000.0, params in 1_000u64..100_000_000_000, bits in prop::sample::select(vec![2u32, 4, 8, 16, 32]),
ops in 1_000u64..1_000_000_000 ) {
let mb = model_bytes(params, bits);
prop_assert!(mb > 0, "model_bytes must be > 0");
let bw_ceil = bandwidth_ceiling(bw_gb_s, mb);
prop_assert!(
bw_ceil > 0.0 && bw_ceil.is_finite(),
"bandwidth ceiling={}, expected > 0 and finite", bw_ceil
);
let compute_ceil = compute_ceiling(gflops, ops);
prop_assert!(
compute_ceil > 0.0 && compute_ceil.is_finite(),
"compute ceiling={}, expected > 0 and finite", compute_ceil
);
}
#[test]
fn prop_memory_bound_classification(
bw_gb_s in 1.0f64..2000.0,
gflops in 1.0f64..1000.0,
params in 1_000_000u64..10_000_000_000,
bits in prop::sample::select(vec![4u32, 8, 16]),
ops in 100_000u64..100_000_000
) {
let mb = model_bytes(params, bits);
let bw_ceil = bandwidth_ceiling(bw_gb_s, mb);
let compute_ceil = compute_ceiling(gflops, ops);
let is_memory_bound = bw_ceil < compute_ceil;
let bottleneck = bw_ceil.min(compute_ceil);
if is_memory_bound {
prop_assert!(
(bottleneck - bw_ceil).abs() < 1e-6,
"memory-bound but bottleneck={} != bw_ceil={}", bottleneck, bw_ceil
);
} else {
prop_assert!(
(bottleneck - compute_ceil).abs() < 1e-6,
"compute-bound but bottleneck={} != compute_ceil={}", bottleneck, compute_ceil
);
}
}
#[test]
fn prop_throughput_bounded(
bw_gb_s in 1.0f64..2000.0,
gflops in 1.0f64..1000.0,
params in 1_000_000u64..10_000_000_000,
bits in prop::sample::select(vec![4u32, 8, 16]),
ops in 100_000u64..100_000_000,
throughput_factor in 0.0f64..2.0
) {
let mb = model_bytes(params, bits);
let bw_ceil = bandwidth_ceiling(bw_gb_s, mb);
let compute_ceil = compute_ceiling(gflops, ops);
let max_throughput = bw_ceil.min(compute_ceil);
let claimed = throughput_factor * max_throughput;
if claimed > max_throughput {
prop_assert!(
claimed > bw_ceil || claimed > compute_ceil,
"throughput {} exceeds max {} but doesn't violate any ceiling",
claimed, max_throughput
);
}
}
#[test]
fn prop_model_bytes_monotonic(
bw_gb_s in 10.0f64..1000.0,
params1 in 1_000_000u64..1_000_000_000,
extra in 1u64..1_000_000_000,
bits in prop::sample::select(vec![4u32, 8, 16, 32])
) {
let params2 = params1.saturating_add(extra);
let mb1 = model_bytes(params1, bits);
let mb2 = model_bytes(params2, bits);
prop_assert!(
mb2 >= mb1,
"model_bytes not monotonic: params1={}->bytes={}, params2={}->bytes={}",
params1, mb1, params2, mb2
);
if mb2 > mb1 {
let ceil1 = bandwidth_ceiling(bw_gb_s, mb1);
let ceil2 = bandwidth_ceiling(bw_gb_s, mb2);
prop_assert!(
ceil2 <= ceil1,
"bandwidth ceiling not monotonically decreasing: ceil1={}, ceil2={}",
ceil1, ceil2
);
}
}
#[test]
#[ignore = "SIMD equivalence — trueno domain"]
fn prop_simd_equivalence(
_x in proptest::collection::vec(-10.0f32..10.0, 1..32usize)
) {
}
}