README.md
lc0-js
lc0-js is an emscripten port of the lc0 engine, very much like stockfish-js is a port of stockfish to the browser. The lc0 engine runs into the browser, without any server computational resources, without need of any pluggins, and possibly offline. tensorflowjs runs the neural network, and uses the GPU to accelerate the computations.
Example
You can play with the engine online here: https://frpays.github.io/lc0-js/.
Compiling
You will need a unix-like operating system (MacOS or Linux), install Emscripten and have emcc in your PATH. You can then build lc0-js typing:
make
The result of the compilation is in the folder www. You can run a local webserver using:
make run_server
Browse to http://localhost:8000/ in order to run your local example.
Porting
Weights
Most of the original code base compiles right out of the box to javascript with emscripten but there are some parts that won't.
Notably:
protobuf: this library is highly optimised for c++. Not only it won't compile, but we have no use of it on the c++ side as the network is loaded by the javascript backend.
zlib: this library does not build compile either, we and we also don't need it on the c++ side.
As a result, all references to protobug and zlib have been removed. No file is loaded on the c++ side and the Weight structure is empty. (Except when the Blas backend is instantiated, generally for debugging purposes. In this case, the only weight file supported format is non-compressed text).
Backends
None of the original backends can be compiled to javascript, except Blas, provided that the matrix multiply calls have been replaced with c++ routines. The Blas backend still exists for debugging purposes but is much slower than tensorflowjs and is normally not instantiated.
A new javascript backend has been written from scratch over tensorflowjs. The backend fetches the weight file with a http request, decodes it (either txt.gz or protobuf gunzipped) and uses tensorflowjs to handle the computations.
Currently the default network is a small id9155 (6b/64) in text.gz format. But it can be switched to a bigger 20b protobuf network (id11248 or id31295).
Threads
There is basic thread support in emscripten, but it is too sketchy and won't work here. The search module and the UCI command processor have been modified to run as a workflow.
Web worker
The engine search is a very resource intensive task. In order to make the graphical interface as responsive as possible, the engine runs inside a web worker when possible. The web worker is a generally well supported feature among browsers, but not yet the offscreen canvas. Without offscreen canvas, tensorflowjs cannot make use of the WebGL extensions to accelerate the network inference. This is why, depending on the browser, the lc0 engine will work either inside a worker or not. At the time of this initial release, Chrome 71 supports the offscreen canvas, Firefox 64 supports it on demand and Safari still does not. Without offscreen canvas support, the engine runs inside the main javascript loop and the interface may feel less responsive.
Release 1 https://github.com/frpays/lc0-js/releases/tag/js-v0.1.0
LC0 Javascript Chess Engine...
Moderator: Ras
-
supersharp77
- Posts: 1266
- Joined: Sat Jul 05, 2014 7:54 am
- Location: Southwest USA