diff --git a/tinygrad/device.py b/tinygrad/device.py index 59a1acef64..b9a7245f13 100644 --- a/tinygrad/device.py +++ b/tinygrad/device.py @@ -411,7 +411,10 @@ class HCQSignal: value: The value to wait for. timeout: Maximum time to wait in milliseconds. Defaults to 10s. """ - raise NotImplementedError("wait() method must be implemented") + start_time = time.time() * 1000 + while time.time() * 1000 - start_time < timeout: + if self.value >= value: return + raise RuntimeError(f"Wait timeout: {timeout} ms! (the signal is not set to {value}, but {self.value})") @contextlib.contextmanager def hcq_profile(dev, enabled, desc, queue_type=None, queue=None): diff --git a/tinygrad/runtime/ops_nv.py b/tinygrad/runtime/ops_nv.py index ede855fd23..5026bb3d16 100644 --- a/tinygrad/runtime/ops_nv.py +++ b/tinygrad/runtime/ops_nv.py @@ -1,5 +1,5 @@ from __future__ import annotations -import os, ctypes, contextlib, re, fcntl, functools, mmap, struct, time, array, decimal +import os, ctypes, contextlib, re, fcntl, functools, mmap, struct, array, decimal from typing import Tuple, List, Any, cast, Union, Dict, Type from dataclasses import dataclass from tinygrad.device import HCQCompiled, HCQAllocator, HCQBuffer, HWCommandQueue, HWComputeQueue, HWCopyQueue, hcq_command, \ @@ -66,7 +66,6 @@ assert ctypes.sizeof(qmd_struct_t) == 0x40 * 4 def nvmethod(subc, mthd, size, typ=2): return (typ << 28) | (size << 16) | (subc << 13) | (mthd >> 2) - class NVSignal(HCQSignal): def __init__(self, value=0): self._signal = NVDevice.signals_pool.pop() @@ -76,11 +75,6 @@ class NVSignal(HCQSignal): def _get_value(self) -> int: return self._signal[0] def _get_timestamp(self) -> decimal.Decimal: return decimal.Decimal(self._signal[1]) / decimal.Decimal(1000) def _set_value(self, new_value:int): self._signal[0] = new_value - def wait(self, value:int, timeout:int=10000): - start_time = time.time() * 1000 - while time.time() * 1000 - start_time < timeout: - if self._signal[0] >= value: return - raise RuntimeError(f"wait_result: {timeout} ms TIMEOUT!") class NVCommandQueue(HWCommandQueue): # pylint: disable=abstract-method def __del__(self): diff --git a/tinygrad/runtime/ops_qcom.py b/tinygrad/runtime/ops_qcom.py index 81d07efc3d..624d522c79 100644 --- a/tinygrad/runtime/ops_qcom.py +++ b/tinygrad/runtime/ops_qcom.py @@ -1,5 +1,5 @@ from __future__ import annotations -import os, time, ctypes, functools, mmap, struct, array, decimal, math +import os, ctypes, functools, mmap, struct, array, decimal, math from types import SimpleNamespace from typing import Tuple, List, Dict, Any, cast from tinygrad.device import BufferOptions, HCQBuffer, HWComputeQueue, HCQProgram, HCQCompiled, HCQSignal, HCQAllocator, HCQArgsState, hcq_command @@ -36,11 +36,6 @@ class QCOMSignal(HCQSignal): def _get_value(self) -> int: return self._signal[0] def _get_timestamp(self) -> decimal.Decimal: return decimal.Decimal(self._signal[1]) / decimal.Decimal(19.2) # based on the 19.2MHz always-on timer def _set_value(self, new_value:int): self._signal[0] = new_value - def wait(self, value:int, timeout:int=60000): - start_time = time.time() * 1000 - while time.time() * 1000 - start_time < timeout: - if self._signal[0] >= value: return - raise RuntimeError(f"wait_result: {timeout} ms TIMEOUT!") class QCOMComputeQueue(HWComputeQueue): def __init__(self):