[Feature] Triton kernel dispatcher (#43048)

Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com>
This commit is contained in:
wangxiyuan
2026-09-25 04:07:43 +00:00
committed by GitHub
parent b05f7d5fbc
commit 44257c2e35
8 changed files with 482 additions and 98 deletions
-36
View File
@@ -4,19 +4,10 @@
"""Contains replacement functions to fallback Triton usages in CPU backend."""
import ctypes
from collections.abc import Callable
import torch
class _FuncWrapper:
def __init__(self, func: Callable) -> None:
self.func = func
def __getitem__(self, *args, **kwargs) -> Callable:
return self.func
# For _compute_slot_mapping_kernel in vllm/v1/worker/block_table.py
def _compute_slot_mapping_kernel_impl(
num_tokens: int,
@@ -47,9 +38,6 @@ def _compute_slot_mapping_kernel_impl(
)
compute_slot_mapping_kernel = _FuncWrapper(_compute_slot_mapping_kernel_impl)
def _ensure_int64(t: torch.Tensor) -> torch.Tensor:
return t if t.dtype == torch.int64 else t.to(torch.int64)
@@ -454,31 +442,7 @@ def _sample_recovered_tokens_kernel_impl(
output_token_ids.copy_(output_i64.to(orig_dtype))
eagle_prepare_inputs_padded_kernel = _FuncWrapper(
_eagle_prepare_inputs_padded_kernel_impl
)
eagle_prepare_next_token_padded_kernel = _FuncWrapper(
_eagle_prepare_next_token_padded_kernel_impl
)
copy_and_expand_eagle_inputs_kernel = _FuncWrapper(
_copy_and_expand_eagle_inputs_kernel_impl
)
copy_and_expand_dflash_inputs_kernel = _FuncWrapper(
_copy_and_expand_dflash_inputs_kernel_impl
)
eagle_step_slot_mapping_metadata_kernel = _FuncWrapper(
_eagle_step_slot_mapping_metadata_kernel_impl
)
rejection_greedy_sample_kernel = _FuncWrapper(_rejection_greedy_sample_kernel_impl)
rejection_random_sample_kernel = _FuncWrapper(_rejection_random_sample_kernel_impl)
expand_kernel = _FuncWrapper(_expand_kernel_impl)
sample_recovered_tokens_kernel = _FuncWrapper(_sample_recovered_tokens_kernel_impl)
def _batch_memcpy_impl(src_ptrs, dst_ptrs, sizes, BLOCK_SIZE=None):
# BLOCK_SIZE is unused; kept for signature parity with the Triton kernel.
for src, dst, size in zip(src_ptrs.tolist(), dst_ptrs.tolist(), sizes.tolist()):
ctypes.memmove(dst, src, size)
batch_memcpy_kernel = _FuncWrapper(_batch_memcpy_impl)