[Perf][MRV2] Avoid stream syncs in NonUvaBuffer host-to-device copies (#60215)
Signed-off-by: cheesecake <farzanaman99@gmail.com> Co-authored-by: William Joyner <133391209+joynerwk03@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
William Joyner
Claude Opus 5.5
parent
283d76d56a
commit
956960f85f
@@ -234,6 +234,25 @@ def test_non_pinned_cpu_tensor(device):
|
||||
assert gpu_view[9, 9] == 198
|
||||
|
||||
|
||||
@pytest.mark.skipif(not current_platform.is_cuda(), reason="CUDA-only sync check.")
|
||||
def test_non_uva_buffer_copies_without_stream_sync():
|
||||
buffer = buffer_utils.NonUvaBuffer(8, torch.int32)
|
||||
buffer.np[:] = np.arange(8)
|
||||
|
||||
torch.cuda.set_sync_debug_mode("error")
|
||||
try:
|
||||
prefix = buffer.uva(4)
|
||||
full = buffer.uva()
|
||||
finally:
|
||||
torch.cuda.set_sync_debug_mode(0)
|
||||
# The next step overwrites the host buffer right after the copy is issued.
|
||||
buffer.np[:] = -1
|
||||
torch.accelerator.synchronize()
|
||||
|
||||
assert prefix.tolist() == list(range(4))
|
||||
assert full.tolist() == list(range(8))
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_uva_available(), reason="UVA is not available.")
|
||||
@pytest.mark.skipif(
|
||||
not current_platform.is_xpu(), reason="XPU non-contiguous UVA test."
|
||||
|
||||
@@ -54,8 +54,8 @@ class NonUvaBuffer:
|
||||
|
||||
def uva(self, n: int | None = None) -> torch.Tensor:
|
||||
if n is None:
|
||||
return self._uva.copy_(self.cpu)
|
||||
return self._uva[:n].copy_(self.cpu[:n])
|
||||
return self._uva.copy_(self.cpu, non_blocking=True)
|
||||
return self._uva[:n].copy_(self.cpu[:n], non_blocking=True)
|
||||
|
||||
|
||||
class UvaBufferPool:
|
||||
|
||||
Reference in New Issue
Block a user