carrot/tinygrad_repo/extra/ring_copy.py
Vehicle Researcher 8eb8330d95 openpilot v0.9.9 release
date: 2025-03-08T09:09:29
master commit: ce355250be726f9bc8f0ac165a6cde41586a983d
2025-03-08 09:09:31 +00:00

15 lines
472 B
Python

from tinygrad import Tensor, Device, GlobalCounters
from tinygrad.helpers import Timing
N = 512
GPUS = 5
ds = tuple([f"{Device.DEFAULT}:{i+1}" for i in range(GPUS)])
t = [Tensor.ones(N, N, N, device=d).contiguous().realize() for d in ds]
for _ in range(10):
GlobalCounters.reset()
with Timing():
for ti in t:
ti.to_(ds[(ds.index(ti.device)+1+len(ds))%len(ds)])
# ti.to_(ds[(ds.index(ti.device)-1+len(ds))%len(ds)]) # reversed order
ti.realize()