Skip to content

Commit

Permalink
Remove most special handling of MKL in CMake configuration (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg authored May 31, 2024
1 parent 780d344 commit 62718b9
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 420 deletions.
1 change: 0 additions & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ CMake option | Values | Note
`blaspp_DIR` | CMAKE:PATH | Location of the blaspp CMake-config file
`lapackpp_DIR` | CMAKE:PATH | Location of the lapackpp CMake-config file
`DLAF_WITH_MKL` | `{ON,OFF}` (default: `OFF`) | if blaspp/lapackpp is built with oneMKL
`DLAF_WITH_LEGACY_MKL` | `{ON,OFF}` (default: `OFF`) | if blaspp/lapackpp is built with MKL (deprecated)
`DLAF_WITH_SCALAPACK` | `{ON,OFF}` (default: `OFF`) | Enable ScaLAPACK-like API.
`MKL_ROOT` | CMAKE:PATH | Location of the MKL library
`DLAF_ASSERT_ENABLE` | `{ON,OFF}` (default: `ON`) | enable/disable cheap assertions
Expand Down
82 changes: 25 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ endif()

option(BUILD_SHARED_LIBS "Build shared libraries." ON)
option(DLAF_WITH_OPENMP "${DLAF_WITH_OPENMP_DESCRIPTION}" ${DLAF_WITH_OPENMP_DEFAULT})
option(DLAF_WITH_MKL "Enable oneMKL as provider for BLAS and LAPACK" OFF)
option(DLAF_WITH_MKL_LEGACY "Enable MKL as provider for BLAS and LAPACK" OFF)
option(DLAF_WITH_CUDA "Enable CUDA support" OFF)
option(DLAF_WITH_HIP "Enable HIP support" OFF)
cmake_dependent_option(
Expand All @@ -55,11 +53,30 @@ 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)

if(DLAF_WITH_MKL AND DLAF_WITH_MKL_LEGACY)
message(SEND_ERROR "DLAF_WITH_MKL and DLAF_WITH_MKL_LEGACY are mutually exclusive.")
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()
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()

if(DLAF_WITH_MKL OR DLAF_WITH_MKL_LEGACY)
if(DLAF_WITH_MKL)
# When using MKL there is no need to set the number of threads with
# omp_set_num_threads; it's sufficient to use MKL's own mechanisms.
set(DLAF_WITH_OPENMP OFF CACHE BOOL "${DLAF_WITH_OPENMP_DESCRIPTION}" FORCE)
Expand Down Expand Up @@ -140,58 +157,9 @@ if(DLAF_WITH_OPENMP)
find_package(OpenMP REQUIRED)
endif()

# ----- LAPACK/SCALAPACK
if(DLAF_WITH_MKL) # oneMKL
set(MKL_INTERFACE "lp64" CACHE STRING "")
set(MKL_THREADING "sequential" CACHE STRING "")
set(MKL_MPI "mpich" CACHE STRING "")

find_package(MKL CONFIG REQUIRED)

set(LAPACK_FOUND TRUE)
add_library(DLAF::LAPACK INTERFACE IMPORTED GLOBAL)
target_link_libraries(DLAF::LAPACK INTERFACE MKL::MKL)

if(DLAF_WITH_SCALAPACK)
set(SCALAPACK_FOUND TRUE)
add_library(DLAF::SCALAPACK INTERFACE IMPORTED GLOBAL)
endif()
elseif(DLAF_WITH_MKL_LEGACY) # MKL (deprecated)
find_package(MKL MODULE REQUIRED)

set(MKL_LAPACK_TARGET "mkl::mkl_intel_32bit_seq_dyn"
CACHE STRING "MKL LAPACK target (see FindMKL for details)"
)

# Note:
# If specified targets are found, "standardize" them

if(TARGET ${MKL_LAPACK_TARGET})
set(LAPACK_FOUND TRUE)
add_library(DLAF::LAPACK INTERFACE IMPORTED GLOBAL)
target_link_libraries(DLAF::LAPACK INTERFACE ${MKL_LAPACK_TARGET})
else()
message(FATAL_ERROR "${MKL_LAPACK_TARGET} as LAPACK target has not been found")
endif()

if(DLAF_WITH_SCALAPACK)
set(MKL_SCALAPACK_TARGET "mkl::scalapack_intel_32bit_seq_dyn"
CACHE STRING "MKL ScaLAPACK target (see FindMKL for details)"
)

if(TARGET ${MKL_SCALAPACK_TARGET})
set(SCALAPACK_FOUND TRUE)
add_library(DLAF::SCALAPACK INTERFACE IMPORTED GLOBAL)
target_link_libraries(DLAF::SCALAPACK INTERFACE ${MKL_SCALAPACK_TARGET})
else()
message(FATAL_ERROR "${MKL_SCALAPACK_TARGET} as ScaLAPACK target has not been found")
endif()
endif()
else()
find_package(LAPACK REQUIRED)
if(DLAF_WITH_SCALAPACK)
find_package(SCALAPACK REQUIRED)
endif()
find_package(LAPACK REQUIRED)
if(DLAF_WITH_SCALAPACK)
find_package(SCALAPACK REQUIRED)
endif()

# ----- pika
Expand Down
2 changes: 1 addition & 1 deletion ci/common-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ stages:
reports:
dotenv: build.env
variables:
SPACK_SHA: dcc4423a9d0219a26ceeb52e329ed956e41f4d2c
SPACK_SHA: 1184de8352281ce1b34a8f3f6b54d7fadc2b216a
SPACK_DLAF_REPO: ./spack
DOCKER_BUILD_ARGS: '[
"BASE_IMAGE",
Expand Down
2 changes: 1 addition & 1 deletion ci/docker/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN apt-get -yqq update && \
apt-get -yqq install --no-install-recommends \
software-properties-common \
build-essential gfortran \
autoconf automake ninja-build pkg-config \
autoconf automake libssl-dev ninja-build pkg-config \
${EXTRA_APTGET} \
gawk \
python3 python3-distutils \
Expand Down
22 changes: 19 additions & 3 deletions cmake/FindLAPACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# LAPACK_LIBRARY
# ;-list of {lib name, lib filepath, -Llibrary_folder}
#
# LAPACK_INCLUDE_DIR
# ;-list of include folders
#
# This module sets the following variables:
# LAPACK_FOUND - set to true if a library implementing the LAPACK interface is found
#
Expand Down Expand Up @@ -54,27 +57,40 @@ endmacro()
# Dependencies
set(_DEPS "")

if(LAPACK_LIBRARY STREQUAL "" OR NOT LAPACK_LIBRARY)
if(NOT LAPACK_LIBRARY)
set(LAPACK_LIBRARY "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
endif()

mark_as_advanced(LAPACK_LIBRARY)

_lapack_check_is_working()

if(NOT LAPACK_INCLUDE_DIR)
set(LAPACK_INCLUDE_DIR "LAPACK_INCLUDE_DIR-PLACEHOLDER-FOR-EMPTY-INCLUDE-DIR")
endif()

mark_as_advanced(LAPACK_INCLUDE_DIR)

### Package
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LAPACK DEFAULT_MSG LAPACK_LIBRARY _LAPACK_CHECK _LAPACK_CHECK_BLAS)
find_package_handle_standard_args(
LAPACK DEFAULT_MSG LAPACK_LIBRARY LAPACK_INCLUDE_DIR _LAPACK_CHECK _LAPACK_CHECK_BLAS
)

# Remove the placeholder
# Remove the placeholders
if(LAPACK_LIBRARY STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
set(LAPACK_LIBRARY "")
endif()

if(LAPACK_INCLUDE_DIR STREQUAL "LAPACK_INCLUDE_DIR-PLACEHOLDER-FOR-EMPTY-INCLUDE-DIR")
set(LAPACK_INCLUDE_DIR "")
endif()

if(LAPACK_FOUND)
if(NOT TARGET DLAF::LAPACK)
add_library(DLAF::LAPACK INTERFACE IMPORTED GLOBAL)
endif()

target_link_libraries(DLAF::LAPACK INTERFACE "${LAPACK_LIBRARY}" "${_DEPS}")
target_include_directories(DLAF::LAPACK INTERFACE "${LAPACK_INCLUDE_DIR}")
endif()
Loading

0 comments on commit 62718b9

Please sign in to comment.