Apple Silicon Support
olmoulin opened this issue ยท 9 comments
hi, I was able to get progcen works on my macbook M1 by doing the following:
Install glfw with homebrew (and make sure the lib path is in DYLD_LIBRARY_PATH)
modify the march=native to mcpu=lightning in the cmake configuration file ...
It is quite an easy fix, so may be good if you want to implement it ...
I don't have an M1 mac but would accept a PR that improved support for M1. cibuildwheel https://cibuildwheel.readthedocs.io/en/stable/#what-does-it-do says it supports apple silicon, so there's probably some way to make the github actions workflow build a wheel for that platform.
@olmoulin Hi, and thanks for the solution you mentioned!
However, since I'm novice to mac computer, can you elaborate what is the lib path here and
let me know where is the cmake configuration file you mentioned?
Thank you :)
Sure, install home-brew, it should be located in /opt/homebrew
update .zshrc file and add the following lines :
export PATH="/opt/homebrew/bin:/opt/homebrew/opt:$PATH"
export DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
type source .zshrc
then type brew install wget cmake glow qt5
clone the git repository from procgen
go into procgen/procgen
edit CMakeLists.txt
replace the line : set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -march=native")
by the following one : set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -mcpu=lightning")
install conda-miniforge and create an environment with python=3.8
activate the environment
Then follow the normal guide to compile and install procgen (as indicated in compile from source section of this GitHub repository) ... I add the lines there for more clarity :
go to procgen folder (top one)
pip install -e .
python -c "from procgen import ProcgenGym3Env; ProcgenGym3Env(num=1, env_name='coinrun')"
python -m procgen.interactive
Hope it helps :)
Thanks for the answer above!
I found this worked for me without editing the CMakeLists.txt file.
If mcpu=lightning
doesn't work, you can try mcpu=apple-m1
. That worked for me. You can check available cpus with the command clang --print-supported-cpus
mcpu=lightning
does not work for me too. I tried changing to mcpu=apple-m1
. But I got the following errors. Has anyone encountered the same? Is this related to some version issues? I am using python3.8 if it helps.
building procgen...RUN FAILED ['cmake', '--build', '.', '--config', 'relwithdebinfo']:
[ 3%] Building CXX object CMakeFiles/env.dir/src/assetgen.cpp.o
[ 6%] Building CXX object CMakeFiles/env.dir/src/cpp-utils.cpp.o
[ 13%] Building CXX object CMakeFiles/env.dir/src/game.cpp.o
[ 13%] Building CXX object CMakeFiles/env.dir/src/entity.cpp.o
[ 16%] Building CXX object CMakeFiles/env.dir/src/game-registry.cpp.o
[ 20%] Building CXX object CMakeFiles/env.dir/src/games/bigfish.cpp.o
[ 23%] Building CXX object CMakeFiles/env.dir/src/basic-abstract-game.cpp.o
[ 26%] Building CXX object CMakeFiles/env.dir/src/games/dodgeball.cpp.o
[ 30%] Building CXX object CMakeFiles/env.dir/src/games/bossfight.cpp.o
[ 33%] Building CXX object CMakeFiles/env.dir/src/games/caveflyer.cpp.o
[ 36%] Building CXX object CMakeFiles/env.dir/src/games/climber.cpp.o
[ 40%] Building CXX object CMakeFiles/env.dir/src/games/coinrun_old.cpp.o
[ 43%] Building CXX object CMakeFiles/env.dir/src/games/coinrun.cpp.o
[ 46%] Building CXX object CMakeFiles/env.dir/src/games/fruitbot.cpp.o
[ 50%] Building CXX object CMakeFiles/env.dir/src/games/heist.cpp.o
[ 53%] Building CXX object CMakeFiles/env.dir/src/games/jumper.cpp.o
[ 56%] Building CXX object CMakeFiles/env.dir/src/games/leaper.cpp.o
[ 60%] Building CXX object CMakeFiles/env.dir/src/games/maze.cpp.o
[ 63%] Building CXX object CMakeFiles/env.dir/src/games/miner.cpp.o
[ 66%] Building CXX object CMakeFiles/env.dir/src/games/ninja.cpp.o
[ 70%] Building CXX object CMakeFiles/env.dir/src/games/chaser.cpp.o
[ 73%] Building CXX object CMakeFiles/env.dir/src/games/plunder.cpp.o
[ 76%] Building CXX object CMakeFiles/env.dir/src/games/starpilot.cpp.o
[ 80%] Building CXX object CMakeFiles/env.dir/src/mazegen.cpp.o
[ 83%] Building CXX object CMakeFiles/env.dir/src/randgen.cpp.o
/mydir/procgen/procgen/src/games/chaser.cpp:296:13: error: variable 'num_orbs' set but not used [-Werror,-Wunused-but-set-variable]
int num_orbs = 0;
^
[ 86%] Building CXX object CMakeFiles/env.dir/src/roomgen.cpp.o
[ 90%] Building CXX object CMakeFiles/env.dir/src/resources.cpp.o
[ 93%] Building CXX object CMakeFiles/env.dir/src/vecgame.cpp.o
1 error generated.
make[2]: *** [CMakeFiles/env.dir/src/games/chaser.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/mydir/procgen/procgen/src/games/starpilot.cpp:231:18: error: variable 'i' set but not used [-Werror,-Wunused-but-set-variable]
for (int i = 0; t <= SHOOTER_WIN_TIME; i++) {
^
1 error generated.
make[2]: *** [CMakeFiles/env.dir/src/games/starpilot.cpp.o] Error 1
make[1]: *** [CMakeFiles/env.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/mydir/procgen/procgen/env.py", line 246, in __init__
super().__init__(num, env_name, options, **kwargs)
File "/mydir/procgen/procgen/env.py", line 96, in __init__
lib_dir = build(debug=debug)
File "/mydir/procgen/procgen/builder.py", line 138, in build
check(run(build_cmd), verbose=package)
File "/mydir/procgen/procgen/builder.py", line 47, in check
raise RunFailure("failed to build procgen from source")
procgen.builder.RunFailure: failed to build procgen from source
Ok, I manage to fix the errors I had by commenting out the following lines in chaser.cpp:296: // int num_orbs = 0;
and chaser.cpp:306: //num_orbs++;
And by replacing cpp:231:18 in starpilot.cpp with: while (t <= SHOOTER_WIN_TIME) {
@raymondchua this seems to be a breaking behavior of c compiler clang
from 12 to 13 (my up-to-date M1 Mac's clang is 14) mentioned elsewhere. I bypassed it by adding another flag to CMakeLists.txt. Let me make a quick PR.
Thanks for following up, @falcondai. My clang version:
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.4.0