Skip to content

WASM PR 3: test the invariants the WASM kernels rely on, and run CI against relaxed-simd - #2565

Open
czoli1976 wants to merge 2 commits into
sonos:mainfrom
czoli1976:test/wasm-invariants-and-relaxed-ci
Open

WASM PR 3: test the invariants the WASM kernels rely on, and run CI against relaxed-simd#2565
czoli1976 wants to merge 2 commits into
sonos:mainfrom
czoli1976:test/wasm-invariants-and-relaxed-ci

Conversation

@czoli1976

Copy link
Copy Markdown
Contributor

Stacked on #2564.

Two gaps in how the wasm backend is covered, both of which matter before anything touches the kernels.

CI only builds one of the two configurations. The backend chooses its multiply-add form, its int8 packing and its sigmoid/tanh kernels at compile time on +relaxed-simd, so the single +simd128 leg in .travis/cross.sh leaves roughly half of it never executed. This adds a second leg. I ran it: tract-linalg 2208, tract-core 816 + 267, test-unit-core 9 + 1, all green. It does cost a second wasm build and about 2.5 minutes of test time per run — the one thing in this series that costs you something, so say if you would rather not.

Nothing checked that AddRowColProducts and AddMatMul agree on fusion. With k = 1 they compute the same c[i][j] += a[i] * b[j], so within a kernel they have to make the same choice about the fused multiply-add — and today they do, in both directions: 32x1 and 8x8 fuse both arms, the other four fuse neither. Nothing held that in place. The existing mmm_kernel_fuse_tests! cannot: it uses small integers whose products are exact, where fused and separate agree trivially. The new test picks a = b = 1 + 2^-12 against c = -1, so the product needs 25 significand bits and the two forms differ by one ulp, then compares the two arms bit-for-bit. Under +simd128 it is vacuous but still true; under +relaxed-simd it bites. I confirmed it bites by flipping 32x1's AddRowColProducts to the non-fused macro — it fails on exactly that kernel.

Also records why wasm_f32_4x4 sits at TargetOptimized. It is the only kernel not at ManuallyOptimized, so strategize's retain() drops it and neither mmm_f32 nor mmv_f32 names it — it is unreachable through dispatch and reached only by name from its generated tests. It is worth keeping there as the second f32 kernel with a genuinely two-dimensional C tile, which is what gives the generated store and packing tests a second layout to cover, so this documents the arrangement and asserts dispatch never returns it rather than changing anything.

🍍

czoli1976 and others added 2 commits August 3, 2026 21:36
… target

Three timing modules lived in src behind #[cfg(test)] + #[ignore], which no
other backend does. benches/wasm.rs already supersedes two of them — its own
header records that looping four kernels back-to-back biased the in-src
version — so those are dropped, and the activation bench moves across. The
numerical-consistency check between 16x1 and 32x1 is an assertion rather than
a timer, so it stays in src alongside the dispatch tests. The four copies of
the kernel-lookup helper in the bench collapse to one; the timing loops keep
their own warmup and repetition counts, which differ on purpose.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… against relaxed-simd

The backend picks its multiply-add form, its int8 packing and its sigmoid/tanh
kernels at compile time on +relaxed-simd, so the single +simd128 CI leg left
half of it untested; add a second leg. AddRowColProducts and AddMatMul with k=1
compute the same product and so must agree on whether that multiply-add is
fused, which nothing checked — the existing coverage uses operands whose
products are exact, where fused and separate agree trivially. Also record why
wasm_f32_4x4 sits at TargetOptimized and is unreachable through dispatch, and
assert that it stays that way.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kali

kali commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

⚠️⚠️⚠️ Just rebased! ⚠️⚠️⚠️

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.

2 participants