Skip to content

Commit

Permalink
[cmake] Improve logic when MKL is detected as LAPACK distribution
Browse files Browse the repository at this point in the history
- If no BLA_VENDOR specified, link against single dynamic library
  and set MKL_INTERFACE_LAYER to GNU,LP64 at runtime
  • Loading branch information
Wentzell committed Dec 5, 2023
1 parent e6711f8 commit 1f5e358
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions c++/nda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ target_link_libraries(${PROJECT_NAME}_c PUBLIC OpenMP::OpenMP_CXX)

message(STATUS "-------- Lapack detection -------------")

find_package(LAPACK REQUIRED)
if(LAPACK_LIBRARIES MATCHES "libmkl" AND NOT LAPACK_LIBRARIES MATCHES "libmkl_rt")
message(STATUS "Found MKL: Making sure to use single dynamic library")
find_package(LAPACK QUIET REQUIRED)
if(LAPACK_LIBRARIES MATCHES "libmkl" AND BLA_VENDOR STREQUAL "All")
message(STATUS "Detected MKL with no BLA_VENDOR set, defaulting to single dynamic library 'libmkl_rt'")
set(BLA_VENDOR Intel10_64_dyn)
find_package(LAPACK REQUIRED)
endif()
if(LAPACK_LIBRARIES MATCHES "Accelerate.framework")
message(STATUS "Can't build with Accelerate Framework on OSX, trying to find OpenBLAS instead.")
elseif(LAPACK_LIBRARIES MATCHES "Accelerate.framework")
message(STATUS "Can't build with Accelerate Framework on OSX, trying to find OpenBLAS instead...")
set(BLA_VENDOR OpenBLAS) # Accelerate Framework has issue in zdot
set(LAPACK_ROOT "${LAPACK_ROOT};$ENV{LAPACK_ROOT};/opt/homebrew/opt/openblas;/usr/local/opt/openblas")
find_package(LAPACK REQUIRED)
endif()
find_package(LAPACK REQUIRED)

# Create an interface target
add_library(blas_lapack INTERFACE)
Expand All @@ -70,6 +68,9 @@ if(LAPACK_LIBRARIES MATCHES "libmkl")
target_include_directories(${PROJECT_NAME}_c PUBLIC $ENV{MKLROOT}/include)
endif()
target_compile_definitions(${PROJECT_NAME}_c PUBLIC NDA_USE_MKL)
if(LAPACK_LIBRARIES MATCHES "libmkl_rt")
target_compile_definitions(${PROJECT_NAME}_c PRIVATE NDA_USE_MKL_RT)
endif()
endif()

# Link against interface target and export
Expand Down
2 changes: 2 additions & 0 deletions c++/nda/blas/interface/cxx_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ using namespace std::string_literals;
#ifdef NDA_USE_MKL
#include <mkl.h>
namespace nda::blas {
#ifdef NDA_USE_MKL_RT
static int const mkl_interface_layer = mkl_set_interface_layer(MKL_INTERFACE_LP64 + MKL_INTERFACE_GNU);
#endif
inline auto *mklcplx(nda::dcomplex *c) { return reinterpret_cast<MKL_Complex16 *>(c); } // NOLINT
inline auto *mklcplx(nda::dcomplex const *c) { return reinterpret_cast<const MKL_Complex16 *>(c); } // NOLINT
inline auto *mklcplx(nda::dcomplex **c) { return reinterpret_cast<MKL_Complex16 **>(c); } // NOLINT
Expand Down

0 comments on commit 1f5e358

Please sign in to comment.