[Perf] Ensure async h2d copies are pinned in more places (#55202)
This commit is contained in:
@@ -21,6 +21,7 @@ import vllm.envs as envs
|
||||
from vllm.logger import init_logger
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.utils.torch_utils import PIN_MEMORY
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -181,6 +182,31 @@ def _lazy_import_wrapper(
|
||||
return wrapper
|
||||
|
||||
|
||||
def pin_host_range_buf(length: int) -> None:
|
||||
"""Pin flashinfer's cached host-side arange buffer covering `length`.
|
||||
|
||||
flashinfer's decode plan() builds its host qo_indptr from the cached
|
||||
`_get_range_buf` entry and copies it to the GPU with non_blocking=True on
|
||||
every call; the cache entry is unpinned, so the copy silently blocks the
|
||||
host. Replace the entry with a pinned copy so the copies stay async.
|
||||
"""
|
||||
if not PIN_MEMORY:
|
||||
return
|
||||
mod = _get_submodule("flashinfer.utils")
|
||||
if mod is None:
|
||||
return
|
||||
get_range_buf = getattr(mod, "_get_range_buf", None)
|
||||
cache_buf = getattr(mod, "_cache_buf", None)
|
||||
ceil_pow2 = getattr(mod, "_ceil_pow2", None)
|
||||
if get_range_buf is None or cache_buf is None or ceil_pow2 is None:
|
||||
return
|
||||
get_range_buf(length, "cpu") # Ensure the cache entry exists.
|
||||
key = (f"range_{ceil_pow2(length)}", "cpu")
|
||||
buf = cache_buf[key]
|
||||
if not buf.is_pinned():
|
||||
cache_buf[key] = buf.pin_memory()
|
||||
|
||||
|
||||
# Create lazy wrappers for each function
|
||||
flashinfer_trtllm_bf16_moe = _lazy_import_wrapper(
|
||||
"flashinfer.fused_moe", "trtllm_bf16_moe"
|
||||
|
||||
Reference in New Issue
Block a user