[XPU] Enable XPU eplb (#44987)

Signed-off-by: mayuyuace <qiming1.zhang@intel.com>
Signed-off-by: Qiming Zhang <qiming1.zhang@intel.com>
This commit is contained in:
Qiming Zhang
2026-09-17 13:19:13 +08:00
committed by GitHub
parent 2743dc4f92
commit e6b1a5e5e3
16 changed files with 267 additions and 109 deletions
+21 -4
View File
@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Utility functions for EPLB (Expert Parallel Load Balancing)."""
import contextlib
import os
import threading
@@ -13,6 +14,22 @@ from vllm.logger import init_logger
logger = init_logger(__name__)
@contextlib.contextmanager
def device_stream(stream: torch.Stream | None):
"""Platform-agnostic context manager that activates *stream* as the
current accelerator stream for the duration of the ``with`` block.
A no-op when *stream* is ``None``."""
if stream is None:
yield
return
prev = torch.accelerator.current_stream()
torch.accelerator.set_stream(stream)
try:
yield
finally:
torch.accelerator.set_stream(prev)
class CpuGpuEvent:
"""Combines a CUDA event with a CPU threading event to enforce record->wait
ordering across two threads.
@@ -30,10 +47,10 @@ class CpuGpuEvent:
"""
def __init__(self):
self._event = torch.cuda.Event()
self._event = torch.Event()
self._recorded = threading.Event()
def wait(self, stream: torch.cuda.Stream | None = None):
def wait(self, stream: torch.Stream | None = None):
"""Blocks the calling thread until record finishes. Used to guarantee that the
record kernel is called before wait.
@@ -43,7 +60,7 @@ class CpuGpuEvent:
self._event.wait(stream)
self._recorded.clear()
def record(self, stream: torch.cuda.Stream | None = None):
def record(self, stream: torch.Stream | None = None):
"""Unblocks the waiting thread after calling event.record().
Should only be called by the main thread.
@@ -53,7 +70,7 @@ class CpuGpuEvent:
"CpuGpuEvent.record() called before the previous event was "
"consumed by wait()"
)
self._event = torch.cuda.Event()
self._event = torch.Event()
self._event.record(stream)
self._recorded.set()