diff --git a/CMakeLists.txt b/CMakeLists.txt index ff30a5511ff51c059f5b5342863df120f0be271e..856ff87c616dc7e5ba9b403cd6b4a647d5328d32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,11 +25,11 @@ SOFTWARE. cmake_minimum_required(VERSION 3.12) -set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.29) +set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.30) include("./cmake/HandlePolicies.cmake" NO_POLICY_SCOPE) -project(AccelerateLAPACKE VERSION 1.0.0 LANGUAGES C) +project(AccelerateLAPACKE VERSION 1.1.0 LANGUAGES C) include(FetchContent) @@ -40,14 +40,69 @@ if (NOT IS_TOP_LEVEL) endif () if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") - # Mac OS X 13.3 Ventura - if (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 22.4) + # The available binary Accelerate version is determined by the MacOS system + message(STATUS "The Darwin kernel version is: ${CMAKE_HOST_SYSTEM_VERSION}") + + if (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 24.0) + # Mac OS X 15.0 Sequoia or later + message(STATUS "The MacOS version is: >=15.0") + set(MINIMUM_MACOS_SDK_VERSION 15.0) + set(ACCELERATE_NEW_LAPACK_VERSION 3.11.0) + elseif (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 22.4) + # Mac OS X 13.3 Ventura or later + message(STATUS "The MacOS version is: >=13.3,<15.0") + set(MINIMUM_MACOS_SDK_VERSION 13.3) + set(VALID_MACOS_SDK_VERSIONS 14.5 14.4 14.2 14.0 13.3) set(ACCELERATE_NEW_LAPACK_VERSION 3.9.1) else () - message(FATAL_ERROR "You need at least Mac OS X 13.3 Ventura for Accelerate with BLAS/LAPACK v3.9.1!") + message(FATAL_ERROR "You need at least MacOS 13.3 Ventura for Accelerate with BLAS/LAPACK v3.9.1!") + endif () + + message(STATUS "The BLAS/LAPACK version provided by the Accelerate framework is: ${ACCELERATE_NEW_LAPACK_VERSION}") +endif () + +string(REGEX MATCH [=[SDKs/MacOSX(.*)\.sdk$]=] _REGEX_DUMMY "${CMAKE_OSX_SYSROOT}") +set(DEFAULT_MACOS_SDK_VERSION "${CMAKE_MATCH_1}") + +# The text-based .dylib stubs describing the Accelerate framework are provided +# by the MacOS SDK, which has to match the MacOS system. Otherwise, there might +# be newer symbols in the text-based .dylib stubs that are not provided by the +# Accelerate binary, leading to linking errors. +if (NOT DEFINED VALID_MACOS_SDK_VERSIONS) + # MacOS system supports the latest iteration of the new Accelerate + # BLAS/LAPACK. Use the default SDK, if it's recent enough. + if (DEFAULT_MACOS_SDK_VERSION VERSION_LESS MINIMUM_MACOS_SDK_VERSION) + message(STATUS "The MacOS SDK is: ${CMAKE_OSX_SYSROOT}") + message(STATUS "The minimum compatible MacOS SDK version is: ${MINIMUM_MACOS_SDK_VERSION}") + message(FATAL_ERROR "Please install a more recent XCode for a compatible MacOS SDK.") + endif () +elseif (NOT DEFAULT_MACOS_SDK_VERSION IN_LIST VALID_MACOS_SDK_VERSIONS) + # MacOS system supports one of the past iterations of the new Accelerate + # BLAS/LAPACK. If the latest possible XCode is installed is installed on + # this older system, there might be a mismatch between the SDK and the + # system binary. Find a matching SDK from the Command Line Tools instead. + foreach (_MACOS_SDK_VERSION IN LISTS VALID_MACOS_SDK_VERSIONS) + find_path(VALID_MACOS_SDK NAMES "MacOSX${_MACOS_SDK_VERSION}.sdk" HINTS "/Library/Developer/CommandLineTools/SDKs" NO_CACHE) + + if (VALID_MACOS_SDK) + set(VALID_MACOS_SDK "${VALID_MACOS_SDK}/MacOSX${_MACOS_SDK_VERSION}.sdk") + break () + endif () + endforeach () + + if (VALID_MACOS_SDK) + set(CMAKE_OSX_SYSROOT "${VALID_MACOS_SDK}" CACHE PATH "" FORCE) + else () + message(STATUS "The MacOS SDK is: ${CMAKE_OSX_SYSROOT}") + message(STATUS "The compatible MacOS SDK versions are: ${VALID_MACOS_SDK_VERSIONS}") + message(FATAL_ERROR "Couldn't find a compatible MacOS SDK. Please install compatible XCode Command Line Tools.") endif () endif () +message(STATUS "The MacOS SDK is: ${CMAKE_OSX_SYSROOT}") + +set(ENV{CMAKE_FRAMEWORK_PATH} "${CMAKE_OSX_SYSROOT}/System/Library/Frameworks") + set(BLA_VENDOR "Apple") find_package(LAPACK MODULE) diff --git a/README.md b/README.md index b509127f4de3978c06f3ee64103116351f67ca40..79ceee228559bbd816bcdbe5c3f2a9d157f24286 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,24 @@ SOFTWARE. # Accelerate LAPACKE # -Since Mac OS X 13.3 Ventura, Apple's Accelerate framework comes with a new +Since MacOS 13.3 Ventura, Apple's Accelerate framework comes with a new [BLAS/LAPACK interface](https://developer.apple.com/documentation/accelerate/blas) compatible with [Reference LAPACK -v3.9.1](https://github.com/Reference-LAPACK/lapack/tree/v3.9.1). It also +v3.9.1](https://github.com/Reference-LAPACK/lapack/releases/tag/v3.9.1). It also provides an ILP64 interface. On Apple Silicon M-processors, it utilises the [proprietary AMX co-processor](https://github.com/corsix/amx), which makes it especially interesting. Unfortunately, it comes without the LAPACKE C-interface library. +**Update**: With the release of MacOS 15.0 Sequoia, Apple updated the Accelerate +framework to be compatible with [Reference LAPACK +v3.11.0](https://github.com/Reference-LAPACK/lapack/releases/tag/v3.11.0). +Unfortunately, there is no mention of it in the [MacOS 15.0 Sequoia Release +Notes](), but the note in the [Accelerate BLAS +docs](https://developer.apple.com/documentation/accelerate/blas) has been +updated accordingly. + These new interfaces are hidden behind the preprocessor defines `ACCELERATE_NEW_LAPACK` and `ACCELERATE_LAPACK_ILP64` and they only work, if you include the Accelerate C/C++ headers. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de151172d933a9bf8c3313fe4c2ec14a42894dbd..1dfaa72293717c9246e4ab3b867c67665ed89cb8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,14 +72,14 @@ set(CBLAS OFF CACHE BOOL "") set(LAPACKE ON CACHE BOOL "") # Add the $NEWLAPACK symbols to the linker flags used in try_compile() -set(CMAKE_EXE_LINKER_FLAGS "-Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias") +set(CMAKE_EXE_LINKER_FLAGS "-framework Accelerate -Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias") if (BUILD_INDEX64) # Add the $NEWLAPACK$ILP64 symbols to the linker flags used for shared libraries - set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack-ilp64.alias") + set(CMAKE_SHARED_LINKER_FLAGS "-framework Accelerate -Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack-ilp64.alias") else () # Add the $NEWLAPACK symbols to the linker flags used for shared libraries - set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias") + set(CMAKE_SHARED_LINKER_FLAGS "-framework Accelerate -Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias") endif () FetchContent_Declare(