Skip to content

Add a 4x4 WASM SIMD128 GEMM microkernel - #5983

Open
jjerphan wants to merge 2 commits into
OpenMathLib:developfrom
jjerphan:wasm128-4x4-gemm
Open

Add a 4x4 WASM SIMD128 GEMM microkernel#5983
jjerphan wants to merge 2 commits into
OpenMathLib:developfrom
jjerphan:wasm128-4x4-gemm

Conversation

@jjerphan

Copy link
Copy Markdown

Summary

Follow-up to #5680 / #4023: replace the 2x2 shuffle GEMM for WASM128_GENERIC with a 4x4 outer-product kernel so f32x4 / f64x2 loads match packing width.

  • SGEMM/DGEMM use gemmkernel_4x4_wasm128.c with matching gemm_{n,t}copy_4 and generic TRMM 4x4.
  • KERNEL TRMM defaults are wrapped in ifndef so KERNEL.WASM128_GENERIC packing width is not overwritten.
  • -mrelaxed-simd plus relaxed_madd in the GEMM inner loop only; DOT/AXPY stay IEEE mul+add in intrin_wasm.h.
  • Separate commit gates leftover WASM TRSM call counters behind OPENBLAS_WASM_TRSM_PROFILE.

Benchmarks

Node / Emscripten, TARGET=WASM128_GENERIC, USE_THREAD=0, COMMON_OPT=-O2. Same machine, 5 warmup + 10 timed samples (median). Speedup > 1 means this branch is faster than develop.

Geomean vs develop: SGEMM 1.44x, DGEMM 1.82x, SSYRK 1.46x, DSYRK 1.73x, STRSM 1.33x, DTRSM 1.39x. Level-1/2 kernels are unchanged within noise.

op n develop MFLOPS 4x4 MFLOPS speedup
sgemm 32 14141.8 27612.0 1.953
sgemm 64 18077.5 26887.8 1.487
sgemm 128 20662.3 25570.7 1.238
sgemm 256 20922.9 28427.7 1.359
sgemm 512 22546.2 28625.6 1.270
dgemm 32 9728.9 17933.1 1.843
dgemm 64 10937.9 19025.1 1.739
dgemm 128 11355.1 20954.0 1.845
dgemm 256 11948.5 21770.6 1.822
dgemm 512 11893.9 22016.5 1.851
ssyrk 32 9938.9 17646.4 1.775
ssyrk 64 15650.7 23219.1 1.484
ssyrk 128 19700.5 26626.8 1.352
ssyrk 256 21511.9 27573.4 1.282
dsyrk 32 7782.4 12758.0 1.639
dsyrk 64 9920.3 17041.1 1.718
dsyrk 128 10926.3 19363.8 1.772
dsyrk 256 11743.9 21167.8 1.802
strsm 32 6908.7 10204.4 1.477
strsm 64 10845.4 15067.1 1.389
strsm 128 15141.3 19255.0 1.272
strsm 256 19006.7 22809.6 1.200
dtrsm 32 5288.2 6726.3 1.272
dtrsm 64 7730.9 9780.4 1.265
dtrsm 128 9644.2 13868.7 1.438
dtrsm 256 10760.1 17370.6 1.614

Test plan

  • Node CBLAS odd-size GEMM/TRSM/TRMM check
  • utest under node (106/106)
  • CBLAS ctest L1/L2/L3 (x{s,d,c,z}cblat{1,2,3}) under node, including SGEMM/DGEMM, STRMM/DTRMM, STRSM/DTRSM, SSYRK/DSYRK

Keep production STRSM/DTRSM free of always-on increments; enable the
counters only when counting invocations.

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Switch WASM128_GENERIC to unroll 4 with matching ncopy/tcopy and TRMM
4x4 so packing width stays consistent. Use relaxed SIMD madd in the
inner loop when compiled with -mrelaxed-simd.

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
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