noether.core.utils.common.stopwatch¶
Classes¶
A stopwatch class to measure elapsed time. |
Module Contents¶
- class noether.core.utils.common.stopwatch.Stopwatch(device=None)¶
A stopwatch class to measure elapsed time.
Supports two timing backends depending on the provided device:
CPU (
device=None): plaintime.perf_counter()wall-clock timing.GPU (CUDA or MPS
device): device event-based timing usingtorch.cuda.Event/torch.mps.Eventfor accurate GPU measurements. Events are recorded non-blocking instop()/lap()and resolved lazily inelapsed_seconds, which synchronizes each pending event pair individually before callingelapsed_time().
- Parameters:
device (torch.device | None) – Optional device that selects the timing backend.
- stop()¶
Stop the stopwatch and return the elapsed time since the last lap.
For GPU devices the return value is always
float("nan"); accesselapsed_secondsafter stopping to obtain the resolved time.- Return type:
- lap()¶
Record a lap time and return the elapsed time since the last lap.
For GPU devices the return value is always
float("nan"); accesselapsed_secondsafter stopping to obtain the resolved time.- Return type:
- static sync(device)¶
Synchronize the given GPU device. No-op for CPU devices.
- Parameters:
device (torch.device)
- Return type:
None