fhelium.benchmarks.timing
Device-aware timing and CUDA allocator helpers for benchmark workloads.
DeviceLike
data View source
DeviceLike: TypeAlias = torch.device | str | int | NoneCudaMemoryBaseline
class View source
CudaMemoryBaseline(device: torch.device | None, allocated_bytes: int, reserved_bytes: int)Allocator counters captured immediately after resetting peak statistics.
Attributes
| Name | Type | Default/value |
|---|---|---|
device | torch.device | None | |
allocated_bytes | int | |
reserved_bytes | int |
synchronize
function View source
def synchronize(device: DeviceLike=None) -> None: ...Synchronize device when it is CUDA.
Omitting device preserves the original helper's current-device behavior. Benchmark runners should pass the device that owns the measured tensors so another current CUDA device cannot leave the measurement unsynchronized.
measure
function View source
def measure(function: Callable[[], Any], *, warmup: int, runs: int, device: DeviceLike=None, include_samples: bool=False) -> dict[str, Any]: ...Measure synchronized wall latency in milliseconds.
device and include_samples are optional to preserve existing callers. Warmup calls are excluded from the returned statistics. When raw evidence is requested, samples_ms retains samples in execution order.
measure_paired
function View source
def measure_paired(first: Callable[[], Any], second: Callable[[], Any], *, warmup: int, runs: int, repetitions: int=1, device: DeviceLike=None, include_samples: bool=False) -> dict[str, Any]: ...Measure a paired A/B comparison with alternating execution order.
Each warmup and measured pair invokes both callables exactly once. The leading callable alternates for every pair and for every repetition, which avoids assigning all first-run or thermal effects to one side. Returned first and second summaries pool all repetitions. paired_ratio summarizes sample-wise first_ms / second_ms ratios, while the repetition records preserve the pairing structure. Raw samples are added only when include_samples is true.
reset_peak_memory
function View source
def reset_peak_memory(device: DeviceLike=None) -> CudaMemoryBaseline: ...Reset allocator peaks on one CUDA device and return its live baseline.
read_peak_memory
function View source
def read_peak_memory(baseline: CudaMemoryBaseline) -> dict[str, int]: ...Read device-targeted CUDA allocator peaks relative to baseline.