用途:在无物理 GPU 的 Linux 机器上运行 ONNX Runtime WebGPU 执行提供程序(EP)测试。仅限 Linux ORT WebGPU;macOS 使用 Metal 后端和真实 GPU,本技能是 Mac 之外的本地开发循环方案。
原理:Linux 上 ORT WebGPU EP 运行于 Dawn 的 Vulkan 后端,Vulkan 不要求硬件 GPU,Mesa lavapipe 是软件(CPU)Vulkan 适配器,Dawn 会像普通设备一样枚举它。适合 EP 正确性测试:许多主机侧校验路径(形状/广播检查、ORT_ENFORCE)在任何着色器派发前触发,可在软件适配器上观察到失败;会派发的逐元素与广播内核在 lavapipe 上也能正确(但较慢)运行,可与 CPU 参考结果比对数值。代价是速度,不适用于性能敏感或驱动特定路径。
覆盖范围:软件 Vulkan 覆盖主机侧失败(派发前的形状/广播 ORT_ENFORCE)和不含 MatMul 的派发内核;不覆盖任何含 MatMul 的图——MatMul 系列会使 lavapipe 的 LLVM JIT 崩溃,包括展开的 Attention 节点测试(test_attention_4d_softcap_neginf_mask_expanded),这些只能在 macOS-arm64 Metal 上运行,是唯一可信来源。切勿因 lavapipe 通过就认为 Attention/MatMul 修复已在 Mac 之外验证。
安装(Azure Linux 用 dnf,不用 apt): dnf install -y mesa-vulkan-drivers vulkan-loader 可选校验适配器: dnf install -y vulkan-tools && vulkaninfo | head lavapipe ICD 清单位于 /usr/share/vulkan/icd.d/lvp_icd.<arch>.json(x86_64 为 lvp_icd.x86_64.json,arm64 为 lvp_icd.aarch64.json)。
构建: ./build.sh --config Release --parallel --use_webgpu
运行测试:WebGPU 算子/内核测试构建进 onnxruntime_provider_test 目标(不是 onnxruntime_test_all)。将 Vulkan 加载器指向 lavapipe ICD 并用 --gtest_filter 选择子集: cd build/Linux/Release VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json ./onnxruntime_provider_test --gtest_filter="WebGPU" VK_ICD_FILENAMES 强制只加载 lavapipe,使运行结果确定。
已知问题:MathOpTest.MatMulFloatType 等 MatMul 系列测试会使 lavapipe 崩溃,报错 LLVM ERROR: Instruction Combining did not reach a fixpoint after 1 iterations。这是软件 Vulkan(Mesa lavapipe 的 LLVM JIT)的既有局限,不是 ORT 缺陷。广泛运行时排除 MatMul 系列: VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json ./onnxruntime_provider_test --gtest_filter="WebGPU:-MatMul"
背景:Linux webgpu CI 分支(.github/workflows/linux_webgpu.yml)只构建、不运行 WebGPU 内核,因此其通过不代表任何 WebGPU 测试实际执行;macOS-arm64 webgpu 分支是唯一运行 WebGPU 后端节点测试的 CI 分支。本地 lavapipe 运行是推送前在 Mac 之外实际执行 WebGPU 内核的实用方式,但须遵守上述范围限制。