From 70dad9d6425d190771bf7a057bd6f8072f286d83 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:57:40 +0800 Subject: [PATCH] add PING to RemoteCmd (#15371) * add PING to RemoteCmd * cleanup --- extra/remote/bench.py | 12 +++++++----- extra/remote/serve.py | 3 +++ tinygrad/runtime/support/system.py | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/extra/remote/bench.py b/extra/remote/bench.py index 8ab2052280..e747ba9d9f 100644 --- a/extra/remote/bench.py +++ b/extra/remote/bench.py @@ -16,12 +16,14 @@ if __name__ == "__main__": pci = RemotePCIDevice("BN", devs[0]) print(f"connected to {os.environ['REMOTE']}, device: {devs[0]}\n") - # latency - for _ in range(10): pci.read_config(0, 4) + # ping (minimal server round-trip, no device I/O) + from tinygrad.runtime.support.system import RemoteCmd + sock = pci.sock + for _ in range(10): RemotePCIDevice._rpc(sock, 0, RemoteCmd.PING) st = time.perf_counter() - for _ in range(LAT_N_RUNS): pci.read_config(0, 4) - lat = (time.perf_counter() - st) / LAT_N_RUNS - print(f"RPC latency: {lat*1e6:.1f} us ({1/lat:,.0f} ops/sec)\n") + for _ in range(LAT_N_RUNS): RemotePCIDevice._rpc(sock, 0, RemoteCmd.PING) + ping_lat = (time.perf_counter() - st) / LAT_N_RUNS + print(f"PING latency: {ping_lat*1e6:.1f} us ({1/ping_lat:,.0f} ops/sec)\n") # throughput sysmem, _ = pci.alloc_sysmem(max(SIZES)) diff --git a/extra/remote/serve.py b/extra/remote/serve.py index 736f3ba994..aa1af984a0 100644 --- a/extra/remote/serve.py +++ b/extra/remote/serve.py @@ -12,6 +12,9 @@ mapped_bars: dict[tuple[int, int], object] = {} sysmem_allocs: list[tuple] = [] def handle(conn, cmd, dev_id, bar, arg0, arg1, arg2): + if cmd == RemoteCmd.PING: + return conn.sendall(resp()) + if cmd == RemoteCmd.PROBE: payload = conn.recv(arg1, socket.MSG_WAITALL) if arg1 > 0 else b"" filter_devices: dict[int, list[int]] = {} diff --git a/tinygrad/runtime/support/system.py b/tinygrad/runtime/support/system.py index 7394bfc3ea..9352695e20 100644 --- a/tinygrad/runtime/support/system.py +++ b/tinygrad/runtime/support/system.py @@ -284,7 +284,7 @@ class PCIIfaceBase: # *** Remote PCI Devices class RemoteCmd(enum.IntEnum): - PROBE, MAP_BAR, MAP_SYSMEM_FD, CFG_READ, CFG_WRITE, RESET, MMIO_READ, MMIO_WRITE, MAP_SYSMEM, SYSMEM_READ, SYSMEM_WRITE, RESIZE_BAR = range(12) + PROBE,MAP_BAR,MAP_SYSMEM_FD,CFG_READ,CFG_WRITE,RESET,MMIO_READ,MMIO_WRITE,MAP_SYSMEM,SYSMEM_READ,SYSMEM_WRITE,RESIZE_BAR,PING = range(13) class RemoteMMIOInterface(MMIOInterface): def __init__(self, dev:RemotePCIDevice, residx:int, nbytes:int, fmt='B', off=0, rd_cmd=RemoteCmd.MMIO_READ, wr_cmd=RemoteCmd.MMIO_WRITE):