Skip to content

Commit

Permalink
Merge pull request #274 from GEOS-ESM/feature/mathomp4/fixes-for-m1
Browse files Browse the repository at this point in the history
Changes needed to run GEOS on M1
  • Loading branch information
mathomp4 authored Jun 15, 2022
2 parents 17bf513 + 3cb1a8c commit c5fa3e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed

- Update M1 flags on GNU from GEOS testing
- Also add M1-Rosetta2 flags from @climbfuji

### Fixed
### Removed
### Added
Expand Down
35 changes: 25 additions & 10 deletions compiler/flags/GNU_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set (FOPT1 "-O1")
set (FOPT2 "-O2")
set (FOPT3 "-O3")
set (FOPT4 "-O3")
set (FOPTFAST "-Ofast")
set (DEBINFO "-g")

set (FPE0 "")
Expand Down Expand Up @@ -109,24 +110,28 @@ set (NO_ALIAS "")

set (NO_RANGE_CHECK "-fno-range-check")

cmake_host_system_information(RESULT proc_decription QUERY PROCESSOR_DESCRIPTION)
cmake_host_system_information(RESULT proc_description QUERY PROCESSOR_DESCRIPTION)

if ( ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL aarch64 )
set (GNU_TARGET_ARCH "armv8.2-a+crypto+crc+fp16+rcpc+dotprod")
set (GNU_NATIVE_ARCH ${GNU_TARGET_ARCH})
elseif ( ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL arm64 )
# For now the only arm64 we have tested is Apple M1. This
# might need to be revisited for M1 Max/Ultra and M2+.
# Also, fail if a Linux Arm64
if (APPLE)
elseif (${proc_description} MATCHES "Apple M1")
if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64")
# Testing show GEOS fails with -march=native on M1 in native mode
set (GNU_TARGET_ARCH "armv8-a")
set (GNU_NATIVE_ARCH ${GNU_TARGET_ARCH})
elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
# Rosetta2 flags per tests by @climbfuji
set (GNU_TARGET_ARCH "westmere")
set (GNU_NATIVE_ARCH "native")
set (PREFER_AVX128 "-mprefer-avx128")
set (NO_FMA "-mno-fma")
endif ()
elseif (${proc_decription} MATCHES "EPYC")
elseif (${proc_description} MATCHES "EPYC")
set (GNU_TARGET_ARCH "znver2")
set (GNU_NATIVE_ARCH "native")
set (NO_FMA "-mno-fma")
elseif (${proc_decription} MATCHES "Intel")
elseif (${proc_description} MATCHES "Intel")
set (GNU_TARGET_ARCH "westmere")
set (GNU_NATIVE_ARCH "native")
set (PREFER_AVX128 "-mprefer-avx128")
Expand Down Expand Up @@ -177,8 +182,18 @@ set (GEOS_Fortran_Vect_FPE_Flags ${GEOS_Fortran_Release_FPE_Flags})
# NOTE2: This uses -march=native so compile on your target architecture!!!

# Options per Jerry DeLisle on GCC Fortran List
set (GEOS_Fortran_Aggressive_Flags "${FOPT2} -march=${GNU_NATIVE_ARCH} -ffast-math -ftree-vectorize -funroll-loops --param max-unroll-times=4 ${PREFER_AVX128} ${NO_FMA}")
set (GEOS_Fortran_Aggressive_FPE_Flags "${DEBINFO} ${TRACEBACK} ${MISMATCH} ${ALLOW_BOZ}")
if (${proc_description} MATCHES "Apple M1" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64")
# For now the only arm64 we have tested is Apple M1. This
# might need to be revisited for M1 Max/Ultra and M2+.
# Testing has not yet found any aggressive flags better than
# the release so for now, use those
set (GEOS_Fortran_Aggressive_Flags "${GEOS_Fortran_Release_Flags}")
set (GEOS_Fortran_Aggressive_FPE_Flags "${GEOS_Fortran_Release_FPE_Flags}")
else ()
set (GEOS_Fortran_Aggressive_Flags "${FOPT2} -march=${GNU_NATIVE_ARCH} -ffast-math -ftree-vectorize -funroll-loops --param max-unroll-times=4 ${PREFER_AVX128} ${NO_FMA}")
set (GEOS_Fortran_Aggressive_FPE_Flags "${DEBINFO} ${TRACEBACK} ${MISMATCH} ${ALLOW_BOZ}")
endif ()


# Options per Jerry DeLisle on GCC Fortran List with SVML (does not seem to help)
#set (GEOS_Fortran_Aggressive_Flags "-O2 -march=native -ffast-math -ftree-vectorize -funroll-loops --param max-unroll-times=4 ${PREFER_AVX128} -mno-fma -mveclibabi=svml")
Expand Down
6 changes: 3 additions & 3 deletions compiler/flags/Intel_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ set (USE_SVML "-fimf-use-svml=true")

set (NO_RANGE_CHECK "")

cmake_host_system_information(RESULT proc_decription QUERY PROCESSOR_DESCRIPTION)
if (${proc_decription} MATCHES "EPYC")
cmake_host_system_information(RESULT proc_description QUERY PROCESSOR_DESCRIPTION)
if (${proc_description} MATCHES "EPYC")
set (COREAVX2_FLAG "-march=core-avx2")
elseif (${proc_decription} MATCHES "Intel")
elseif (${proc_description} MATCHES "Intel")
set (COREAVX2_FLAG "-march=core-avx2")
# Previous versions of GEOS used this flag, which was not portable
# for AMD. Keeping here for a few versions for historical purposes.
Expand Down

0 comments on commit c5fa3e6

Please sign in to comment.