From 8a7be0a747e047bd09379cc8effa0d809ba81443 Mon Sep 17 00:00:00 2001 From: nimlgen <138685161+nimlgen@users.noreply.github.com> Date: Tue, 12 Aug 2025 16:16:34 +0300 Subject: [PATCH] metal: workaround for transfers sync issue (#11622) * metal: workaround for transfers sync issue * metal tracsfer sync is broken * hm * rm it? * keep it --- tinygrad/runtime/ops_metal.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tinygrad/runtime/ops_metal.py b/tinygrad/runtime/ops_metal.py index 027e5080ab..9e453eb729 100644 --- a/tinygrad/runtime/ops_metal.py +++ b/tinygrad/runtime/ops_metal.py @@ -221,6 +221,9 @@ class MetalAllocator(LRUAllocator[MetalDevice]): msg("setLabel:")(src_command_buffer, to_ns_str(f"COPY {src_dev.device} -> {dest_dev.device}")) msg("commit")(src_command_buffer) src_dev.mtl_buffers_in_flight.append(src_command_buffer) + # Transfers currently synchronize the completion. Otherwise, copies can sometimes lead to incorrect values. + # There is no real metal multidevice support for now, so transfer is used only for tests. + src_dev.synchronize() def _cp_mv(self, dst, src, prof_desc): with cpu_profile(prof_desc, self.dev.device, is_copy=True): dst[:] = src def _as_buffer(self, src:MetalBuffer) -> memoryview: