Nek5000 / nekRS

our next generation fast and scalable CFD code
https://nek5000.mcs.anl.gov/
Other
290 stars 76 forks source link

Fix Build Process for Apple M3 Processors #605

Open cmaloney111 opened 1 week ago

cmaloney111 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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.