Skip to content

Commit

Permalink
FindLAPACK:oneAPI: use vendor MKLConfig.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Aug 22, 2023
1 parent 1b8a394 commit 96ed58a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 122 deletions.
145 changes: 26 additions & 119 deletions cmake/FindLAPACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ COMPONENTS default to Netlib LAPACK / LapackE, otherwise:
Intel MKL -- sequential by default, or add TBB or MPI as well
``MKL64``
MKL only: 64-bit integers (default is 32-bit integers)
``OpenMP``
Intel MPI with OpenMP threading addition to MKL
``TBB``
Intel MPI + TBB for MKL
``AOCL``
Expand Down Expand Up @@ -309,52 +307,40 @@ endfunction(aocl_libs)
#===============================

function(find_mkl_libs)
# https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor
# https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-linux/2023-2/cmake-config-for-onemkl.html

set(_mkl_libs ${ARGV})
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
CMAKE_Fortran_COMPILER_ID STREQUAL "GNU"
)
list(INSERT _mkl_libs 0 mkl_gf_${_mkl_bitflag}lp64)
else()
if(WIN32 AND BUILD_SHARED_LIBS)
list(INSERT _mkl_libs 0 mkl_intel_${_mkl_bitflag}lp64_dll)
else()
list(INSERT _mkl_libs 0 mkl_intel_${_mkl_bitflag}lp64)
endif()
set(MKL_INTERFACE "lp64")
if(MKL64 IN_LIST LAPACK_FIND_COMPONENTS)
string(PREPEND MKL_INTERFACE "i")
endif()

foreach(s ${_mkl_libs})
find_library(LAPACK_${s}_LIBRARY
NAMES ${s}
PATHS ${MKLROOT}/lib ${MKLROOT}/lib/intel64 ${oneapi_libdir}
NO_DEFAULT_PATH
DOC "Intel MKL ${s} library"
)
# ${MKLROOT}/[lib[/intel64]]: general MKL libraries
# oneapi_libdir: openmp library
if(LAPACK95 IN_LIST LAPACK_FIND_COMPONENTS)
set(ENABLE_BLAS95 true)
set(ENABLE_LAPACK95 true)
endif()

if(NOT LAPACK_${s}_LIBRARY)
return()
endif()
# MKL_THREADING default: "intel_thread" which is Intel OpenMP
if(TBB IN_LIST LAPACK_FIND_COMPONENTS)
set(MKL_THREADING "tbb_thread")
endif()

# default: dynamic
if(STATIC IN_LIST LAPACK_FIND_COMPONENTS)
set(MKL_LINK "static")
endif()

list(APPEND LAPACK_LIBRARY ${LAPACK_${s}_LIBRARY})
endforeach()
find_package(MKL CONFIG HINTS $ENV{MKLROOT})

find_path(LAPACK_INCLUDE_DIR
NAMES mkl_lapack.h
HINTS ${MKLROOT}
PATH_SUFFIXES include
NO_DEFAULT_PATH
DOC "Intel MKL header"
)
if(MKL_FOUND)
set(LAPACK_MKL_FOUND true PARENT_SCOPE)

if(NOT LAPACK_INCLUDE_DIR)
return()
foreach(c IN ITEMS TBB LAPACK95 MKL64)
if(${c} IN_LIST LAPACK_FIND_COMPONENTS)
set(LAPACK_${c}_FOUND true PARENT_SCOPE)
endif()
endforeach()
endif()

set(LAPACK_LIBRARY ${LAPACK_LIBRARY} PARENT_SCOPE)

endfunction(find_mkl_libs)

# ========== main program
Expand Down Expand Up @@ -384,87 +370,8 @@ if(STATIC IN_LIST LAPACK_FIND_COMPONENTS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()

# ==== generic MKL variables ====

if(MKL IN_LIST LAPACK_FIND_COMPONENTS OR MKL64 IN_LIST LAPACK_FIND_COMPONENTS)
# we have to sanitize MKLROOT if it has Windows backslashes (\) otherwise it will break at build time
# double-quotes are necessary per CMake to_cmake_path docs.
file(TO_CMAKE_PATH "$ENV{MKLROOT}" MKLROOT)

file(TO_CMAKE_PATH "$ENV{ONEAPI_ROOT}" ONEAPI_ROOT)
# oneapi_libdir is where iomp5 is located
set(oneapi_libdir ${ONEAPI_ROOT}/compiler/latest/)
if(WIN32)
string(APPEND oneapi_libdir "windows/compiler/lib/intel64_win")
elseif(APPLE)
string(APPEND oneapi_libdir "mac/compiler/lib")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
string(APPEND oneapi_libdir "linux/compiler/lib/intel64_lin")
endif()

if(MKL64 IN_LIST LAPACK_FIND_COMPONENTS)
set(_mkl_bitflag i)
else()
set(_mkl_bitflag)
endif()

set(_mkl_libs)
if(LAPACK95 IN_LIST LAPACK_FIND_COMPONENTS)
find_mkl_libs(mkl_blas95_${_mkl_bitflag}lp64 mkl_lapack95_${_mkl_bitflag}lp64)
if(LAPACK_LIBRARY)
set(LAPACK95_LIBRARY ${LAPACK_LIBRARY})
set(LAPACK_LIBRARY)
set(LAPACK95_INCLUDE_DIR ${LAPACK_INCLUDE_DIR})
set(LAPACK_LAPACK95_FOUND true)
endif()
endif()

set(_tbb)
if(TBB IN_LIST LAPACK_FIND_COMPONENTS)
list(APPEND _mkl_libs mkl_tbb_thread mkl_core)
set(_tbb tbb stdc++)
elseif(OpenMP IN_LIST LAPACK_FIND_COMPONENTS)
if(WIN32)
set(_mp libiomp5md)
else()
set(_mp iomp5)
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
list(APPEND _mkl_libs mkl_intel_thread_dll mkl_core_dll ${_mp})
else()
list(APPEND _mkl_libs mkl_intel_thread mkl_core ${_mp})
endif()
else()
if(WIN32 AND BUILD_SHARED_LIBS)
list(APPEND _mkl_libs mkl_sequential_dll mkl_core_dll)
else()
list(APPEND _mkl_libs mkl_sequential mkl_core)
endif()
endif()

find_mkl_libs(${_mkl_libs})

if(LAPACK_LIBRARY)

if(NOT WIN32)
list(APPEND LAPACK_LIBRARY ${_tbb} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} m)
endif()

set(LAPACK_MKL_FOUND true)

if(MKL64 IN_LIST LAPACK_FIND_COMPONENTS)
set(LAPACK_MKL64_FOUND true)
endif()

if(OpenMP IN_LIST LAPACK_FIND_COMPONENTS)
set(LAPACK_OpenMP_FOUND true)
endif()

if(TBB IN_LIST LAPACK_FIND_COMPONENTS)
set(LAPACK_TBB_FOUND true)
endif()
endif()

find_mkl_libs()
elseif(Atlas IN_LIST LAPACK_FIND_COMPONENTS)
atlas_libs()
elseif(Netlib IN_LIST LAPACK_FIND_COMPONENTS)
Expand Down
3 changes: 0 additions & 3 deletions cmake/lapack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ if(MKL IN_LIST LAPACK_VENDOR)
if(intsize64)
list(APPEND LAPACK_VENDOR MKL64)
endif()
if(openmp)
list(APPEND LAPACK_VENDOR OpenMP)
endif()
endif()

if(find_static)
Expand Down

0 comments on commit 96ed58a

Please sign in to comment.