From 4d09ea4c0607e6f916224e3903da361800aee593 Mon Sep 17 00:00:00 2001 From: nimlgen <138685161+nimlgen@users.noreply.github.com> Date: Tue, 11 Mar 2025 10:02:07 +0000 Subject: [PATCH] hcq: reset timer on progress in singal.wait --- tinygrad/runtime/support/hcq.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tinygrad/runtime/support/hcq.py b/tinygrad/runtime/support/hcq.py index 9b2134e3d6..f4f2a1c5d0 100644 --- a/tinygrad/runtime/support/hcq.py +++ b/tinygrad/runtime/support/hcq.py @@ -246,11 +246,12 @@ class HCQSignal(Generic[DeviceType]): Args: value: The value to wait for. - timeout: Maximum time to wait in milliseconds. Defaults to 10s. + timeout: Maximum time to wait in milliseconds. Defaults to 30s. """ start_time = int(time.perf_counter() * 1000) - while self.value < value and (time_spent:=int(time.perf_counter() * 1000) - start_time) < timeout: + while (prev_value:=self.value) < value and (time_spent:=int(time.perf_counter() * 1000) - start_time) < timeout: self._sleep(time_spent) + if self.value != prev_value: start_time = int(time.perf_counter() * 1000) # progress was made, reset timer if self.value < value: raise RuntimeError(f"Wait timeout: {timeout} ms! (the signal is not set to {value}, but {self.value})") @contextlib.contextmanager