MCPcopy Create free account
hub / github.com/LMCache/LMCache / device_sync

Function device_sync

tests/v1/test_python_ops_fallback.py:26–45  ·  view source on GitHub ↗

Synchronize device operations. Args: device: Device string ("cuda", "xpu", or "cpu") This function synchronizes operations for GPU devices: - For CUDA devices, calls torch.cuda.synchronize() - For XPU devices, calls torch.xpu.synchronize() - For CPU, no synchronization

(device: str)

Source from the content-addressed store, hash-verified

24
25# Device utility functions
26def device_sync(device: str) -> None:
27 """Synchronize device operations.
28
29 Args:
30 device: Device string ("cuda", "xpu", or "cpu")
31
32 This function synchronizes operations for GPU devices:
33 - For CUDA devices, calls torch.cuda.synchronize()
34 - For XPU devices, calls torch.xpu.synchronize()
35 - For CPU, no synchronization is needed (returns immediately)
36 """
37 if device == "cuda":
38 torch.cuda.synchronize()
39 elif device == "xpu":
40 if hasattr(torch, "xpu") and torch.xpu.is_available():
41 torch.xpu.synchronize()
42 else:
43 # TODO: add more device here
44 pass
45 # CPU requires no synchronization
46
47
48# ==========================================

Calls 2

synchronizeMethod · 0.45
is_availableMethod · 0.45

Tested by

no test coverage detected