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

Initial Apple M1 support #18617

Merged
merged 1 commit into from
Nov 19, 2021
Merged

Initial Apple M1 support #18617

merged 1 commit into from
Nov 19, 2021

Conversation

ThomasDebrunner
Copy link
Member

@ThomasDebrunner ThomasDebrunner commented Nov 10, 2021

This PR adds initial support native compilation on apple silicon (M1) macos.

Describe problem solved by this pull request
Apple is moving to their own arm64 based processor architecture. While at the moment one can run PX4 sitl perfectly fine in x86 emulation on those machines, having it running natively is more desirable.

Describe your solution
Two things are addressed:

  • Submodule for jmavsim set to Native macOS ARM jogl binaries for M1 support jMAVSim#132. This version of jmavsim contains native OpenGL binaries for arm64, this makes it run on M1

  • The gyro_fft module uses CMSIS. CMSIS has a lot of functions with inline arm 32-bit assembly. When compiling on x86 or any non-dsp and non-neon arm processor (such as the M1), none of these functions ever get used. This is what allows (presumably) to compile on x86. On M1, the story is the same. Also none of those functions ever get used, but since we are compiling to an arm target, the apple compiler somehow still issues warnings for the inline arm assembly using 32-bit registers instead of native 64-bit registers. Since we treat those warnings as errors, compilation fails. Disabling this specific warning on apple silicon fixes the issue. This seems to be an apple-clang thing. GCC on linux arm64 doesn't seem to have this issue.

Describe possible alternatives
It would be better if all those functions would be behind preprocessor statements to actually not be in the code for targets that do not support them, especially also x86. But since we just use CMSIS code, we should not alter those files

Test data / coverage
SITL runs in jmavsim, after installing the environment natively with homebrew from PX4/homebrew-px4#80

Additional context

To note:

  • gazebo is not working yet
  • When compiling for nuttx, we invoke the arm compiler binaries installed with the toolchain. Those compiler binaries are x86 and run therefore in rosetta. This is fine though and works out of the box.

Additional testing would be welcome!

@dlech
Copy link
Contributor

dlech commented Nov 11, 2021

I was able to get jmavsim to run using this. (this is all quite new too me, so don't think I can help with much more than just a compile test).

I did make some progress with fixing dylib errors like this on the gazebo build:

dyld[98448]: Library not loaded: @rpath/libgazebo.11.dylib
  Referenced from: /opt/homebrew/Cellar/gazebo11/11.9.0/bin/gzserver-11.9.0
  Reason: tried: '/usr/local/lib/libgazebo.11.dylib' (no such file), '/usr/lib/libgazebo.11.dylib' (no such file)

by running:

install_name_tool -add_rpath /opt/homebrew/lib /opt/homebrew/Cellar/gazebo11/11.9.0/bin/gzclient-11.9.0
install_name_tool -add_rpath /opt/homebrew/lib /opt/homebrew/Cellar/gazebo11/11.9.0/bin/gzserver-11.9.0

I'm still getting

dyld[1690]: symbol not found in flat namespace '_rmtMetal_usGetTime'

but google has 0 results for "_rmtMetal_usGetTime", so I'm not sure what that is.

@dlech
Copy link
Contributor

dlech commented Nov 11, 2021

but google has 0 results for "_rmtMetal_usGetTime", so I'm not sure what that is.

found something: Celtoys/Remotery#139

@dagar
Copy link
Member

dagar commented Nov 16, 2021

Merge the cmake change while you settle jmavsim?

…rning is caused by unused functions only. As with compiling for x86, the functions containing assembly never get used, but since the apple silicon is also an ARM target, they trigger a warning.
@ThomasDebrunner ThomasDebrunner marked this pull request as ready for review November 19, 2021 08:04
@ThomasDebrunner
Copy link
Member Author

@dagar Removed the jmavsim submodule update, just the cmake addition left. Ready for merge IMO

@dagar dagar merged commit fb54324 into master Nov 19, 2021
@dagar dagar deleted the m1-assembly-warnings branch November 19, 2021 14:14
@dlech
Copy link
Contributor

dlech commented Dec 1, 2021

FYI, I got gazebo working with Homebrew/homebrew-core#90205 and osrf/homebrew-simulation#1698.

@ThomasDebrunner
Copy link
Member Author

@dlech nice!

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

Successfully merging this pull request may close these issues.

3 participants