core/cnn: SIMD-vectorize BlockedConv's inner loop for WASM - #2592
Open
czoli1976 wants to merge 1 commit into
Open
core/cnn: SIMD-vectorize BlockedConv's inner loop for WASM#2592czoli1976 wants to merge 1 commit into
czoli1976 wants to merge 1 commit into
Conversation
The blocked conv reduced its 16-wide W blocks with scalar multiplies; on wasm +simd128 hosts run the reduction as 4-wide f32x4 load/madd/store per output channel (relaxed-simd FMA when available), fall back to the scalar path elsewhere, and cover the non-const-OCG generic path with a test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.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.
BlockedConvreduced its 16-wide W blocks with scalar multiplies on every target; on wasm+simd128hosts this runs the(kh, icg)reduction as 4×f32x4 load/madd/store per output channel instead, withf32x4_relaxed_madd(FMA) when+relaxed-simdis active and the existing scalar path kept as the fallback when simd128 is off.Numbers
df_convp.1shape (group=2, 64→10ch, kernel [5,1], 100×96), release under wasmtime on x86-64:runrun_simd+simd128+simd128,+relaxed-simdThe ratio is modest because LLVM already auto-vectorizes part of the scalar const-OCG loop; the handwritten version wins on schedule and, under relaxed-simd, on FMA.
Numerics
On plain simd128 each output lane accumulates over
(kh, icg)in the same order and with the same mul-then-add rounding as the scalar kernel, so results are bit-exact againstrun. The relaxed-simd FMA variant rounds once per madd; the test tolerance (1e-5 max abs) covers it.Coverage
The pre-existing
blocked_conv_matches_referencecases all landed in the const-dispatched OCG set, so the non-construn_simd_genericpath had no test; an ocg=7 case now exercises it (full block + remainder).New
unsafehere is the v128 load/store blocks; the file already carriesunsafe(get_unchecked/as_slice_unchecked) in the scalar path.Verified on native (scalar fallback),
wasm32-wasip1+simd128and+relaxed-simdunder wasmtime, andwasm32-unknown-unknownwithout simd;cargo fmt/clippyclean.🍍