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)
| 24 | |
| 25 | # Device utility functions |
| 26 | def 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 | # ========================================== |
no test coverage detected