Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove most special handling of MKL in CMake configuration #1149

Merged
merged 32 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5d0f37d
Use spack's blas/lapack libraries for MKL from version 0.5.X onwards
msimberg May 28, 2024
018ebcd
Remove DLAF_WITH_MKL_LEGACY CMake option
msimberg May 28, 2024
3f9ffc1
Add auto-detection for MKL
msimberg May 28, 2024
dc0ffe3
TEMP: Disable most CI configurations for testing
msimberg May 28, 2024
9967509
Update SPACK_SHA in CI
msimberg May 28, 2024
f71272b
Add libssl-dev to CI image for external openssl
msimberg May 28, 2024
910724d
Don't explicitly set DLAF_WITH_MKL in spack package
msimberg May 28, 2024
e681b72
Print MKL try_compile result
msimberg May 28, 2024
bedcec4
Don't find_package(MKL)
msimberg May 29, 2024
3ec281b
Don't use -Werror=all-warnings for CUDA in CI
msimberg May 29, 2024
a5cdae8
Add TODO about enabling MKL and OpenMP
msimberg May 29, 2024
c54431b
Remove -Werror=missing-launch-bounds from CUDA CI configuration
msimberg May 29, 2024
ecb341d
Use older try_compile signature
msimberg May 29, 2024
ebe5106
Add LAPACK_INCLUDE_DIR and SCALAPACK_INCLUDE_DIR variables
msimberg May 29, 2024
1631e50
Add placeholder for empty LAPACK_INCLUDE_DIR
msimberg May 29, 2024
ed6f9da
Remove semicolons from CMAKE_CUDA_FLAGS list
msimberg May 29, 2024
6e365c7
Disable all CUDA warnings in CI
msimberg May 29, 2024
0e1c544
Uncomment all CI configurations
msimberg May 29, 2024
68519ff
Conditionally use separable compilation
msimberg May 29, 2024
76aa169
Use -Werror=all-warnings again in CUDA CI
msimberg May 29, 2024
bb54476
Make minimum cmake version 3.22 again
msimberg May 29, 2024
becc830
Remove TODO
msimberg May 29, 2024
7cbc163
Remove TODOs
msimberg May 29, 2024
fb0d487
Remove TODO about auto-detecting MKL in spack package
msimberg May 29, 2024
460d24f
Update DLAF_WITH_MKL option description
msimberg May 29, 2024
b25b3e1
Rerun MKL detection every time CMake is configured
msimberg May 29, 2024
672a700
Fix MKL try_compile build directory
msimberg May 29, 2024
22b3f18
Refactor MKL auto-detection
msimberg May 30, 2024
9dc2f78
Remove DLAF_WITH_MKL as an option
msimberg May 31, 2024
1758a66
Simplify checks for empty LAPACK_LIBRARY and LAPACK_INCLUDE_DIR
msimberg May 31, 2024
5f5bb92
Remove DLAF_WITH_MKL from DLAFConfig.cmake.in
msimberg May 31, 2024
f0fd524
Update SPACK_SHA
msimberg May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 26 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,31 @@ 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.")
option(DLAF_WITH_MKL "Enable MKL as provider for BLAS and LAPACK" "${DLAF_WITH_MKL_TRY_COMPILE}")
albestro marked this conversation as resolved.
Show resolved Hide resolved
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)
msimberg marked this conversation as resolved.
Show resolved Hide resolved
# 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 +158,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: fd3c18b6fd7eda8abbb72ee81b39aa81b053d9bd
rasolca marked this conversation as resolved.
Show resolved Hide resolved
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 \
msimberg marked this conversation as resolved.
Show resolved Hide resolved
${EXTRA_APTGET} \
gawk \
python3 python3-distutils \
Expand Down
20 changes: 18 additions & 2 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 @@ -62,19 +65,32 @@ mark_as_advanced(LAPACK_LIBRARY)

_lapack_check_is_working()

if(LAPACK_INCLUDE_DIR STREQUAL "" OR NOT LAPACK_INCLUDE_DIR)
albestro marked this conversation as resolved.
Show resolved Hide resolved
set(LAPACK_INCLUDE_DIR "LAPACK_INCLUDE_DIR-PLACEHOLDER-FOR-EMPTY-INCLUDE-DIR")
endif()
msimberg marked this conversation as resolved.
Show resolved Hide resolved

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
Loading