Skip to content

test(gpu-wgpu): wgpu (WebGPU) compute carpet - Python / C / C++ / Rust bindings#1576

Open
Lfan-ke wants to merge 1 commit into
rcore-os:devfrom
Lfan-ke:apps-starry-gpu-wgpu
Open

test(gpu-wgpu): wgpu (WebGPU) compute carpet - Python / C / C++ / Rust bindings#1576
Lfan-ke wants to merge 1 commit into
rcore-os:devfrom
Lfan-ke:apps-starry-gpu-wgpu

Conversation

@Lfan-ke

@Lfan-ke Lfan-ke commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

概述

在 StarryOS 上以 wgpu(WebGPU 的 Rust 实现 wgpu-core / wgpu-native)跑真实 WebGPU COMPUTE,覆盖它的四种语言绑定

  • Pythonwgpu-py(34 断言)
  • C — wgpu-native C API webgpu.h / wgpu.h(33 断言)
  • C++ — wgpu-native 经 C++17(38 断言)
  • Rustwgpu crate(36 断言)

四者都走 wgpu 的 Vulkan 后端,落到 lavapipe(Mesa 软件 Vulkan 驱动,LLVM 20 llvmpipe CPU JIT)—— 真实的 WebGPU COMPUTE 设备,全在 CPU 上,无需 GPU。每个算子是一段真实 WGSL compute shader(wgpu-native 的 naga 运行期编译),经完整 WebGPU 管线(bind group + compute pipeline + dispatch + 缓冲回读)执行,对各语言里的参照做精确 / 闭式 / 容差断言(非 import-only)。覆盖 elementwise / 超越 / 融合 axpy+relu / reduce(shared-mem 树形) / prefix-sum / matmul(2D) / transpose / 1-D 卷积 / gather / compare+select / iota-parity / workgroup 归约等。

交付模型

prebuild.sh 从 conda-forge 装 wgpu-py + wgpu-native + Mesa lavapipe + vulkan-loader 到 /opt/miniconda,随附 Debian libc6 glibc 闭包。Python 绑定目标端由 conda python 直接跑;C / C++ / Rust 绑定由 prebuild 在宿主用原生(x86_64)/ 交叉(aarch64)工具链编成目标架构原生二进制。关键处理:

  • mesalib 钉 25.0.5(LLVM 20):mesalib 26 的 LLVM 22.1 llvmpipe miscompile compute shader(segfault / SSBO 读回垃圾),LLVM 20 正确执行。
  • lavapipe ICD 路径:prebuild 重写到 on-target /opt/miniconda/lib/libvulkan_lvp.so
  • Rust 绑定构建:从 TMPDIR 下的 scratch 拷贝 + 全新 CARGO_HOME 构建,只用默认 crates.io sparse 索引 —— 不受构建宿主全局 cargo 镜像(source-replacement)配置影响,且在干净宿主上可复现。

门控

  • x86_64 真绿 1/1:四绑定全过(wgpu-python 34 / wgpu-c 33 / wgpu-cpp 38 / wgpu-rust 36),GPU_OK=4/4 + TEST PASSED,设备均为 llvmpipe (LLVM 20.1.8)
  • riscv64 / loongarch64 无 conda wgpu 分发(上游缺架构),run_wgpu.py 打印诚实说明并 TEST PASSED(不伪造能力)。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审总结

本 PR 在 StarryOS 上新增了 apps/starry/gpu-wgpu 应用,通过 wgpu(WebGPU 的 Rust 实现)在 lavapipe(Mesa 软件 Vulkan 驱动)上运行计算算子地毯式测试,覆盖 Python / C / C++ / Rust 四种语言绑定。整体代码结构清晰,文档详尽,四个 QEMU 架构配置合理(riscv64 / loongarch64 无 conda 分发时诚实跳过)。

阻塞问题

1. cargo fmt 检查未通过

apps/starry/gpu-wgpu/rssrc/wgpu-carpet/ 下的独立 Rust crate 未通过 cargo fmt --check,存在多处格式问题(如 use 语句间缺少空行分隔、长行未换行等)。请在该目录下运行 cargo fmt 修复所有格式差异。

需关注的问题

2. CI 路径过滤器未覆盖新 app

.github/workflows/ci.yml 中的 ci_checks 路径过滤器目前仅包含 apps/starry/aka00-tennis-yolo/**,未包含新增的 apps/starry/gpu-wgpu/**。当前 CI 运行中仅有 "Detect changed paths" 和 "Cancel stale CI runs" 通过,所有实际构建/测试 job 均被跳过。建议在 ci_checks 过滤器中添加 apps/starry/gpu-wgpu/** 路径,以确保后续变更能触发 CI 验证。

关联 PR

  • PR #1578(同一作者,apps-starry-gpu-webgpu):通过 Deno 内置 WebGPU 在 lavapipe 上运行 compute carpet,与本 PR 互补(不同语言绑定:Deno/TypeScript vs Python/C/C++/Rust),无冲突。两 PR 共用的 lavapipe/prebuild 基础设施在逻辑上一致。

非阻塞观察

  • 代码质量良好:C/C++ 代码正确管理资源(RAII / 显式 release),Rust 代码类型安全,Python 脚本错误处理合理。
  • run_wgpu.py 的失败检测逻辑正确:仅在所有已就绪绑定 fail=0 时才输出 TEST PASSED,riscv64/loongarch64 上诚实报告无 conda 分发。
  • QEMU 配置中 success_regex / fail_regex 设置正确,能可靠检测测试结果。
  • app 放置在 apps/starry/gpu-wgpu/ 符合项目 apps/starry/README.md 规范。

验证结果

  • cargo fmt --checkrssrc/wgpu-carpet/): 失败
  • cargo fmt --check(workspace): 通过
  • ⚠️ CI: 所有构建/测试 job 被跳过(路径过滤器未覆盖),需本地验证
  • ❌ 本地 QEMU 验证:环境中缺少 conda/llvmpipe 依赖,无法运行完整 app 测试

请先修复 cargo fmt 问题后重新提交。

Powered by deepseek-v4-pro

// Each operator runs one storage-buffer compute shader and is checked
// against a Rust host reference with tight tolerance.

use std::borrow::Cow;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt 要求在 use std::borrow::Cow;use wgpu::util::DeviceExt; 之间增加空行以区分不同来源的导入组。请在当前目录运行 cargo fmt 修复。

impl Ctx {
fn new() -> Self {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::VULKAN,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt 要求此处的 request_adapter 调用参数缩进调整。请运行 cargo fmt 修复。

fn main() {
let ctx = Ctx::new();
let mut rep = Report::new();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此长 .map() 链式调用需要换行以符合 rustfmt 格式。请运行 cargo fmt 修复。

@mai-team-app
mai-team-app Bot requested a review from ZCShou July 11, 2026 09:31
@Lfan-ke
Lfan-ke force-pushed the apps-starry-gpu-wgpu branch from e3b76b8 to 1901cb3 Compare July 11, 2026 12:26
@Lfan-ke

Lfan-ke commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Closing to re-deliver as a single comprehensive, industrial-grade GPU/compute suite: full API/interface coverage across every backend, plus model-inference correctness (not smoke) and parallel-compute test cases. This operator-level carpet is superseded by that forthcoming work.

…indings

Full API ground-truth carpet for wgpu compute:
- wgpu_rust: 60 assertions, Rust wgpu crate (ash Vulkan backend), on-target 4arch
  via musl cross-build (dynamic musl PIE, dlopen libvulkan.so.1 -> musl lavapipe)
- wgpu_c: 58 assertions (host-reference; no musl libwgpu-native prebuilt for rv/la)
- wgpu_cpp: 58 assertions (host-reference)
- wgpu_py: 95 assertions (host-reference; wgpu-py conda only x86/aa glibc)
Total: 271 gated, 4-cell full API coverage (not import-only)

On-target gate: Rust cell cross-compiled to x86_64/aarch64/riscv64/loongarch64-unknown-
linux-musl with -C target-feature=-crt-static (dynamic musl, enables dlopen libvulkan);
runs through musl Mesa vulkan-swrast lavapipe stack staged from Alpine packages (same
as rcore-os#1575). C/C++/py cells run host-reference (glibc conda binaries, no musl prebuilt).

Resolves CHANGES_REQUESTED:
- cargo fmt (import grouping, indentation, method chain line breaks)
- CI path filter added for apps/starry/gpu-wgpu/**

Signed-off-by: 林晨 <lc@lbos.cn>
Signed-off-by: 林晨 <chengkelfan@qq.com>
@Lfan-ke
Lfan-ke force-pushed the apps-starry-gpu-wgpu branch from f3dade5 to 56d9371 Compare July 19, 2026 01:50

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审结论

本 PR 新增 apps/starry/gpu-wgpu,通过 Rust wgpu/Vulkan/lavapipe 在 StarryOS 四种架构上执行计算 carpet,并加入 rootfs 预置脚本、QEMU 配置和 CI 路径过滤。整体实现方向与现有 Starry app 预构建模式一致;.github/workflows/ci.yml 的新路径过滤已覆盖该 app,既有 review 中关于 fmt 的问题在当前 head 也已修复。

阻塞问题

  1. clippy -D warnings 未通过(正确性/可维护性,阻塞):在当前 head 对独立 crate 运行 cargo clippy --manifest-path apps/starry/gpu-wgpu/rssrc/wgpu-carpet/Cargo.toml --all-targets -- -D warnings,失败于 src/main.rs:472assign_op_pattern,以及 src/main.rs:1022src/main.rs:1108manual_div_ceil。这些是新增 Rust 目标的 CI/代码质量门禁错误,应分别改为 corrupt[0] -= 1.0N_BIG.div_ceil(64)/N_TAIL.div_ceil(64)(或提供确有必要且有解释的等价实现),不能用 allow 绕过。

  2. PR 意图已被作者明确标记为 superseded(项目流程/重复工作,阻塞):PR issue comment #4945855541 说明该 operator-level carpet 将关闭并由同作者后续的 comprehensive GPU/compute suite 取代;当前 PR body 也仍将该工作定位为可合并的完整 suite。请先同步实际意图:若该 PR 确实已由后续工作取代,应关闭/不再合并此 PR;若要继续合并,请更新说明并证明与后续 PR 的明确差异,避免把已声明 superseded 的实现并入 base。

验证与上下文

  • prepare-review:通过;workspace HEAD 为 56d93711a56d10dd02f1c75c17d5377908d61013
  • cargo fmt --manifest-path apps/starry/gpu-wgpu/rssrc/wgpu-carpet/Cargo.toml -- --check:通过。
  • git diff --check origin/dev...HEAD:通过。
  • 远端 check-runs:当前 head 共 59 个,29 success、29 skipped、1 cancelled;实际相关工作流(包括 formatting、Starry x86_64 QEMU 以及其他矩阵 job)已有 success,skipped 属于矩阵/条件路径行为,未将 CI 结果本身作为阻塞依据。
  • 由于上述 clippy 门禁失败,未批准;QEMU 应用运行也不应被仅有宿主格式检查替代。当前环境没有必要为已经通过的远端 CI 重复完整矩阵运行。
  • 既有 review 的 fmt 和 CI 路径问题已检查:fmt 已解决,CI filter 已加入 apps/starry/gpu-wgpu/**。既有 inline 讨论仍对应旧 commit,当前 head 已不再是该位置的格式问题。
  • 已检查 base 中的 apps/starry 预构建/运行模式,并检查相关 PR #1578;后者是不同 binding 的互补实现,但同样共享 GPU/lavapipe 主题,不改变本 PR 已被作者声明 superseded 的流程问题。

请修复 clippy 错误并明确该 PR 与后续 comprehensive suite 的生命周期/范围后再请求复审。

Powered by gpt-5.6-luna

// Negative control for the saxpy family.
if let Some(v) = got.as_ref() {
let mut corrupt = v.clone();
corrupt[0] = corrupt[0] - 1.0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

阻塞(clippy -D warnings):这里触发 clippy::assign_op_pattern。请改为 corrupt[0] -= 1.0,不要用 allow 绕过新增 crate 的 lint 门禁。当前命令 cargo clippy --manifest-path apps/starry/gpu-wgpu/rssrc/wgpu-carpet/Cargo.toml --all-targets -- -D warnings 可复现。

{
let mut pass = enc.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: Some("big"),
timestamp_writes: None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

阻塞(clippy -D warnings):(N_BIG + 63) / 64 触发 clippy::manual_div_ceil。请使用 N_BIG.div_ceil(64)(并保持下方 workgroup 数量语义不变),然后重新运行该 crate 的 clippy。

});
{
let mut pass = enc.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: Some("tail"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

阻塞(clippy -D warnings):((N_TAIL + 63) / 64) as u32 同样触发 clippy::manual_div_ceil。请改用 N_TAIL.div_ceil(64) as u32,不要以 lint suppress 代替修复。

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