# cont 6-A: clock-event reasons during the slow window after context start: light (duty-cycled) load 5 s, then sustained 3 s.
import time, torch, pynvml
pynvml.nvmlInit(); h = pynvml.nvmlDeviceGetHandleByIndex(0)
R = getattr(pynvml, "nvmlDeviceGetCurrentClocksEventReasons", None) or pynvml.nvmlDeviceGetCurrentClocksThrottleReasons
def rd(): return (pynvml.nvmlDeviceGetPerformanceState(h), pynvml.nvmlDeviceGetClockInfo(h, 1), pynvml.nvmlDeviceGetClockInfo(h, 2), hex(R(h)))
print("name", pynvml.nvmlDeviceGetName(h), "app sm", pynvml.nvmlDeviceGetApplicationsClock(h,1), "default app", pynvml.nvmlDeviceGetDefaultApplicationsClock(h,1), "max", pynvml.nvmlDeviceGetMaxClockInfo(h,1), flush=True)
buf = torch.empty(16 << 20, dtype=torch.float32, device="cuda:0"); torch.cuda.synchronize()
t0 = time.monotonic(); prev = None
def log(tag):
    global prev
    r = rd()
    if r != prev: print(f"{time.monotonic()-t0:6.2f}s {tag} P{r[0]} sm {r[1]} mem {r[2]} reasons {r[3]}", flush=True); prev = r
while time.monotonic() - t0 < 5:
    buf.add_(1.0); torch.cuda.synchronize(); time.sleep(0.02); log("light")
t1 = time.monotonic()
while time.monotonic() - t1 < 3:
    for _ in range(8): buf.add_(1.0)
    torch.cuda.synchronize(); log("sustained")
