Skip to content

Add a WASM SIMD128 8x4 SGEMM microkernel - #6023

Open
jjerphan wants to merge 1 commit into
OpenMathLib:developfrom
jjerphan:wasm128-sgemm-8x4
Open

Add a WASM SIMD128 8x4 SGEMM microkernel#6023
jjerphan wants to merge 1 commit into
OpenMathLib:developfrom
jjerphan:wasm128-sgemm-8x4

Conversation

@jjerphan

@jjerphan jjerphan commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #5983 / #5986 / #5680 / #4023: replace the 4×4 SGEMM microkernel for WASM128_GENERIC with an 8×4 tile so adjacent f32x4 A loads match the V8 WasmRevecReducer shape. Double stays on the existing 4×4 path.

  • SGEMM_DEFAULT_UNROLL_M/N become 8/4. SGEMMKERNEL uses kernel/wasm/gemmkernel_8x4_wasm128.c with gemm_{n,t}copy_8 for A and gemm_{n,t}copy_4 for B.
  • STRMMKERNEL switches to generic trmmkernel_8x4.c so TRMM unroll matches SGEMM. DTRMMKERNEL stays trmmkernel_4x4_wasm128.c; DGEMM packing and unroll stay 4×4.
  • Relaxed madd is used in the SGEMM inner k-loop when compiled with -mrelaxed-simd / WASM_RELAXED_SIMD=1 (same as GEMM in Add a 4x4 WASM SIMD128 GEMM microkernel #5983). Remainders keep 4/2/1 scalar (and a 4-wide SIMD panel for bm & 4).

Benchmarks

Node / Emscripten, TARGET=WASM128_GENERIC, USE_THREAD=0, COMMON_OPT=-O2, WASM_RELAXED_SIMD=1. Same machine, pinned to one P-core (taskset -c 0), median of timed samples. Speedup > 1 means this branch is faster than develop.

Geomean vs develop (n = 64…4096): SGEMM 1.52x, SSYRK 1.47x, STRMM 1.30x, STRSM 1.22x. DGEMM/DSYRK/DTRMM/DTRSM unchanged within noise (~1.00x).

op n develop MFLOPS 8x4 MFLOPS speedup
sgemm 64 26947.2 37264.9 1.383
sgemm 128 27032.8 42076.1 1.556
sgemm 256 28086.9 43561.5 1.551
sgemm 512 28842.5 41872.3 1.452
sgemm 1024 28300.8 45321.0 1.601
sgemm 2048 29265.3 45075.0 1.540
sgemm 4096 30399.6 47028.1 1.547
ssyrk 64 25290.1 31863.6 1.260
ssyrk 128 27646.8 39643.7 1.434
ssyrk 256 30235.2 44223.4 1.463
ssyrk 512 30996.6 46699.1 1.507
ssyrk 1024 30669.0 47689.7 1.555
ssyrk 2048 31164.8 48452.6 1.555
ssyrk 4096 31017.6 48258.7 1.556
strmm 64 25397.0 28038.7 1.104
strmm 128 30082.0 33779.7 1.123
strmm 256 31072.7 37505.8 1.207
strmm 512 31762.2 42779.3 1.347
strmm 1024 31704.7 43052.4 1.358
strmm 2048 31370.6 47616.9 1.518
strmm 4096 31151.7 47383.5 1.521
strsm 64 16118.3 13295.8 0.825
strsm 128 21350.9 21217.3 0.994
strsm 256 25570.2 29843.4 1.167
strsm 512 28219.7 37165.9 1.317
strsm 1024 30017.9 42520.5 1.417
strsm 2048 30836.5 46110.6 1.495
strsm 4096 30776.0 46643.2 1.516

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

@jjerphan

jjerphan commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Local Node / Emscripten correctness gate on this branch (TARGET=WASM128_GENERIC, USE_THREAD=0, WASM_RELAXED_SIMD=1):

  • CBLAS odd-size GEMM/TRSM/TRMM check: OK
  • utest: 106/106 ok
  • CBLAS ctest L1/L2/L3 (x{s,d,c,z}cblat{1,2,3}): no computational failures

@martin-frbg martin-frbg added this to the 0.3.35 milestone Sep 9, 2026
ZGEMVTKERNEL = ../riscv64/zgemv_t.c

STRMMKERNEL = ../generic/trmmkernel_4x4.c
STRMMKERNEL = ../generic/trmmkernel_8x4.c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wonder whether this rather be changed in another PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

GEMM is usually linked to TRMM (and SYMM) in OpenBLAS, so I'm fine with having it here

@jjerphan
jjerphan marked this pull request as draft September 9, 2026 13:00
@jjerphan

jjerphan commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

I have opened #6024 which should be valuable for properly testing all those new kernels for WASM.

Wire single-precision 8x4 tile and packers; leave double on the existing 4x4 path.
@jjerphan
jjerphan marked this pull request as ready for review September 11, 2026 08:53
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