GithubHelp home page GithubHelp logo

lichess-org / stockfish.wasm Goto Github PK

View Code? Open in Web Editor NEW
249.0 13.0 41.0 12.65 MB

WebAssembly port of the strong chess engine Stockfish

Home Page: https://npmjs.com/package/stockfish.wasm

License: GNU General Public License v3.0

Makefile 3.74% C++ 94.08% JavaScript 0.40% Shell 1.54% HTML 0.23%
chess stockfish emscripten lichess webassembly

stockfish.wasm's Introduction

stockfish.wasm

WebAssembly port of the strong chess engine Stockfish. See it in action on https://lichess.org/analysis.

npm version CI Passively maintained

Superceded by Stockfish with NNUE

This port is branched from SF_classical. See https://github.com/hi-ogawa/Stockfish for a WebAssembly port with NNUE support.

Requirements

Uses the latest WebAssembly threading proposal. Requires these HTTP headers on the top level response:

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

And the following header on the included files:

Cross-Origin-Embedder-Policy: require-corp

If headers are not configured correctly on the top level response, wasmThreadsSupported() as defined below will return false. If headers are not configured correctly on the included files, something like pthread sent an error! undefined:undefined: undefined may be logged to the console.

Chromium based (desktop only)

  • Since Chromium 79: Full support.
  • Chromium 74: Supports treading, but cannot allocate additional memory. The default allocation suffices for up to 2 threads and 16 MB hash.
  • Chromium 70 to 73: Needs flag chrome://flags/#enable-webassembly-threads or Origin Trial.

Firefox

  • Since Firefox 79: Full support.
  • Firefox 72 to 78: Structured cloning can no longer be enabled with flags, except on nightlies.
  • Firefox 71: Requires javascript.options.shared_memory and dom.postMessage.sharedArrayBuffer.withCOOP_COEP to be enabled in about:flags.
  • Firefox 68 to 70: Requires javascript.options.shared_memory to be enabled in about:flags

Other browsers

No support.

See stockfish.js for a more portable but single-threaded version.

Feature detection

function wasmThreadsSupported() {
  // WebAssembly 1.0
  const source = Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00);
  if (
    typeof WebAssembly !== "object" ||
    typeof WebAssembly.validate !== "function"
  )
    return false;
  if (!WebAssembly.validate(source)) return false;

  // SharedArrayBuffer
  if (typeof SharedArrayBuffer !== "function") return false;

  // Atomics
  if (typeof Atomics !== "object") return false;

  // Shared memory
  const mem = new WebAssembly.Memory({ shared: true, initial: 8, maximum: 16 });
  if (!(mem.buffer instanceof SharedArrayBuffer)) return false;

  // Structured cloning
  try {
    // You have to make sure nobody cares about these messages!
    window.postMessage(mem, "*");
  } catch (e) {
    return false;
  }

  // Growable shared memory (optional)
  try {
    mem.grow(8);
  } catch (e) {
    return false;
  }

  return true;
}

Current limitations

  • Hashtable: 1024 MB. You may want to check navigator.deviceMemory before allocating.
  • Threads: 32. You may want to check navigator.hardwareConcurrency. May be capped lower (e.g., dom.workers.maxPerDomain in Firefox).
  • Can hang when UCI protocol is misused. (Do not send invalid commands or positions. While the engine is searching, do not change options or start additional searches).
  • No NNUE support.
  • No Syzygy tablebase support.

Building

Assuming em++ (^2.0.13) is available:

npm run-script prepare

Usage

Requires stockfish.js, stockfish.wasm and stockfish.worker.js (total size ~400K, ~150K gzipped) to be served from the same directory.

<script src="stockfish.js"></script>
<script>
  Stockfish().then((sf) => {
    sf.addMessageListener((line) => {
      console.log(line);
    });

    sf.postMessage("uci");
  });
</script>

Or from recent node (v14.4.0 tested) with flags --experimental-wasm-threads --experimental-wasm-bulk-memory:

const Stockfish = require("stockfish.wasm"); // the module, not the file

Stockfish().then((sf) => {
  // ...
});

License

Thanks to the Stockfish team for sharing the engine under the GPL3.

stockfish.wasm's People

Contributors

31m059 avatar ajithcj avatar ceebo avatar elbertoone avatar fauziakram avatar glinscott avatar hxim avatar jcalovski avatar joergoster avatar jromang avatar jundery avatar locutus2 avatar lucasart avatar mcostalba avatar miguel-l avatar mjz1977 avatar niklasf avatar pb00068 avatar r-peleg avatar rocky640 avatar sfisgod avatar snicolet avatar stefano80 avatar syzygy1 avatar unaiic avatar uriblass avatar vizvezdenec avatar vondele avatar voyagerone avatar zamar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stockfish.wasm's Issues

Max memory for analysis on Firefox = 32MB

Hi,

I don't know if this is indeed a new issue, something related to issue #3 or a configuration problem, but in Firefox the possible memory values in the analysis page is 16MB or 32MB.
On Google Chrome I can adjust the memory between 16MB - 1GB.

Inspecting the slider on Firefox and Chrome show this difference:

Firefox:

<div class="setting">
    <label for="analyse-memory">Memory</label>
    <input id="analyse-memory" type="range" min="4" max="5" step="1">
    <div class="range_value">32MB</div>
</div>

On Firefox inspector there is a overflow bubble with the message This element is causing an element to overflow..
The bubble is at the end of each inline inside the block.

Chrome:

<div class="setting">
<label for="analyse-memory">Memory</label>
<input id="analyse-memory" type="range" min="4" max="10" step="1">
<div class="range_value">1GB</div></div>

I'm not a developer, so I couldn't figure out what information would be relevant to this issue or if it is related to the section Current limitations.

Thank you for your work.

System OS: EndeavourOS
Kernel: Linux 5.10.7-zen1-1-zen x86_64
CPU: i7-6500U Skylake
Memory size: 16 GB DDR3
Firefox version: 84.0.2
Chrome version: 87.0.4280.141

How to handle errors when "set position IMPOSSIBLE_FEN"

Hello,

I've problem - when I make Stockfish calculate some impossible position, I get:

 worker.js onmessage() captured an uncaught exception: RuntimeError: memory access out of bounds
pthread sent an error! undefined:undefined: memory access out of bounds

... which crashes my whole app.
Is there some way to prevent engine from calculating such positions, or handle those errors some way?

compile c++ to wasm (old version)

Hello I found stockfish 5 on this link

https://github.com/lichess-org/stockfish.wasm/tree/54f8a9cb138a1bc0b0054b98f911fafd8d1b03ad

i want to covert stockfish 5 c++ project to wasm with Emscripten in linux

i use this code for compile

make ARCH=wasm build -j

but this error

Testing config sanity. If this fails, try 'make help' ...

Makefile:409: recipe for target 'config-sanity' failed
make[1]: *** [config-sanity] Error 1
make[1]: Leaving directory '/root/stockfish/src'
Makefile:365: recipe for target 'build' failed
make: *** [build] Error 2

it is possible to convert this c++ version to wasm ??
what commend I use to compile this version ?
please help ,thank you

Failed to execute 'postMessage'

lichess.site.min.js:26 Lichess is open source! github.com/ornicar/lila
lichess.analyse.min.js:1 watchdog armed: wasmx
stockfish.js:12 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': #<Module> could not be cloned.
at Object.allocateUnusedWorkers (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:31359)
at lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18291
at callRuntimeCallbacks (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:15739)
at preRun (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:16381)
at run (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146940)
at runCaller (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146186)
at removeRunDependency (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18062)
at receiveInstance (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:20807)
at receiveInstantiatedSource (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:21128)
lichess.site.min.js:7 The Web Audio autoplay policy will be re-enabled in Chrome 71 (December 2018). Please check that your website is compatible with it. goo.gl/7K7WLu
s @ lichess.site.min.js:7
stockfish.js:12 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': #<Module> could not be cloned.
at Object.allocateUnusedWorkers (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:31359)
at lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18291
at callRuntimeCallbacks (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:15739)
at preRun (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:16381)
at run (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146940)
at runCaller (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146186)
at removeRunDependency (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18062)
at receiveInstance (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:20807)
at receiveInstantiatedSource (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:21128)
lichess.analyse.min.js:1 watchdog disarmed: wasmx
stockfish.js:12 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': #<Module> could not be cloned.
at Object.allocateUnusedWorkers (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:31359)
at lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18291
at callRuntimeCallbacks (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:15739)
at preRun (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:16381)
at run (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146940)
at runCaller (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146186)
at removeRunDependency (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18062)
at receiveInstance (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:20807)
at receiveInstantiatedSource (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:21128)
stockfish.js:12 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': #<Module> could not be cloned.
at Object.allocateUnusedWorkers (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:31359)
at lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18291
at callRuntimeCallbacks (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:15739)
at preRun (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:16381)
at run (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146940)
at runCaller (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:146186)
at removeRunDependency (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:18062)
at receiveInstance (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:20807)
at receiveInstantiatedSource (lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:21128)

Cannot compile with message "em++: error: any: No such file or directory"

I have just followed your instruction, downloaded, installed very things today (thus all are up to date) on my macOS. I can't compile. The full log as below:

nguyenpham@Nguyens-iMac stockfish.wasm % npm run-script prepare 

> [email protected] prepare /Users/nguyenpham/workspace/chess/stockfish.wasm
> cd src && make clean && make ARCH=wasm build -j && cd .. && cat preamble.js src/stockfish.js > stockfish.js && cp src/stockfish.worker.js src/stockfish.wasm .


Config:
debug: 'no'
sanitize: 'no'
optimize: 'yes'
arch: 'any'
bits: '64'
kernel: 'Darwin'
os: ''
prefetch: 'no'
popcnt: 'yes'
sse: 'no'
pext: 'no'

Flags:
CXX: em++
CXXFLAGS: -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME=Stockfish -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall] -s INCOMING_MODULE_JS_API=[print, postRun, onAbort, onRuntimeInitialized] -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto
LDFLAGS:  -s MODULARIZE=1 -s EXPORT_NAME=Stockfish -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall] -s INCOMING_MODULE_JS_API=[print, postRun, onAbort, onRuntimeInitialized] -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -lpthread -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME=Stockfish -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall] -s INCOMING_MODULE_JS_API=[print, postRun, onAbort, onRuntimeInitialized] -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto

Testing config sanity. If this fails, try 'make help' ...

/Library/Developer/CommandLineTools/usr/bin/make ARCH=wasm COMP=emscripten all
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o benchmark.o benchmark.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o bitbase.o bitbase.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o bitboard.o bitboard.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o endgame.o endgame.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o evaluate.o evaluate.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o main.o main.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o material.o material.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o misc.o misc.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o movegen.o movegen.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o movepick.o movepick.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o pawns.o pawns.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o position.o position.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o psqt.o psqt.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o search.o search.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o thread.o thread.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o timeman.o timeman.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o tt.o tt.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o uci.o uci.cpp
em++ -Wall -Wcast-qual -std=c++11  -s MODULARIZE=1 -s EXPORT_NAME="Stockfish" -s NO_EXIT_RUNTIME=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1 -s TOTAL_MEMORY=67108864 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648 --pre-js pre.js -arch any -mmacosx-version-min=10.9 -DNDEBUG -O3 -mdynamic-no-pic -DIS_64BIT -DNO_PREFETCH -msse3 -mpopcnt -DUSE_POPCNT -flto   -c -o ucioption.o ucioption.cpp
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [benchmark.o] Error 1
make[1]: *** Waiting for unfinished jobs....
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [endgame.o] Error 1
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [tt.o] Error 1
make[1]: *** [pawns.o] Error 1
make[1]: *** [position.o] Error 1
make[1]: *** [misc.o] Error 1
make[1]: *** [bitbase.o] Error 1
make[1]: *** [movepick.o] Error 1
make[1]: *** [uci.o] Error 1
make[1]: *** [search.o] Error 1
make[1]: *** [material.o] Error 1
make[1]: *** [evaluate.o] Error 1
make[1]: *** [psqt.o] Error 1
make[1]: *** [timeman.o] Error 1
make[1]: *** [bitboard.o] Error 1
em++: error: any: No such file or directory ("any" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [movegen.o] Error 1
make[1]: *** [thread.o] Error 1
make[1]: *** [main.o] Error 1
make[1]: *** [ucioption.o] Error 1
make: *** [build] Error 2
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] prepare: `cd src && make clean && make ARCH=wasm build -j && cd .. && cat preamble.js src/stockfish.js > stockfish.js && cp src/stockfish.worker.js src/stockfish.wasm .`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] prepare script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nguyenpham/.npm/_logs/2020-05-26T11_02_52_460Z-debug.log

compile c++ to .js.mem & .wasm

Hello

i coverted stockfish c++ project to wasm and this file created :

stockfish.js
stockfish.wasm
stockfish.worker.js

but also I need stockfish.js.mem for my program , I could not find this file , how to create this file ?

is it possible to create .js.mem file from project ?

please help me , thank you

How to kill process created by Stockfish()?

When you execute Stockfish() it creates an instance of something (engine I guess?) that sits in memory until the main process is killed. Is it possible to kill that thing someway without killing main thread?

I'm running stockfish.wasm on Node.JS server.

Uncaught TypeError: Cannot read property 'apply' of undefined

var __register_pthread_ptr = Module["__register_pthread_ptr"] = (function() {
    return Module["asm"]["__register_pthread_ptr"].apply(null, arguments)
}
VM92 stockfish.js:12 Uncaught TypeError: Cannot read property 'apply' of undefined
    at VM88 stockfish.js:formatted:6585
    at ensureInitRuntime (VM88 stockfish.js:formatted:809)
    at doRun (VM88 stockfish.js:formatted:6888)
    at run (VM88 stockfish.js:formatted:6907)
    at runCaller (VM88 stockfish.js:formatted:6835)
    at removeRunDependency (VM88 stockfish.js:formatted:875)
    at applyMemoryInitializer (VM88 stockfish.js:formatted:6794)
    at XMLHttpRequest.xhr_onload (VM88 stockfish.js:formatted:249)

LDFLAGS duplicate code

Describe the bug
Running the Makefile for wasm it seems to duplicate some flags.

Steps to reproduce the behavior
When running npm run-script prepare the Makefile part $(LDFLAGS) becomes:

 -s MODULARIZE=1 
 -s EXPORT_NAME="Stockfish" 
 -s ENVIRONMENT=web,worker,node 
 -s USE_PTHREADS=1 
 -s PTHREAD_POOL_SIZE=1 
 -s EXIT_RUNTIME=0 
 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" 
 -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" --pre-js pre.js 
 -s ALLOW_MEMORY_GROWTH=1 
 -s INITIAL_MEMORY=67108864 
 -s MAXIMUM_MEMORY=2147483648 
 -s FILESYSTEM=0 --closure 1 
 -s STRICT=1 
 
 -s ASSERTIONS=0 -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++11  

 -s MODULARIZE=1 
 -s EXPORT_NAME="Stockfish" 
 -s ENVIRONMENT=web,worker,node 
 -s USE_PTHREADS=1 
 -s PTHREAD_POOL_SIZE=1 
 -s EXIT_RUNTIME=0 
 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" 
 -s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" --pre-js pre.js 
 -s ALLOW_MEMORY_GROWTH=1 
 -s INITIAL_MEMORY=67108864 
 -s MAXIMUM_MEMORY=2147483648 
 -s FILESYSTEM=0 --closure 1 
 -s STRICT=1 

 -s ASSERTIONS=0 -DNDEBUG -O3 -DIS_64BIT -DNO_PREFETCH -DUSE_POPCNT -flto

Expected behavior
No duplicate code.

Possible solution
When I comment out line 251 it seems to not duplicate the flags:

#CXXFLAGS += $(EMFLAGS)

then the $(LDFLAGS) becomes:

-s MODULARIZE=1 
-s EXPORT_NAME="Stockfish" 
-s ENVIRONMENT=web,worker,node 
-s USE_PTHREADS=1 
-s PTHREAD_POOL_SIZE=1 
-s EXIT_RUNTIME=0 
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" 
-s "INCOMING_MODULE_JS_API=['print', 'postRun', 'onAbort', 'onRuntimeInitialized']" --pre-js pre.js 
-s ALLOW_MEMORY_GROWTH=1 
-s INITIAL_MEMORY=67108864 
-s MAXIMUM_MEMORY=2147483648 
-s FILESYSTEM=0 --closure 1 
-s STRICT=1 
-s ASSERTIONS=0 -lpthread -Wall -Wcast-qual -fno-exceptions -std=c++11  -DNDEBUG -O3 -DIS_64BIT -DNO_PREFETCH -DUSE_POPCNT -flto

How do I set the HTTP headers

After successfully compiling the the WASM and JS using emscripten, I noticed an error accessing the Shared Buffer array as I had not set the proper HTTP Headers
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
In my files.

I know what the issue is however I am failing to find an easy explanation on how to set these values, must I redirect the user to a page and set the values then? Or can I not just have some code that sets those values when the page loads.
Ive been reading the docs at
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest]

Please point me in the direction where I can get the answer to this question, as I clearly must be missing an obvious fact that I fail to grasp regarding HTTP headers.
Thanks

position move and position fen messages generate different stockfish output

This might be expected behavior.

From let's say you make a move from a given starting fen, would you expect
position move the-move
to generate the same output as
position fen the-fen-after-the-move

In my tests it looks like 'position fen ...' is naive to what came before in the game. Is this expected?

See my question on stachexchange which has some engine output
https://chess.stackexchange.com/questions/33903/stockfish-depth-calculations/33906#33906

Multi Threads limitations Problem

Hello , I See This Program Support Until 32 Threads , My Computer has Only 8 Threads , I want To Use 32 Threads For Stockfish Wasm Search

I Do Not Have 32 Thread But In Main Stockfish Project I Use This Comment And It Work :

setoption name threads value 32

How Can I Use This Method In Stockfish Wasm ? Is It Possible ?

Compile with webpack fails

I installed the package with npm (version 6.13.4; node version 12.14.1) and got it to run just fine.

However, when I try to compile it with webpack I get the following error messages:

WARNING in ./node_modules/stockfish.wasm/stockfish.js
Module not found: Error: Can't resolve 'worker_threads' in '/path/to/test/node_modules/stockfish.wasm'
 @ ./node_modules/stockfish.wasm/stockfish.js
 @ ./src/engine.js
 @ ./src/use_sum.js

ERROR in ./node_modules/stockfish.wasm/stockfish.js
Module not found: Error: Can't resolve 'fs' in '/path/to/test/node_modules/stockfish.wasm'
 @ ./node_modules/stockfish.wasm/stockfish.js 20:3758-3771 20:5743-5756
 @ ./src/engine.js
 @ ./src/use_sum.js

ERROR in ./node_modules/stockfish.wasm/stockfish.js
Module not found: Error: Can't resolve 'perf_hooks' in '/path/to/test/node_modules/stockfish.wasm'
 @ ./node_modules/stockfish.wasm/stockfish.js 20:6786-6807
 @ ./src/engine.js
 @ ./src/use_sum.js

my package.json is

{
  "name": "test",
  "version": "1.0.0",
  "description": "this is a test",
  "main": "./dist/index.js",
  "browser": "./dist/index.html",
  "engines": {
    "node": "10.18.x"
  },
  "scripts": {
    "build": "webpack --progress",
  },
  "repository": {
    "type": "git"
  },
  "author": "Patrick",
  "license": "ISC",
  "devDependencies": {
    "eslint": "^6.8.0",
    "eslint-config-airbnb-base": "^14.0.0",
    "eslint-plugin-import": "^2.20.0",
    "html-webpack-plugin": "^3.2.0",
    "jest": "^25.1.0",
    "raw-loader": "^4.0.0",
    "terser-webpack-plugin": "^2.3.4",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.10.2"
  },
  "dependencies": {
    "copy-webpack-plugin": "^5.1.1",
    "esm": "^3.2.25",
    "express": "^4.17.1",
    "mithril": "^2.0.4",
    "stockfish.wasm": "^0.6.1",
    "webpack": "^4.41.5"
  }
}

Do you have any idea what is causing this error or how to mitigate it?

PS Great project! :)

compile c++ to wasm via Emscripten

Hello

i want to covert stockfish c++ project to wasm with Emscripten in windows 10

i use this code for compile

emcc main.cpp

but this error

wasm-ld: error: C:\Users\GO\AppData\Local\Temp\emscripten_temp_25b66pq5\main_0.o: undefined symbol: Options
wasm-ld: error: C:\Users\GO\AppData\Local\Temp\emscripten_temp_25b66pq5\main_0.o: undefined symbol: Threads
wasm-ld: error: C:\Users\GO\AppData\Local\Temp\emscripten_temp_25b66pq5\main_0.o: undefined symbol: TT

it is possible to convert c++ to wasm in windows ???
also i have visual studio 2019 but only compile .exe not .wasm
please help ,thank you

pthread sent an error

Whenever importing the script and then doing Stockfish().then... etc
I get the following error printed in my console: pthread sent an error! undefined:undefined: undefined
Why does this happen?

pthread sent an error! undefined:undefined: undefined

I am getting the error in the title in firefox 80.0.1. The same code is working in chromium 85.0.4183.83.

Code: https://github.com/ArneVogel/listudy/blob/stockfish_play/lib/listudy_web/templates/study/play.html.eex#L13

Output:

hi
pthread sent an error! undefined:undefined: undefined              stockfish.js:45:439

js/stockfish.js js/stockfish.wasm js/stockfish.worker.js were copied from node_modules/stockfish.wasm/, which was installed with npm i stockfish.wasm.

convert c++ to javascript

hi niklas

i want to convert stockfish c++ code to stockfish javascript as exist exactly same name function c++ in javascript ?

for example :

  Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {

}

How do I receive the engine output in my code?

I am able to run the engine using this library but I cannot intercept the output of the engine before it is printed in the console. I tried using some standard methods like onmessage or onbestmove but nothing worked.

const Stockfish = require("stockfish.wasm")
Stockfish().then((engine) => {
    engine.postMessage("uci");
    engine.postMessage("ucinewgame");
    engine.postMessage("position startpos");
    engine.postMessage("go depth 20 multipv 2");
    engine.onmessage = (output) => {
      console.log(output);
      // This does not log anything as onmessage is not the correct name...
    }
});

What is this function which prints the output to the console called and how do I modify it?

A GUI to work with?

Can you create a Graphical User Interface or suggest one which can work with Stockfish.wasm? I knew Lichess can run it but it is not what I want. I prefer an independent system that can install and run from a website.

wasmThreadSupported returns false in node

Hello,
The function wasmThreadSupported in the readme returns false in node. Am I correct to assume that this function should only be used in the browser setting? I already have your package running well on node 14 with the experimental flags enabled.

In general I am looking for a robust way to check to see if stockfish.wasm is support in whatever environment I am running it in. In my project right now I use stockfish.wasm on the node backend and stockfish.js on the front end. But in both environment I'd like to check to see if stockfish.wasm is supported and if not fall back to stockfish.js. I'm writing a wrapper that does so (and also promisifies some of the UCI messages).

Perhaps it would be better if wasmThreadSupported was a method on this projects object? ...
const Stockfish = require('stockfish.wasm'); Stockfish. wasmThreadSupported();
That would help this function/method stay current with future updates to stockfish.wasm.

Or am I reinventing the wheel? Have robust ways of checking stockfish.wasm and falling back to stockfish.js already been worked out?

bad ioctl syscall 0

stockfish.js:12 bad ioctl syscall 0
abort @ stockfish.js:12
stockfish.js:12 abort("bad ioctl syscall 0"). Build with -s ASSERTIONS=1 for more info.
abort @ stockfish.js:12
stockfish.js:12 exception thrown: abort("abort(\"bad ioctl syscall 0\"). Build with -s ASSERTIONS=1 for more info."). Build with -s ASSERTIONS=1 for more info.
callMain @ stockfish.js:12
white#12:1 Uncaught (in promise) abort("abort(\"bad ioctl syscall 0\"). Build with -s ASSERTIONS=1 for more info."). Build with -s ASSERTIONS=1 for more info.
lichess.analyse.min.js:1 

Expose as web worker

Is it possible to expose stockfish.wasm as web worker, similar as to what you did in https://github.com/niklasf/stockfish.js? So that one could run

var stockfish = new Worker(wasmThreadSupported ? 'stockfish.worker.js' : 'stockfish.js');

Unfortunately when I tried this out it didn't work...

Lift 16 Thread limit for Ryzen and future Processors

The 1gb and 16 thread limit is really bad compared to native stockfish-avx performance.
On Ryzen and future intel processors (anything above 8 cores) you lose speed.

So i would suggest setting threadpool size up to 64 threads. (This will yield +100% nps)
I dont know if 1GB is a hard limit but i would suggest 4GB. (This probably will yield +5%)

stockfish.wasm is currently limiting analysis performance on lichess.org.

Divide by zero

Sometimes when changing the number of threads:

lichess.site.min.js:26 Lichess is open source! https://github.com/ornicar/lila
lichess.analyse.min.js:1 watchdog armed: wasmx
lichess.analyse.min.js:1 watchdog disarmed: wasmx
pthread-main.js:188 pthread-main.js onmessage() captured an uncaught exception: RuntimeError: divide by zero
onmessage @ pthread-main.js:188
pthread-main.js:189 RuntimeError: divide by zero
    at wasm-function[255]:1003
    at wasm-function[402]:3127
    at wasm-function[896]:1738
    at wasm-function[880]:288
    at wasm-function[879]:149
    at wasm-function[452]:12
    at Object.dynCall_ii (https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:143795)
    at onmessage (https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/pthread-main.js:151:38)
onmessage @ pthread-main.js:189
pthread-main.js:47 Pthread 49575216 uncaught exception in https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/pthread-main.js:190:5: Uncaught RuntimeError: divide by zero. Error object:
(anonymous) @ pthread-main.js:47
pthread-main.js:48 RuntimeError: divide by zero
    at wasm-function[255]:1003
    at wasm-function[402]:3127
    at wasm-function[896]:1738
    at wasm-function[880]:288
    at wasm-function[879]:149
    at wasm-function[452]:12
    at Object.dynCall_ii (https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:143795)
    at onmessage (https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/pthread-main.js:151:38)
(anonymous) @ pthread-main.js:48
VM64 stockfish.js:12 pthread sent an error! https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/pthread-main.js:190: Uncaught RuntimeError: divide by zero
(anonymous) @ VM64 stockfish.js:12
pthread-main.js:190 Uncaught RuntimeError: divide by zero
    at wasm-function[255]:1003
    at wasm-function[402]:3127
    at wasm-function[896]:1738
    at wasm-function[880]:288
    at wasm-function[879]:149
    at wasm-function[452]:12
    at Object.dynCall_ii (https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/stockfish.js:12:143795)
    at onmessage (https://lichess.org/assets/_UcLLmA/vendor/stockfish.wasm/pthread-main.js:151:38)
wasm-function[255]
wasm-function[402]
wasm-function[896]
wasm-function[880]
wasm-function[879]
wasm-function[452]
(anonymous) @ stockfish.js:12
onmessage @ pthread-main.js:151

Freezes when "go" inmediatly after receive "bestmove"

If we configure a loop of:
a) position fen ...
b) go depth ...
c) wait for "bestmove"

The engine freezes in the second iteration. Workaround is to delay the "go" command few milliseconds after receive the previous "bestmove".

logs:
stockfish.onMessage:Stockfish 120719 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
onMessage:id name Stockfish 120719 64 POPCNT
onMessage:id author T. Romstad, M. Costalba, J. Kiiski, G. Linscott
onMessage:
onMessage:option name Debug Log File type string default
onMessage:option name Contempt type spin default 24 min -100 max 100
onMessage:option name Analysis Contempt type combo default Both var Off var White var Black var Both
onMessage:option name Threads type spin default 1 min 1 max 4
onMessage:option name Hash type spin default 16 min 1 max 16
onMessage:option name Clear Hash type button
onMessage:option name Ponder type check default false
onMessage:option name MultiPV type spin default 1 min 1 max 500
onMessage:option name Skill Level type spin default 20 min 0 max 20
onMessage:option name Move Overhead type spin default 30 min 0 max 5000
onMessage:option name Minimum Thinking Time type spin default 20 min 0 max 5000
onMessage:option name Slow Mover type spin default 84 min 10 max 1000
onMessage:option name nodestime type spin default 0 min 0 max 10000
onMessage:option name UCI_Chess960 type check default false
onMessage:option name UCI_AnalyseMode type check default false
onMessage:uciok
postMessage:position fen 2k5/8/8/8/8/5P2/8/4K3 w - - 0 1
postMessage:go depth 40

onMessage:info depth 1 seldepth 1 multipv 1 score cp 4795 nodes 6 nps 6000 time 1 pv e1f2
onMessage:info depth 2 seldepth 2 multipv 1 score cp 4795 nodes 17 nps 269 time 63 pv e1f2 c8b7
onMessage:info depth 3 seldepth 3 multipv 1 score cp 4795 nodes 62 nps 607 time 102 pv e1f2 c8c7 f2g2
onMessage:info depth 4 seldepth 4 multipv 1 score cp 4795 nodes 121 nps 1152 time 105 pv e1f2 c8c7 f2g2 c7b6
onMessage:info depth 5 seldepth 5 multipv 1 score cp 4795 nodes 254 nps 2116 time 120 pv e1f2 c8c7 f2g2 c7c6 g2g3
onMessage:info depth 6 seldepth 6 multipv 1 score cp 4795 nodes 420 nps 3255 time 129 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6
onMessage:info depth 7 seldepth 7 multipv 1 score cp 4795 nodes 716 nps 5114 time 140 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4
onMessage:info depth 8 seldepth 8 multipv 1 score cp 4795 nodes 1080 nps 7448 time 145 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6
onMessage:info depth 9 seldepth 9 multipv 1 score cp 4795 nodes 1709 nps 10614 time 161 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6 f4g4
onMessage:info depth 10 seldepth 10 multipv 1 score cp 4795 nodes 2145 nps 12257 time 175 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6 f4g4 e6e5
onMessage:info depth 11 seldepth 11 multipv 1 score cp 4795 nodes 2987 nps 16594 time 180 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6 f4g4 e6e5 g4g5
onMessage:info depth 12 seldepth 12 multipv 1 score cp 4795 nodes 3892 nps 21037 time 185 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6 f4g4 e6f7 g4g5 f7f8
onMessage:info depth 13 seldepth 13 multipv 1 score cp 4795 nodes 4974 nps 24746 time 201 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6 f4g4 e6f7 g4g5 f7f8 g5f5
onMessage:info depth 14 seldepth 14 multipv 1 score cp 4795 nodes 6361 nps 29863 time 213 pv e1f2 c8c7 f2g2 c7c6 g2g3 c6d6 g3f4 d6e6 f4g4 e6f7 g4g5 f7g8 g5f5 g8g7
onMessage:info depth 15 seldepth 15 multipv 1 score cp 4796 nodes 10885 nps 49477 time 220 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5
onMessage:info depth 16 seldepth 16 multipv 1 score cp 4796 nodes 12521 nps 54916 time 228 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8f8 f4f5 f8e8
onMessage:info depth 17 seldepth 17 multipv 1 score cp 4796 nodes 14304 nps 60610 time 236 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5 g7f8 e6f6
onMessage:info depth 18 seldepth 18 multipv 1 score cp 4796 nodes 16047 nps 64967 time 247 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5 g7f8 e6f6 f8g8
onMessage:info depth 19 seldepth 19 multipv 1 score cp 4796 nodes 18119 nps 69688 time 260 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5 g7f8 e6f6 f8g8 f6g6
onMessage:info depth 20 seldepth 20 multipv 1 score cp 4796 nodes 21198 nps 79097 time 268 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5 g7f8 e6f6 f8g8 f6g6 g8f8
onMessage:info depth 21 seldepth 21 multipv 1 score cp 4797 nodes 28969 nps 103831 time 279 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5 g7f8 e6f6 f8g8 f6e7 g8h7 e7e6
onMessage:info depth 22 seldepth 22 multipv 1 score cp 4797 nodes 32972 nps 116098 time 284 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7g8 f3f4 g8g7 f4f5 g7f8 e6f6 f8g8 f6e7 g8h7 e7e6 h7h6
onMessage:info depth 23 seldepth 24 multipv 1 score cp 5916 nodes 50508 nps 165058 time 306 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7d6 f3f4 d6d5 f4f5 d5e4 f5f6 e4f3 f6f7 f3g2 f7f8q
onMessage:info depth 24 seldepth 24 multipv 1 score cp 5924 nodes 62971 nps 198022 time 318 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7d6 f3f4 d6d5 f4f5 d5c4 g6g5 c4b3 f5f6 b3b2 f6f7 b2a3 f7f8q a3a4
onMessage:info depth 25 seldepth 26 multipv 1 score cp 5924 nodes 69512 nps 213226 time 326 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7d6 f3f4 d6d5 f4f5 d5c4 g6g5 c4b3 f5f6 b3a2 g5g6 a2a3 g6g7 a3a2 f6f7
onMessage:info depth 26 seldepth 27 multipv 1 score cp 5929 nodes 84147 nps 229909 time 366 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 f4f5 f8g8 g6f6 g8f8 f6e6 f8g7 f5f6 g7g6 e6e7 g6f5 f6f7 f5e4 f7f8q
onMessage:info depth 27 seldepth 28 multipv 1 score cp 5933 nodes 95599 nps 252907 time 378 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 f4f5 f8g8 g6f6 g8f8 f6e6 f8g7 f5f6 g7g6 e6e7 g6f5 f6f7 f5e4 f7f8q e4d3
onMessage:info depth 28 seldepth 29 multipv 1 score cp 5933 nodes 102350 nps 254601 time 402 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 f4f5 f8g8 g6f6 g8f8 f6e6 f8g7 f5f6 g7g6 e6e7 g6f5 f6f7 f5e4 f7f8q e4d3 e7f6
onMessage:info depth 29 seldepth 31 multipv 1 score cp 5943 nodes 128965 nps 300617 time 429 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e5 g8f7 e5f5 f7g7 f5e6 g7h6 f4f5 h6g5 f5f6 g5f4 e6e7 f4e5
onMessage:info depth 30 seldepth 30 multipv 1 score cp 5943 nodes 140525 nps 322305 time 436 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e5 g8f7 e5f5 f7g7 f5e6 g7h6 f4f5 h6g5 f5f6 g5f4 e6e7 f4e5 f6f7 e5d5
onMessage:info depth 31 seldepth 31 multipv 1 score cp 5943 nodes 152153 nps 340387 time 447 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e5 g8f7 e5f5 f7g7 f5e6 g7h6 f4f5 h6g5 f5f6 g5f4 e6e7 f4e5 f6f7 e5d5 f7f8q
onMessage:info depth 32 seldepth 32 multipv 1 score cp 5943 nodes 162886 nps 354871 time 459 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e5 g8f7 e5f5 f7g7 f5e6 g7h6 f4f5 h6g5 f5f6 g5f4 e6e7 f4e5 f6f7 e5d5 f7f8q d5d4
onMessage:info depth 33 seldepth 33 multipv 1 score cp 5943 nodes 180829 nps 382302 time 473 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e5 g8f7 e5f5 f7g7 f5e6 g7h6 f4f5 h6g5 f5f6 g5f4 e6e7 f4e5 f6f7 e5d5 f7f8q d5d4 e7f6
onMessage:info depth 34 seldepth 34 multipv 1 score cp 5943 nodes 214202 nps 432731 time 495 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e5 g8f7 e5f5 f7g7 f5e6 g7h6 f4f5 h6g5 f5f6 g5f4 e6e7 f4e5 f6f7 e5d5 f7f8q d5d4 e7f6 d4e4
onMessage:info depth 35 seldepth 39 multipv 1 score cp 5952 nodes 412522 nps 712473 time 579 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f6e7 g8g7 f4f5 g7h6 f5f6 h6g5 e7e6 g5f4 f6f7 f4e3 f7f8q e3d3 e6d5 d3e2 f8a3 e2d1 d5d4 d1e1
onMessage:info depth 36 seldepth 39 multipv 1 score cp 5961 nodes 538908 nps 825280 time 653 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f4f5 g8h7 f6e6 h7h6 f5f6 h6g5 f6f7 g5f4 f7f8q f4e3 e6d5 e3d3 f8a3 d3e2 d5d4 e2f2 a3h3 f2g1 h3f3 g1h2 d4e3
onMessage:info depth 37 seldepth 40 multipv 1 score cp 5971 nodes 640611 nps 904817 time 708 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8f8 g6f6 f8g8 f4f5 g8h7 f6e6 h7h6 f5f6 h6g5 f6f7 g5f4 f7f8q f4e3 e6d5 e3d3 f8a3 d3e2 d5d4 e2f2 a3h3 f2g1 h3f3 g1h2 d4e3 h2g1
onMessage:info depth 38 seldepth 41 multipv 1 score cp 5982 nodes 866075 nps 1079894 time 802 pv e1f2 c8c7 f2g3 c7d6 g3f4 d6e6 f4g5 e6f7 g5f5 f7e7 f5g6 e7e8 f3f4 e8e7 f4f5 e7f8 g6f6 f8e8 f6g7 e8d7 f5f6 d7c6 f6f7 c6b5 f7f8q b5a4 g7f6 a4b3 f6e5 b3c2 f8a3 c2d2 e5d4 d2e1 a3b3 e1f2 b3h3 f2g1
onMessage:info depth 39 seldepth 39 multipv 1 score mate 54 nodes 1598547 nps 1503807 hashfull 60 time 1063 pv e1f2 c8d7 f2g3 d7e7 g3g4 e7f6 g4f4 f6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7f8 e6f6 f8e8 f6f5 e8d8 f5f4 d8c7 f4g4 c7b7 g4g3 b7a8 f3f4 a8b8 g3g4 b8a7 f4f5 a7a8 g4h5 a8b7 h5g5 b7a7
onMessage:info depth 40 seldepth 55 multipv 1 score mate 40 nodes 2199565 nps 1705089 hashfull 66 time 1290 pv e1f2 c8d7 f2g3 d7e7 g3g4 e7f6 g4f4 f6e6 f4g5 e6f7 g5f5 f7g7 f5e6 g7f8 e6f6 f8e8 f6g6 e8e7 f3f4 e7e8 f4f5 e8f8 g6f6 f8e8 f6g7 e8d7 f5f6 d7c6 f6f7 c6c5 f7f8q c5c4 g7f6 c4d3 f8a3 d3e2 f6e6 e2f2 a3f8 f2e2 e6d5 e2e3
onMessage:bestmove e1f2 ponder c8d7
postMessage:position fen 2k5/8/8/8/8/5P2/5K2/8 b - - 1 1
postMessage:go depth 40

error when building with em++

Hello, i have installed the newest version of em++ (3.1) but im getting the following error when trying to build the stockfish.wasm app:

error: legacy setting used in strict mode: USE_PTHREADS

I have tried to replace USE_PTHREADS with PTHREADS (which ive read is the newer version of USE_PTHREADS) in MakeFile which results in another error:

PTHREADS is an internal setting and cannot be set from command line

Im not very familiar with Emscripten, is it an error related to the em++ version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.