Skip to content
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

Apple Silicon Support #69

Open
ghost opened this issue Oct 9, 2021 · 9 comments
Open

Apple Silicon Support #69

ghost opened this issue Oct 9, 2021 · 9 comments

Comments

@ghost
Copy link

ghost commented Oct 9, 2021

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 ...

@christopherhesse
Copy link
Collaborator

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.

@christopherhesse christopherhesse changed the title Not an issue, just a suggestion Apple Silicon Support Jan 15, 2022
@heyzude
Copy link

heyzude commented Feb 9, 2022

@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 :)

@ghost
Copy link
Author

ghost commented Feb 18, 2022

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 :)

@skezle
Copy link

skezle commented Apr 25, 2022

Thanks for the answer above!

I found this worked for me without editing the CMakeLists.txt file.

sgoodfriend added a commit to sgoodfriend/procgen that referenced this issue Feb 10, 2023
Following instructions from openai#69
@jhsul
Copy link

jhsul commented Mar 14, 2023

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

@raymondchua
Copy link

raymondchua commented Apr 19, 2023

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

@raymondchua
Copy link

raymondchua commented Apr 19, 2023

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) {

@falcondai
Copy link

@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.

falcondai added a commit to falcondai/procgen that referenced this issue May 3, 2023
Problem:
As mentioned in [this comment](openai#69 (comment)) of openai#69, a compilation crashes due to an error of unused variables on Apple silicon (with clang 14 and possibly 13+). This issue has been reported [elsewhere](ClickHouse/ClickHouse#27705). This seems to be caused by breaking behavior in clang 13 which escalates unused variable from a warning in prior versions to an error.

The solution implemented here:
I add an additional cflags `-Wno-unused-but-set-variable` for apple platforms. 

Tested on macOS 13.3.1 with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
@raymondchua
Copy link

raymondchua commented May 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants