[MRV2] Buffer util simplifications (#56888)

Signed-off-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
Nick Hill
2026-09-15 20:36:51 +00:00
committed by GitHub
parent b6ce714354
commit f2aad6aa70
21 changed files with 125 additions and 112 deletions
+4 -3
View File
@@ -137,9 +137,10 @@ class CpuGpuBuffer:
self.np = self.cpu.numpy()
def copy_to_gpu(self, n: int | None = None) -> torch.Tensor:
if n is None:
return self.gpu.copy_(self.cpu, non_blocking=True)
return self.gpu[:n].copy_(self.cpu[:n], non_blocking=True)
cpu, gpu = self.cpu, self.gpu
if n is not None:
cpu, gpu = cpu[:n], gpu[:n]
return gpu.copy_(cpu.pin_memory() if PIN_MEMORY else cpu, non_blocking=True)
def copy_to_cpu(self, n: int | None = None) -> torch.Tensor:
"""NOTE: Because this method is non-blocking, explicit synchronization