Skip to content

基于 DirectLaunch 的 HIP/CUDA 双平台 vLLM 调度#26

Open
tonghaoxin wants to merge 63 commits into
XpuOS:mainfrom
tonghaoxin:fix/vllm-xsched
Open

基于 DirectLaunch 的 HIP/CUDA 双平台 vLLM 调度#26
tonghaoxin wants to merge 63 commits into
XpuOS:mainfrom
tonghaoxin:fix/vllm-xsched

Conversation

@tonghaoxin

Copy link
Copy Markdown

概述

原版 XSched 对默认流(stream=nullptr)直接 bypass,不建 XQueue、不参与调度。vLLM 等现代推理引擎主要使用默认流发射 kernel,导致 GPU
活动对调度器完全不可见。本次提交解决了 HIP(海光 DCU)和 CUDA(NVIDIA)两个平台上的 vLLM 调度问题。

核心思路

应用调 kernel API
→ shim 拦截
→ XQueue 查/建(仅追踪,不执行)
→ Ready 心跳 → 调度器感知活动
→ suspend 门控 → 挂起时 sleep 等待 Resume
→ DirectLaunch → 直调真 GPU 驱动 API

kernel 不再经过 XQueue 的 CommandBuffer/LaunchWorker 执行管线,调度控制通过主线程上的门控实现。

修改内容

HIP 平台

  • HIP_SHIM_FUNC 改为 DirectLaunch,避免 PyTorch 初始化期建大量 LaunchWorker(修复推理乱码)
  • XLaunchKernel 等 kernel 发射函数:加 GetOrCreateXQueue 延迟建 XQueue + IsSuspended() 轮询门控 + 定期 SchedAgent::SendEvent 发 Ready 心跳
  • 事件函数(XEventRecord/XStreamWaitEvent)全部 DirectLaunch,修复跨流同步时序

CUDA 平台

  • intercept.cpp 导出 Runtime API:cudaSetDevice/cudaMalloc 含 ForceRegister 预热 context;cudaLaunchKernel 劫持,修正 dim3 struct ABI(根治乱码)
  • XLaunchKernel:suspend 门控 + Ready 心跳(只查不建,XQueue 由 cudaLaunchKernel 导出创建)
  • cuda_init_done 标志:首笔 kernel 发射前为 init 期允许建 XQueue,之后推理期禁建(修复 VLM/reranker 模型的非法内存访问错误)
  • CudaQueueLv1:默认流支持 + OnXQueueCreate 改为空操作
  • CUDA_SHIM_FUNC:DirectLaunch

基础设施

  • XQueue::IsSuspended() 纯虚接口 + AsyncXQueue 实现
  • platforms/CMakeLists.txt:追加 sched/include 路径

解决的问题

  • vLLM 推理对 XSched 调度器不可见
  • CUDA Runtime API 经 libcudart.so RTLD_NEXT 绕过 LD_PRELOAD 劫持
  • VLM/reranker 模型动态建流时 LaunchWorker 干扰 CUDA context 导致非法内存访问

本次修改关联issue “How to integrate/run vLLM with XSched? (Missing example/docs)#22

tonghaoxin and others added 30 commits June 2, 2026 14:20
包括 CUDA/HIP 平台的 shim 拦截层、XQueue 虚拟队列、
XScheduler 调度器、多级抢占 HAL 等核心组件。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
将 cudaStreamCreate/hipStreamCreate 拦截后改调
cuStreamCreateWithPriority/hipStreamCreateWithPriority,
优先级从 XSCHED_AUTO_XQUEUE_PRIORITY 环境变量读取。

这样 Runtime API 创建的 stream 也能获得 GPU 硬件优先级,
支持 XSched 的多优先级调度,无需 ShadowSubmit/VipPulse
等事后补救机制。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tonghaoxin tonghaoxin changed the title 基于 DirectLaunch 的 HIP/CUDA 双平台 vLLM 调度适配 基于 DirectLaunch 的 HIP/CUDA 双平台 vLLM 调度 Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant