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

Fix Build Process for Apple M3 Processors #605

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

cmaloney111
Copy link

Description:

This PR introduces changes to the CMakeLists.txt file to support compilation for the Apple M3 architecture. Initially, the following errors were encountered due to incorrect or unsupported compiler flags for the M3 processor.

Errors Encountered:

  1. -march
    During the build, the following error was thrown:

    f951: Error: unknown value 'apple-m3' for '-march'
    f951: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8.9-a armv8-r armv9-a armv9.1-a armv9.2-a armv9.3-a armv9.4-a native
    f951: note: did you mean '-mcpu=apple-m3'?
    

    This error occurred because the compiler does not recognize -march=apple-m3, but rather, it suggests using -mcpu=apple-m3.

  2. -mtune
    After correcting the -march flag, the following error was encountered:

    -mtune =  error: unsupported argument 'apple-m3' to option '-mtune='
    

    This error occurred because the -mtune flag does not support apple-m3 as a valid argument.

Changes Made:

To address these issues, the following changes were made to the CMakeLists.txt file:

  1. Processor Detection for Apple M3:
    A check was added for detecting the Apple M3 architecture using sysctl -n machdep.cpu.brand_string to get the processer name. If the brand string contains Apple M3, the code changes certain compiler flags
  2. Corrected Compiler Flags:
    • Only in the case when an Apple M3 processor is detected, the two compiler flags are changed:
    • For -march: The incorrect -march=native was replaced with -mcpu=native, which is the correct flag to target Apple M3 processors.
    • For -mtune: The -mtune=native flag was removed, as it is not supported.

@stgeke
Copy link
Collaborator

stgeke commented Nov 18, 2024

I don't think we need an special handling for Apple M3.

Somehow the following replacement was not performed

if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
  string(REPLACE "-march" "-mcpu" OCCA_CXXFLAGS ${OCCA_CXXFLAGS})
  string(REPLACE "-march" "-mcpu" CMAKE_Fortran_FLAGS_RELWITHDEBINFO ${CMAKE_Fortran_FLAGS_RELWITHDEBINFO})
  string(REPLACE "-march" "-mcpu" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO})
  string(REPLACE "-march" "-mcpu" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
endif()

Can you please check why.
In general I suggest to remove -mtune. It's not needed.

@cmaloney111
Copy link
Author

Okay, I removed the -mtune flag and the special handling for Apple M3. The replacement you mentioned was performed. I apologize as I should not have included that part in my pull request as it occured when I was testing the master branch and not this branch. Only the second error (with -mtune) is relevant for this branch.

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.

2 participants