API reference¶
Everything on this page is generated from the source docstrings.
Top level¶
sns.measure
¶
measure(fn: Callable[[], object], *, warmup: int = DEFAULT_WARMUP, iters: int = MIN_ITERS, device: int = 0, flush_l2: bool = True, policy: ClockPolicy | None = None, min_duration_us: float = MIN_DURATION_US) -> TimingResult
Time a callable honestly.
Returns an interval and a quality tier, never a bare number.
Known limitation: the reported CI is a bootstrap over samples within a single measurement window, so it captures sampling error inside that window but not run-to-run variability between windows. On unlocked hardware the cross-run spread can exceed the reported interval by orders of magnitude — scripts/validate_timing.py measures exactly this. Folding between-window variance into Tier B intervals is planned for Phase 1.
Source code in src/sns/timing.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
sns.compare
¶
compare(candidate_fn: Callable[[], object], baseline_fn: Callable[[], object], **kwargs) -> ComparisonResult
Measure a candidate against a freshly measured baseline.
Both sides are timed in the same process, under the same clock policy, back to back. The baseline is never read from cache — a stale baseline makes it impossible to distinguish a kernel regression from an upstream improvement, which is the whole point of the tool.
Known limitation: the candidate is measured first and the baseline second, so on unlocked hardware the second measurement runs on a warmer, more boosted GPU. Comparing identical work on an RTX 3060 laptop yielded a speedup of 0.962 rather than 1.0 from this effect alone. Tier A pinning largely removes it; Tier B and C comparisons carry it. Interleaving the two sides is planned for Phase 1.
Source code in src/sns/timing.py
Result types¶
sns.TimingResult
¶
Bases: BaseModel
A timing measurement.
Deliberately defines no float, int or index: a caller must not be able to collapse this into a bare number and lose the interval.
Source code in src/sns/types.py
sns.ComparisonResult
¶
Bases: BaseModel
A candidate measured against a baseline timed in the same session.
The baseline is never cached across runs. Re-measuring it every time is what lets us tell "my kernel regressed" from "torch got faster", and it is what makes the ratio comparable across machines and architectures.
Source code in src/sns/types.py
sns.MeasurementTier
¶
Bases: str, Enum
How much the numbers in a result can be trusted.
A: clocks locked and verified stable. Full verdicts, drift-eligible. B: clocks floating, variance measured and folded into the interval. C: unstable or throttled. No performance verdict is valid.
Source code in src/sns/types.py
sns.EnvironmentFingerprint
¶
Bases: BaseModel
Identifies the toolchain and device a run happened on.
Two runs are only comparable when their fingerprints match exactly.
Source code in src/sns/types.py
Clock policies¶
sns.clocks.UnlockedClockPolicy
¶
Measure without pinning. Honest, and the only option on most machines.
Source code in src/sns/clocks.py
sns.clocks.LockedClockPolicy
¶
Pin the SM clock, and optionally the power cap, verifying by readback.
Source code in src/sns/clocks.py
sns.clocks.ClockLockError
¶
sns.clocks.assign_tier
¶
Classify a measurement window.
Throttle flags alone are not sufficient: on an RTX 3060 laptop the SM clock swung 495 MHz (5.1% CV) while the flags stayed silent, and two identical runs disagreed on whether throttling fired at all. Observed variance is the governing signal.
Source code in src/sns/clocks.py
Statistics¶
sns.stats.bootstrap_ci
¶
bootstrap_ci(samples: list[float], confidence: float = 0.95, n_resamples: int = 2000, seed: int = 12648430) -> tuple[float, float]
Percentile bootstrap CI of the median.
Seeded so a given sample set always yields the same interval — a reproducibility requirement, not a convenience.
Source code in src/sns/stats.py
sns.stats.ratio_ci
¶
ratio_ci(candidate: list[float], baseline: list[float], confidence: float = 0.95, n_resamples: int = 2000, seed: int = 12648430) -> tuple[float, float]
CI of speedup = median(baseline) / median(candidate).
Values above 1.0 mean the candidate is faster. Resampling both sides independently propagates uncertainty from each into the ratio, which a naive ratio-of-medians throws away.
Source code in src/sns/stats.py
sns.stats.percentile
¶
Linear-interpolated percentile. p is in [0, 1].
Source code in src/sns/stats.py
sns.stats.cv_percent
¶
Coefficient of variation as a percentage. 0.0 for a zero mean.
Source code in src/sns/stats.py
Environment¶
sns.env.capture_fingerprint
¶
Source code in src/sns/env.py
sns.env.arch_family
¶
Source code in src/sns/env.py
Telemetry¶
sns.telemetry.ClockSampler
¶
Samples SM clock and throttle state cheaply, or not at all.
If NVML is unavailable we collect NO clock evidence rather than collecting bad evidence. Tier A requires clock evidence, so a host without NVML can never reach it. That is the intended, conservative degradation.
Source code in src/sns/telemetry.py
throttled_now
¶
True if any throttle reason other than 'GpuIdle' is currently set.