使用 emscripten 编译 stockfish 10 wasm 时出现内存错误
Memory error when compiling stockfish 10 wasm with emscripten
我在编译过程中遇到内存问题:"Fatal: cannot apply sbrk-val since memory is not flattenable"(更多内容见下文)。其实我只是想编译Stockfish js Wasm but replacing the original Makefile witht the following : custom makefile。
我的目标是尽可能避免对 nodejs 的依赖,以便我可以在 React Native 中使用它。
这是控制台输出
$> make all 2 ↵
em++ -std=c++11 -c bitbase.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c bitboard.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c endgame.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c evaluate.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c main.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c material.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c misc.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c movegen.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c movepick.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c pawns.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c position.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c psqt.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c search.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c thread.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c timeman.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c tt.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c uci.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c ucioption.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -o stockfish.wasm bitbase.o bitboard.o endgame.o evaluate.o main.o material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM -s SIDE_MODULE=1
Fatal: cannot apply sbrk-val since memory is not flattenable
Traceback (most recent call last):
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 3681, in <module>
sys.exit(run(sys.argv))
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 2514, in run
optimizer)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 3028, in do_binaryen
debug=intermediate_debug_info)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 2903, in run_wasm_opt
return Building.run_binaryen_command('wasm-opt', *args, **kwargs)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 2899, in run_binaryen_command
run_process(cmd)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 188, in run_process
result.check_returncode()
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 168, in check_returncode
raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
tools.shared.Py2CalledProcessError: Command '['/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/bin/wasm-opt', '--post-emscripten', '--no-exit-runtime', '-Oz', '--low-memory-unused', '--strip-debug', '--strip-producers', '--pass-arg=emscripten-sbrk-ptr@-1', '--pass-arg=emscripten-sbrk-val@-1', 'stockfish.wasm', '-o', 'stockfish.wasm', '--mvp-features']' returned non-zero exit status 1
make: *** [Makefile:16: stockfish.wasm] Error 1
有人能帮我理解为什么会这样吗?
我找到了需要更改的内容:
标志 -s TOTAL_MEMORY=33554432 是固定内存和编译器拒绝进程的原因。
我在编译过程中遇到内存问题:"Fatal: cannot apply sbrk-val since memory is not flattenable"(更多内容见下文)。其实我只是想编译Stockfish js Wasm but replacing the original Makefile witht the following : custom makefile。
我的目标是尽可能避免对 nodejs 的依赖,以便我可以在 React Native 中使用它。
这是控制台输出
$> make all 2 ↵
em++ -std=c++11 -c bitbase.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c bitboard.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c endgame.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c evaluate.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c main.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c material.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c misc.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c movegen.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c movepick.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c pawns.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c position.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c psqt.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c search.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c thread.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c timeman.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c tt.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c uci.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c ucioption.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -o stockfish.wasm bitbase.o bitboard.o endgame.o evaluate.o main.o material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM -s SIDE_MODULE=1
Fatal: cannot apply sbrk-val since memory is not flattenable
Traceback (most recent call last):
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 3681, in <module>
sys.exit(run(sys.argv))
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 2514, in run
optimizer)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 3028, in do_binaryen
debug=intermediate_debug_info)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 2903, in run_wasm_opt
return Building.run_binaryen_command('wasm-opt', *args, **kwargs)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 2899, in run_binaryen_command
run_process(cmd)
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 188, in run_process
result.check_returncode()
File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 168, in check_returncode
raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
tools.shared.Py2CalledProcessError: Command '['/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/bin/wasm-opt', '--post-emscripten', '--no-exit-runtime', '-Oz', '--low-memory-unused', '--strip-debug', '--strip-producers', '--pass-arg=emscripten-sbrk-ptr@-1', '--pass-arg=emscripten-sbrk-val@-1', 'stockfish.wasm', '-o', 'stockfish.wasm', '--mvp-features']' returned non-zero exit status 1
make: *** [Makefile:16: stockfish.wasm] Error 1
有人能帮我理解为什么会这样吗?
我找到了需要更改的内容: 标志 -s TOTAL_MEMORY=33554432 是固定内存和编译器拒绝进程的原因。