Repository navigation
feat(bench): Record GPU state, sustain GEMM rounds, and flag round spread - #27
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ounds Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
78c16fe to
dd7a97a
Compare
A100 host copies on main came from a half-speed host
What I confirmed
Hypothesis (not verified)The slow runs all landed on driver 610.57.04 hosts. I think that points to a different Modal host pool, not to the driver itself. I haven't tested driver 610 on a fast host or 580 on a slow one, and Modal's gVisor sandbox exposes no lspci or Proposed guard (patch below, not pushed)
With the patch applied, Blocked onRe-running the A100 calibration (
Next steps
Patch (git diff against main b09c64b)diff --git a/README.md b/README.md
index 5e70ffe..b074fa6 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,9 @@ Host copies ran on A100 at PCIe Gen4 x16, and H100 and B200 at Gen5 x16. B300's
GPU link trains at Gen6 x16, but `nvidia-smi` reports `Host Max: 5`: each HGX
B300 GPU connects at Gen6 to the PCIe switch inside its ConnectX-8 NIC, then
Gen5 x16 to the CPU. B300 host copies are therefore Gen5-bound, like B200 and
-H100.
+H100. A benchmark also rejects a host link when its slower copy direction
+delivers less than 70% of the effective PCIe rate, allowing for packet overhead
+while catching links that negotiate full speed but transfer at about half rate.
**Note 1:** Compute figures are dense, not sparse. NVIDIA's headline Tensor
Core numbers assume structured sparsity; dense is half.
diff --git a/crates/napkin-bench/src/cuda.rs b/crates/napkin-bench/src/cuda.rs
index fa9441a..1c4f234 100644
--- a/crates/napkin-bench/src/cuda.rs
+++ b/crates/napkin-bench/src/cuda.rs
@@ -1062,9 +1062,7 @@ pub(crate) fn run(cfg: &Config, gpu_request: &str) -> Result<Measured, BenchErro
let (cc_major, cc_minor) = ctx0.compute_capability()?;
let sm_count =
ctx0.attribute(dsys::CUdevice_attribute::CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT)?;
- let all_ok = checks.values().all(|v| *v);
-
- Ok(Measured {
+ let mut measured = Measured {
captured_at: crate::iso_now(),
gpu_request: if cfg.quick {
format!("{gpu_request} --quick")
@@ -1110,26 +1108,45 @@ pub(crate) fn run(cfg: &Config, gpu_request: &str) -> Result<Measured, BenchErro
.state(cfg.gemm_warmup, cfg.gemm_round, gemm_states)
.map_err(BenchError)?,
),
- })
- .and_then(|m| {
- if all_ok {
- Ok(m)
- } else {
- eprintln!(
- "FAILED CHECKS: {:?}",
- m.checks
- .iter()
- .filter(|(_, v)| !**v)
- .map(|(k, _)| k)
- .collect::<Vec<_>>()
- );
- println!(
- "{}",
- serde_json::to_string_pretty(&m).map_err(|e| BenchError(e.to_string()))?
- );
- Err(BenchError(
- "one or more correctness checks failed".to_owned(),
- ))
- }
- })
+ };
+ if let Some(link_gbps) = measured.pcie_link_gbps()
+ && let Some(at_speed) = measured.pcie_link_at_speed()
+ {
+ let fraction = measured.h2d_gbps.min(measured.d2h_gbps) / link_gbps;
+ progress(
+ "pcie bandwidth",
+ &format!(
+ "{:.1}/{:.1} GB/s = {:.0}% of {:.1} GB/s link",
+ measured.h2d_gbps,
+ measured.d2h_gbps,
+ fraction * 100.0,
+ link_gbps,
+ ),
+ );
+ measured
+ .checks
+ .insert("pcie_link_bandwidth".to_owned(), at_speed);
+ }
+
+ if measured.checks.values().all(|passed| *passed) {
+ Ok(measured)
+ } else {
+ eprintln!(
+ "FAILED CHECKS: {:?}",
+ measured
+ .checks
+ .iter()
+ .filter(|(_, passed)| !**passed)
+ .map(|(name, _)| name)
+ .collect::<Vec<_>>()
+ );
+ println!(
+ "{}",
+ serde_json::to_string_pretty(&measured)
+ .map_err(|error| BenchError(error.to_string()))?
+ );
+ Err(BenchError(
+ "one or more correctness checks failed".to_owned(),
+ ))
+ }
}
diff --git a/crates/napkin-profile/src/lib.rs b/crates/napkin-profile/src/lib.rs
index 9479a70..585cc89 100644
--- a/crates/napkin-profile/src/lib.rs
+++ b/crates/napkin-profile/src/lib.rs
@@ -283,6 +283,13 @@ pub struct Span {
pub max: f64,
}
+/// Minimum fraction of theoretical `PCIe` rate accepted for host copies.
+///
+/// Healthy hosts reach about 83–91% of raw link rate after packet overhead;
+/// 70% rejects links that negotiate full speed but deliver about half of it,
+/// as on the A100 driver-610 host (12.3 GB/s over Gen4 x16).
+pub const PCIE_MIN_LINK_FRACTION: f64 = 0.7;
+
impl Measured {
/// Returns the `PCIe` generation available for host↔device transfers.
#[must_use]
@@ -292,6 +299,29 @@ impl Measured {
.map_or(generation, |host_max| generation.min(host_max))
})
}
+
+ /// Returns the theoretical per-direction rate of the effective `PCIe`
+ /// link in GB/s.
+ #[must_use]
+ pub fn pcie_link_gbps(&self) -> Option<f64> {
+ let per_lane_gbps = match self.pcie_effective_gen()? {
+ 1 => 0.25,
+ 2 => 0.5,
+ 3 => 8.0 * 128.0 / 130.0 / 8.0,
+ 4 => 16.0 * 128.0 / 130.0 / 8.0,
+ 5 => 32.0 * 128.0 / 130.0 / 8.0,
+ 6 => 8.0,
+ _ => return None,
+ };
+ Some(per_lane_gbps * f64::from(self.pcie_width?))
+ }
+
+ /// Whether both measured host-copy directions reach the minimum share of
+ /// the effective link rate, or None when the link rate cannot be derived.
+ #[must_use]
+ pub fn pcie_link_at_speed(&self) -> Option<bool> {
+ Some(self.h2d_gbps.min(self.d2h_gbps) >= PCIE_MIN_LINK_FRACTION * self.pcie_link_gbps()?)
+ }
}
/// Where a rate came from.
diff --git a/crates/napkin/build.rs b/crates/napkin/build.rs
index 95e26e4..984bb48 100644
--- a/crates/napkin/build.rs
+++ b/crates/napkin/build.rs
@@ -452,6 +452,14 @@ fn validate_ceiling(id: &str, ceiling: &Ceiling) -> Result<(), String> {
}
fn validate_measured(id: &str, measured: &Measured) -> Result<(), String> {
+ if measured.pcie_link_at_speed() == Some(false)
+ && let Some(link_gbps) = measured.pcie_link_gbps()
+ {
+ return Err(format!(
+ "measured profile {id:?} is below the PCIe bandwidth floor: H2D {:.1} GB/s, D2H {:.1} GB/s, effective link {:.2} GB/s (70% floor); re-run `modal run modal/bench.py --gpu {id}` on another host",
+ measured.h2d_gbps, measured.d2h_gbps, link_gbps
+ ));
+ }
if let Some((name, _)) = measured.checks.iter().find(|(_, passed)| !**passed) {
return Err(format!(
"measured profile {id:?} has failing check {name:?}"
diff --git a/crates/napkin/src/profile.rs b/crates/napkin/src/profile.rs
index be786d7..66db999 100644
--- a/crates/napkin/src/profile.rs
+++ b/crates/napkin/src/profile.rs
@@ -87,6 +87,63 @@ mod tests {
}
}
+ #[test]
+ fn pcie_link_gbps_uses_effective_generation_and_width() {
+ let parsed = serde_json::from_str::<napkin_profile::Measured>(include_str!(
+ "../../../profiles/h100.measured.json"
+ ));
+ assert!(parsed.is_ok(), "H100 measured profile fixture parses");
+ if let Ok(mut measured) = parsed {
+ measured.pcie_gen = Some(4);
+ measured.pcie_gen_host_max = Some(4);
+ measured.pcie_width = Some(16);
+ assert!(
+ measured
+ .pcie_link_gbps()
+ .is_some_and(|rate| (rate - 31.51).abs() < 0.01)
+ );
+
+ measured.pcie_gen = Some(6);
+ measured.pcie_gen_host_max = Some(5);
+ assert!(
+ measured
+ .pcie_link_gbps()
+ .is_some_and(|rate| (rate - 63.02).abs() < 0.01)
+ );
+
+ measured.pcie_gen = None;
+ assert_eq!(measured.pcie_link_gbps(), None);
+ measured.pcie_gen = Some(4);
+ measured.pcie_width = None;
+ assert_eq!(measured.pcie_link_gbps(), None);
+ }
+ }
+
+ #[test]
+ fn pcie_link_at_speed_checks_the_slower_direction() {
+ let parsed = serde_json::from_str::<napkin_profile::Measured>(include_str!(
+ "../../../profiles/h100.measured.json"
+ ));
+ assert!(parsed.is_ok(), "H100 measured profile fixture parses");
+ if let Ok(mut measured) = parsed {
+ measured.pcie_gen = Some(4);
+ measured.pcie_gen_host_max = Some(4);
+ measured.pcie_width = Some(16);
+
+ measured.h2d_gbps = 26.3;
+ measured.d2h_gbps = 26.1;
+ assert_eq!(measured.pcie_link_at_speed(), Some(true));
+
+ measured.h2d_gbps = 12.3;
+ measured.d2h_gbps = 13.1;
+ assert_eq!(measured.pcie_link_at_speed(), Some(false));
+
+ measured.h2d_gbps = 26.3;
+ measured.d2h_gbps = 12.4;
+ assert_eq!(measured.pcie_link_at_speed(), Some(false));
+ }
+ }
+
#[test]
fn measured_json_without_gpu_state_parses() {
let mut json: serde_json::Value = |
Closes #5
Summary
napkin-benchopens NVML (libnvidia-ml) at run time throughnvml-wrapper0.13. That's the same dynamic loading cudarc uses, and it adds no newunsafe. NVML resolves the CUDA device by PCI bus ID. While the GEMM rounds run, a second thread polls every 5 ms. Each round storeswall_ms, SM and memory clock spans, temperature, power from energy-counter ticks (nullwhen the counter ticked fewer than twice), and how many polls saw each clock-limit reason. This isMeasured.gpu_state(GpuState/RoundState/Spaninnapkin-profile). It is#[serde(default)], so older profiles still parse.napkin tableprints a per-dtype state table, and AGENTS.md pluslint-arch.shnow allow napkin-bench to import those types.GpuStaterecordswarmup_ms/round_ms, and each round records its realwall_ms.Measured::round_spread= slowest round / fastest round − 1. Cells whose rounds spread more thanSPREAD_FLAG(5%) get †, and a footnote names the spreads. The footnote calls the spread an observed range of 7 rounds, not a confidence interval, and says the cell is the median round. The threshold is documented in the README methodology.Investigation (H100!:2 first): power/clock hypothesis confirmed
Probes ran on
H100!:2, driver 610.57.04, with 10-call rounds (the old method). Those hosts had PCIe gen4 links against a gen5 maximum, sopcie_full_linkfailed and none of their numbers are committed. The GEMM data from them is still valid evidence.sw_power_capshowed up from round 4 and the SM clock dropped. fp32 stayed at 52 TFLOP/s and 1980 MHz with no cap, 0.1% spread.sw_power_capengages by about 170 ms. After that the SM clock moves between 1080 and 1500 MHz (548–731 TFLOP/s) for the whole run, a 39% spread. bf16 and tf32 behave the same. The temperature went from 35 to 53 °C and no thermal reason ever appeared.sw_power_capat the 1100 W limit, so the published B300 fp16 rate drops from 1700 to 1314 TFLOP/s. B200 fp16 runs at about 1050 of 1965 MHz at 1000 W, and drops from 1500 to 1251. With the sustained method, B200 and B300 rounds agree within 2%.wall_ms.Deviation from the issue: the 5% flag also fires for non-GEMM rows such as host copies and launch, because the README says "a metric's spread". Those rows have no clock state attached; their noise likely comes from host or PCIe effects (hypothesis, not investigated).
Runs
All on Modal, napkin-bench at this branch (sustained rounds, commit 5944ac9), CUDA 12.9,
modal run modal/bench.py --gpu <gpu>. Every committed run has a full PCIe link:A100-80GB:2H100!:2B200:2B300:2Hosts with degraded links were rejected and rerun: H100 three times at gen4/gen5, and B300 three times reporting gen6 current against a gen5 host maximum. A separate-process pynvml probe on B300 confirmed NVML calls stay fast under load (energy counter p50 4 ms).
The README's hand-written cost example (1 EFLOP bf16 job) is updated for the new B200 rate: 750 s, $1.30 / $4.34, break-even 0.83 instead of 0.73. Its conclusion is unchanged.
Link to Devin session: https://app.devin.ai/sessions/de93f9e3a0d94c2ca7f3960d81528607
Open in Devin Desktop: https://app.devin.ai/desktop/session/de93f9e3a0d94c2ca7f3960d81528607?variant=devin
Requested by: @gpu004