New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASM SIMD for NNUE #30
Conversation
7678f0e
to
f8fc3b7
Compare
Wow, amazing work! Do you know if browsers have a good way to test for the required post MVP features? If so, it should be possible to get a test version out on Lichess pretty quickly. |
Thanks for the reply!
Probably, we have to check the wasm binary itself by WebAssembly.validate. |
I think I found a very quick way to check if certain wasm opcode is supported. It's something like this:
|
a446126
to
9cd72ff
Compare
747617c
to
6de439f
Compare
I implemented Four tournaments settings are
each with 100 rounds (200 games) and openings are from noob_3moves.epd. EDIT: Here is the result of this very rudimental test:
|
I was crawling through v8's code and I found that actually EDIT: According to this page https://omahaproxy.appspot.com where it lists latest chrome versions and corresponding v8 version, it seems all (except iOS, which doesn't use v8) should support latest WASM SIMD features. EDIT: I confirmed that the version with |
I made a little frontend EDIT: Due to the security header issue, the page doesn't work for Firefox... |
d1983d6
to
ad85cb1
Compare
Still very impressed with your work. I also see you have created a much cleaner port of Stockfish at https://github.com/hi-ogawa/Stockfish/tree/emscripten. To me it would make sense to stop maintaining this repository in favor of yours. Are you planning to publish it to npm? |
Thanks for noticing my port!
I wasn't planning to make npm package, but sure, I can do that. |
EDIT: I removed
NOTE.md
from the repository and move its content to here https://github.com/hi-ogawa/stockfish.wasm/wiki/NOTEHi @niklasf
I experimented with WASM SIMD and wanted to share the result, which looks promising even though I'm not sure if it's usable stage.
I've seen the closed PR (#21) where it relied on emscripten's x86 SIMD emulation feature, but here, I implemented some linear algebra routines directly using WASM SIMD intrisics.
These are some benchmark results (see NOTE.md for the detail)
As a comparison, these are the results from current stockfish master (29ed22d) on my machine.
A few things I wanted to mention:
I made a separate file
nnue/math.cpp
and WASM SIMD matrix-vector multiplication routine lives there (mostly because I wanted separate translation unit so that I can rebuild faster).I added two build types
wasm_simd
andwasm_simd_post_mvp
, wherewasm_simd_post_mvp
has substantially faster implementation due to new intrinsic__builtin_wasm_dot_s_i32x4_i16x8
.NNUE data is embedded in executable by generating c++ string literal with my little script
embedded_nnue_data.py
,which means the size of
stockfish.wasm
becomes 21MB.I made
bench_eval
command to measure directly the performance of NNUE inference with my another little scripttimeit.hpp
.It seems both Chrome/Chromium(88.0.4324.150) and Firefox(85.0.1) already enables "post-mvp" features when SIMD is enabled.
On Firefox, there is some security restriction regarding
SharedArrayBuffer
and it needs some special http headers to be sent.So, I included
misc/server.py
to run http server with such headers.At this point, I'm not really sure if this should be even PR, but I'm curious what you think about this.
For the next step, I'm planning to implement a way to run javscript as UCI engine executable so that we can compare two versions' strengths direcly by pitting (e.g. by cutechess-cli).
Thanks a lot for reading!