Skip to content

Commit

Permalink
Refactor MKL auto-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed May 30, 2024
1 parent 672a700 commit 22b3f18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 21 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,29 @@ option(DLAF_BUILD_DOC "Build documentation" OFF)
option(DLAF_WITH_PRECOMPILED_HEADERS "Use precompiled headers." OFF)
option(DLAF_WITH_SCALAPACK "Build ScaLAPACK-like C API (requires ScaLAPACK)" OFF)

unset(DLAF_WITH_MKL_TRY_COMPILE CACHE)
try_compile(
DLAF_WITH_MKL_TRY_COMPILE "${PROJECT_BINARY_DIR}/cmake/tests"
"${PROJECT_SOURCE_DIR}/cmake/tests/mkl_set_num_threads.cpp"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${LAPACK_INCLUDE_DIR}"
LINK_LIBRARIES ${LAPACK_LIBRARY}
)
if(DLAF_WITH_MKL_TRY_COMPILE)
message(STATUS "Intel MKL detection: Found")
option(DLAF_WITH_MKL "Enable MKL as provider for BLAS and LAPACK" "${DLAF_WITH_MKL_TRY_COMPILE}")
if(DEFINED CACHE{DLAF_WITH_MKL})
if(DLAF_WITH_MKL)
message(STATUS "Intel MKL support: Enabled by user")
else()
message(STATUS "Intel MKL support: Disabled by user")
endif()
set(DLAF_WITH_MKL_INTERNAL ${DLAF_WITH_MKL} CACHE BOOL "" FORCE)
else()
message(STATUS "Intel MKL detection: Not found")
unset(DLAF_WITH_MKL_TRY_COMPILE CACHE)
try_compile(
DLAF_WITH_MKL_TRY_COMPILE "${PROJECT_BINARY_DIR}/cmake/tests"
"${PROJECT_SOURCE_DIR}/cmake/tests/mkl_set_num_threads.cpp"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${LAPACK_INCLUDE_DIR}"
LINK_LIBRARIES ${LAPACK_LIBRARY}
)
if(DLAF_WITH_MKL_TRY_COMPILE)
message(STATUS "Intel MKL support: Found")
else()
message(STATUS "Intel MKL support: Not found")
endif()
set(DLAF_WITH_MKL_INTERNAL ${DLAF_WITH_MKL_TRY_COMPILE} CACHE BOOL "" FORCE)
endif()
option(DLAF_WITH_MKL "Enable MKL as provider for BLAS and LAPACK" "${DLAF_WITH_MKL_TRY_COMPILE}")

if(DLAF_WITH_MKL)
# When using MKL there is no need to set the number of threads with
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ target_compile_definitions(
$<$<BOOL:${DLAF_ASSERT_MODERATE_ENABLE}>:DLAF_ASSERT_MODERATE_ENABLE>
$<$<BOOL:${DLAF_ASSERT_HEAVY_ENABLE}>:DLAF_ASSERT_HEAVY_ENABLE>
DLAF_FUNCTION_NAME=$<IF:$<BOOL:is_pretty_function_available>,__PRETTY_FUNCTION__,__func__>
$<$<BOOL:${DLAF_WITH_MKL}>:DLAF_WITH_MKL>
$<$<BOOL:${DLAF_WITH_MKL_INTERNAL}>:DLAF_WITH_MKL>
$<$<BOOL:${DLAF_WITH_OPENMP}>:DLAF_WITH_OPENMP>
$<$<BOOL:${DLAF_WITH_GPU}>:DLAF_WITH_GPU>
$<$<BOOL:${DLAF_WITH_CUDA}>:DLAF_WITH_CUDA>
Expand Down

0 comments on commit 22b3f18

Please sign in to comment.