Repository navigation
perf(wasm): 新增 PackedSimd (WASM SIMD128) 内核,接入 CPU 派发链 - #31
Merged
Merged
Conversation
Dispatch is now AVX-512 -> AVX2 -> AdvSIMD -> PackedSimd -> Vector<float> -> scalar. - NHWC pointwise / dense / transposed conv: 4 px x 8 oc register tile (V8 gives v128 at most 15 XMM regs on x64; the 6-row tile spilled). Dense conv uses a precomputed per-k input offset table. - NHWC depthwise: 2 px x 16 ch strip kernels. - MatMul (packed) and fused MatMul+ArgMax (CTC head) with register accumulators instead of the Vector path's 16-acc / stackalloc tiles. - Erf / GELU (standalone and fused epilogue). All kernels keep the Vector<float> per-lane operation order (no FMA, separate mul + add), so results are bit-identical: 100-image text hashes match the previous build for tiny / small / medium. Ryzen 7 5800X, Edge 155, 4 workers, mean ms/img (Vector -> PackedSimd): tiny 128.1 -> 112.9 (1.13x), small 474.6 -> 411.3 (1.15x), medium 1654.6 -> 1360.4 (1.22x). docs/wasm.md refreshed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
Author
|
这个 PR 可以合并,我没发现会影响正确性的问题。下面列的几项都是测试覆盖或文档上的小问题,不需要因此挡住合并。 在 PR 的 worktree(
逐项核对过、没有问题的地方
建议(按重要性排序)
附带的 ImageSharp 3.2 升级评估文档不属于这个 PR 的改动,我没有评审它。 |
- PPOCR_PACKEDSIMD=0 forces the Vector<float> path in the same build; WasmBench forwards runtime env vars (--env KEY=VALUE / run.ps1 -Env) so both paths can be A/B'd in the browser. Verified: tiny 100 images, text hashes identical between the two paths. - ArgMax PackedSimd dispatch also requires Vector<float>.Count == 4. - docs/wasm.md: bit-exactness holds for finite inputs; correct the original accumulator counts (NHWC 12, MatMul 16); ArgMax max/index state still lives on the stack; restore blank line before section 5. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keeps the other review fixes (ArgMax Count == 4 guard, docs wording) and the generic WasmBench --env / -Env runtime environment passthrough. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
CPU 内核派发链补上 WebAssembly SIMD128(
System.Runtime.Intrinsics.Wasm.PackedSimd):AVX-512 → AVX2 → AdvSIMD → PackedSimd →
Vector<float>→ scalar此前
browser-wasm只走Vector<float>回退路径。新增 PackedSimd 内核
Vector<float>)主要原因:V8 在 x64 上最多给 v128 分配 15 个 XMM。6 行分块(
Count == 4时 12–16 个累加器)会在内层循环溢出,实测 5 行以上都会溢出,所以统一用 4×8。数值:全部内核与
Vector<float>逐 lane 保持相同的运算顺序(WASM 没有 FMA,乘和加分开做),所以结果逐位一致。微基准逐元素比对都是 bit-exact;100 张图在 tiny / small / medium 上的文本 Hash 与旧版本完全一致。netstandard2.0通过<Compile Remove="**/*PackedSimd.cs" />排除这些文件,派发分支都在#if !NETSTANDARD2_0内。端到端 A/B(Ryzen 7 5800X,Edge 155,4 workers,100 张图)
Vector<float>Meantiny 和 small 是两轮的平均,medium 只跑了一轮。
其他改动
docs/wasm.md:换成本机新数据,补上 ISA 派发说明和 A/B 对比。packedSimdSupported,effectiveIsa改为packedsimd。验证
dotnet build:net10.0 和 netstandard2.0 都通过。Sdcb.SimdPaddleOCR.UnitTests:119 个测试全部通过(桌面 x64,不会走 PackedSimd 分支)。