From 62718b9bfd802ce4ad14405ee0e9150b4d95bbec Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Fri, 31 May 2024 14:17:31 +0200 Subject: [PATCH] Remove most special handling of MKL in CMake configuration (#1149) --- BUILD.md | 1 - CMakeLists.txt | 82 +++---- ci/common-ci.yml | 2 +- ci/docker/build.Dockerfile | 2 +- cmake/FindLAPACK.cmake | 22 +- cmake/FindMKL.cmake | 313 --------------------------- cmake/FindSCALAPACK.cmake | 2 + cmake/template/DLAFConfig.cmake.in | 46 +--- cmake/tests/mkl_set_num_threads.cpp | 15 ++ spack/packages/dla-future/package.py | 4 +- src/CMakeLists.txt | 17 +- 11 files changed, 86 insertions(+), 420 deletions(-) delete mode 100644 cmake/FindMKL.cmake create mode 100644 cmake/tests/mkl_set_num_threads.cpp diff --git a/BUILD.md b/BUILD.md index a1c1a4fc5a..d65ae6a5a9 100644 --- a/BUILD.md +++ b/BUILD.md @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index db5c37c6ed..3100730475 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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( @@ -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) @@ -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 diff --git a/ci/common-ci.yml b/ci/common-ci.yml index 626f81edc2..3a9e6f5fa5 100644 --- a/ci/common-ci.yml +++ b/ci/common-ci.yml @@ -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", diff --git a/ci/docker/build.Dockerfile b/ci/docker/build.Dockerfile index 07e7b06fde..f50d178d8a 100644 --- a/ci/docker/build.Dockerfile +++ b/ci/docker/build.Dockerfile @@ -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 \ diff --git a/cmake/FindLAPACK.cmake b/cmake/FindLAPACK.cmake index 65f2fede49..283fa5f4dc 100644 --- a/cmake/FindLAPACK.cmake +++ b/cmake/FindLAPACK.cmake @@ -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 # @@ -54,7 +57,7 @@ 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() @@ -62,19 +65,32 @@ 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() diff --git a/cmake/FindMKL.cmake b/cmake/FindMKL.cmake deleted file mode 100644 index 8c1d121907..0000000000 --- a/cmake/FindMKL.cmake +++ /dev/null @@ -1,313 +0,0 @@ -# -# CMake recipes -# https://github.com/eth-cscs/cmake-recipes -# -# Copyright (c) 2018-2024, ETH Zurich -# BSD 3-Clause License. All rights reserved. -# -# Author: Teodor Nikolov (tnikolov@cscs.ch) -# - -# dlaf-no-license-check - -#[=======================================================================[.rst: -FindMKL -------- - -The following conventions are used: - -intel / INTEL - Bindings for everything except GNU Fortran -gf / GF - GNU Fortran bindings -seq / SEQ - sequential MKL -omp / OMP - threaded MKL with OpenMP back end -tbb / TBB - threaded MKL with TBB back end -32bit / 32BIT - MKL 32 bit integer interface (used most often) -64bit / 64BIT - MKL 64 bit integer interface -mpich / MPICH - MPICH / IntelMPI BLACS back end -ompi / OMPI - OpenMPI BLACS back end -st / ST - static libraries -dyn / DYN - dynamic libraries - -The module attempts to define a target for each MKL configuration. The -configuration will not be available if there are missing library files or a -missing dependency. - -MKL Link line advisor: - https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor - -Note: Mixing GCC and Intel OpenMP backends is a bad idea. - -Search variables -^^^^^^^^^^^^^^^^ - -``MKLROOT`` - Environment variable set to MKL's root directory - -``MKL_ROOT`` - CMake variable set to MKL's root directory - -Example usage -^^^^^^^^^^^^^ - -To Find MKL: - - find_package(MKL REQUIRED) - -To check if target is available: - - if (TARGET mkl::scalapack_mpich_intel_32bit_omp_dyn) - ... - endif() - -To link to an available target (see list below): - - target_link_libraries(... mkl::scalapack_mpich_intel_32bit_omp_dyn) - -Note: dependencies are handled for you (MPI, OpenMP, ...) - -Imported targets -^^^^^^^^^^^^^^^^ - -MKL (BLAS, LAPACK, FFT) targets: - - mkl::mkl_[gf|intel]_[32bit|64bit]_[seq|omp|tbb]_[st|dyn] e.g. - - mkl::mkl_intel_32bit_omp_dyn - -BLACS targets: - - mkl::blacs_[mpich|ompi]_[gf|intel]_[32bit|64bit]_[seq|omp|tbb]_[st|dyn] e.g. - - mkl::blacs_intel_mpich_32bit_seq_st - -ScaLAPACK targets: - - mkl::scalapack_[mpich|ompi]_[gf|intel]_[32bit|64bit]_[seq|omp|tbb]_[st|dyn] e.g. - - mkl::scalapack_mpich_intel_64bit_omp_dyn - -Result variables -^^^^^^^^^^^^^^^^ - -MKL_FOUND - -Not supported -^^^^^^^^^^^^^ - -- F95 interfaces - -#]=======================================================================] - -cmake_minimum_required(VERSION 3.12) - -# check if compatible compiler is found -if(CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED) - set(_mkl_compiler_found TRUE) -else() - set(_mkl_compiler_found FALSE) -endif() - -# Dependencies -# -find_package(Threads) -find_package(MPI COMPONENTS CXX) -find_package(OpenMP COMPONENTS CXX) - -# If MKL_ROOT is not set, set it via the env variable MKLROOT. -# -if(NOT DEFINED MKL_ROOT) - set(MKL_ROOT $ENV{MKLROOT}) -endif() - -# Determine MKL's library folder -# -set(_mkl_libpath_suffix "lib/intel64") -if(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32 bit - set(_mkl_libpath_suffix "lib/ia32") -endif() - -if(WIN32) - string(APPEND _mkl_libpath_suffix "_win") - set(_mkl_libname_prefix "") - set(_mkl_shared_lib "_dll.lib") - set(_mkl_static_lib ".lib") -elseif(APPLE) - string(APPEND _mkl_libpath_suffix "_mac") - set(_mkl_libname_prefix "lib") - set(_mkl_shared_lib ".dylib") - set(_mkl_static_lib ".a") -else() # LINUX - string(APPEND _mkl_libpath_suffix "_lin") - set(_mkl_libname_prefix "lib") - set(_mkl_shared_lib ".so") - set(_mkl_static_lib ".a") -endif() -set(_mkl_search_paths "${MKL_ROOT}" "${MKL_ROOT}/lib" "${MKL_ROOT}/mkl" "${MKL_ROOT}/compiler") - -# Functions: finds both static and shared MKL libraries -# -function(__mkl_find_library _varname _libname) - find_library( - ${_varname}_DYN - NAMES ${_mkl_libname_prefix}${_libname}${_mkl_shared_lib} - HINTS ${_mkl_search_paths} - PATH_SUFFIXES ${_mkl_libpath_suffix} - ) - mark_as_advanced(${_varname}_DYN) - find_library( - ${_varname}_ST - NAMES ${_mkl_libname_prefix}${_libname}${_mkl_static_lib} - HINTS ${_mkl_search_paths} - PATH_SUFFIXES ${_mkl_libpath_suffix} - ) - mark_as_advanced(${_varname}_ST) -endfunction() - -# Find MKL headers -# -find_path(MKL_INCLUDE_DIR mkl.h HINTS ${MKL_ROOT}/include ${MKL_ROOT}/mkl/include) -mark_as_advanced(MKL_INCLUDE_DIR) - -# Group flags for static libraries on Linux (GNU, PGI, ICC -> same linker) -# -if(UNIX AND NOT APPLE) - set(_mkl_linker_pre_flags_ST "-Wl,--start-group") - set(_mkl_linker_post_flags_ST "-Wl,--end-group") -endif() - -# Core MKL -# -__mkl_find_library(MKL_CORE_LIB mkl_core) - -# Interface -# -__mkl_find_library(MKL_INTERFACE_INTEL_32BIT_LIB mkl_intel_lp64) -__mkl_find_library(MKL_INTERFACE_INTEL_64BIT_LIB mkl_intel_ilp64) -if(NOT APPLE AND CMAKE_Fortran_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") - __mkl_find_library(MKL_INTERFACE_GF_32BIT_LIB mkl_gf_lp64) - __mkl_find_library(MKL_INTERFACE_GF_64BIT_LIB mkl_gf_ilp64) -endif() - -# Threading -# -__mkl_find_library(MKL_SEQ_LIB mkl_sequential) -if(NOT APPLE AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" - OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") -) - __mkl_find_library(MKL_OMP_LIB mkl_gnu_thread) -else() - __mkl_find_library(MKL_OMP_LIB mkl_intel_thread) -endif() -__mkl_find_library(MKL_TBB_LIB mkl_tbb_thread) - -# BLACS -# -if(APPLE) - __mkl_find_library(MKL_BLACS_MPICH_32BIT_LIB mkl_blacs_mpich_lp64) - __mkl_find_library(MKL_BLACS_MPICH_64BIT_LIB mkl_blacs_mpich_ilp64) -else() - __mkl_find_library(MKL_BLACS_MPICH_32BIT_LIB mkl_blacs_intelmpi_lp64) - __mkl_find_library(MKL_BLACS_MPICH_64BIT_LIB mkl_blacs_intelmpi_ilp64) -endif() -__mkl_find_library(MKL_BLACS_OMPI_32BIT_LIB mkl_blacs_openmpi_lp64) -__mkl_find_library(MKL_BLACS_OMPI_64BIT_LIB mkl_blacs_openmpi_ilp64) - -# ScaLAPACK -# -__mkl_find_library(MKL_SCALAPACK_32BIT_LIB mkl_scalapack_lp64) -__mkl_find_library(MKL_SCALAPACK_64BIT_LIB mkl_scalapack_ilp64) - -# Check if core libs were found -# -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(MKL REQUIRED_VARS MKL_INCLUDE_DIR Threads_FOUND _mkl_compiler_found) - -# Sequential has no threading dependency. There is currently no TBB module -# shipped with CMake. The dependency is not accounted for. -# -set(_mkl_dep_found_SEQ TRUE) -set(_mkl_dep_found_TBB TRUE) -if(TARGET OpenMP::OpenMP_CXX) - set(_mkl_dep_OMP OpenMP::OpenMP_CXX) - set(_mkl_dep_found_OMP TRUE) -endif() - -# Define all blas, blacs and scalapack -# -foreach(_libtype "ST" "DYN") - set(_mkl_core_lib ${MKL_CORE_LIB_${_libtype}}) - foreach(_bits "32BIT" "64BIT") - set(_mkl_scalapack_lib ${MKL_SCALAPACK_${_bits}_LIB_${_libtype}}) - foreach(_iface "INTEL" "GF") - set(_mkl_interface_lib ${MKL_INTERFACE_${_iface}_${_bits}_LIB_${_libtype}}) - foreach(_threading "SEQ" "OMP" "TBB") - set(_mkl_threading_lib ${MKL_${_threading}_LIB_${_libtype}}) - - string(TOLOWER "${_iface}_${_bits}_${_threading}_${_libtype}" _tgt_config) - set(_mkl_tgt mkl::mkl_${_tgt_config}) - - if(MKL_FOUND - AND _mkl_interface_lib - AND _mkl_threading_lib - AND _mkl_core_lib - AND _mkl_dep_found_${_threading} - AND NOT TARGET ${_mkl_tgt} - ) - set(_mkl_libs - "${_mkl_linker_pre_flags_${_threading}}" - "${_mkl_interface_lib}" - "${_mkl_threading_lib}" - "${_mkl_core_lib}" - "${_mkl_linker_post_flags_${_threading}}" - "${_mkl_dep_${_threading}}" - "Threads::Threads" - ) - add_library(${_mkl_tgt} INTERFACE IMPORTED) - set_target_properties( - ${_mkl_tgt} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES "${_mkl_libs}" - ) - endif() - - foreach(_mpi_impl "MPICH" "OMPI") - set(_mkl_blacs_lib ${MKL_BLACS_${_mpi_impl}_${_bits}_LIB_${_libtype}}) - - string(TOLOWER "${_mpi_impl}_${_iface}_${_bits}_${_threading}_${_libtype}" _tgt_config) - set(_blacs_tgt mkl::blacs_${_tgt_config}) - set(_scalapack_tgt mkl::scalapack_${_tgt_config}) - - if(_mkl_blacs_lib - AND TARGET ${_mkl_tgt} - AND TARGET MPI::MPI_CXX - AND NOT TARGET ${_blacs_tgt} - ) - set(_blacs_libs - "${_mkl_linker_pre_flags_${_libtype}}" - "${_mkl_interface_lib}" - "${_mkl_threading_lib}" - "${_mkl_core_lib}" - "${_mkl_blacs_lib}" - "${_mkl_linker_post_flags_${_libtype}}" - "MPI::MPI_CXX" - "${_mkl_dep_${_threading}}" - "Threads::Threads" - ) - add_library(${_blacs_tgt} INTERFACE IMPORTED) - set_target_properties( - ${_blacs_tgt} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES "${_blacs_libs}" - ) - endif() - - if(_mkl_scalapack_lib AND TARGET ${_blacs_tgt} AND NOT TARGET ${_scalapack_tgt}) - set(_scalapack_libs "${_mkl_scalapack_lib}" "${_blacs_tgt}") - add_library(${_scalapack_tgt} INTERFACE IMPORTED) - set_target_properties( - ${_scalapack_tgt} PROPERTIES INTERFACE_LINK_LIBRARIES "${_scalapack_libs}" - ) - endif() - endforeach() - endforeach() - endforeach() - endforeach() -endforeach() diff --git a/cmake/FindSCALAPACK.cmake b/cmake/FindSCALAPACK.cmake index f6f7eb1eab..ad9ebc9d54 100644 --- a/cmake/FindSCALAPACK.cmake +++ b/cmake/FindSCALAPACK.cmake @@ -29,6 +29,7 @@ find_library( find_package_handle_standard_args(SCALAPACK DEFAULT_MSG SCALAPACK_LIBRARY) mark_as_advanced(SCALAPACK_LIBRARY) +mark_as_advanced(SCALAPACK_INCLUDE_DIR) if(SCALAPACK_FOUND) if(NOT TARGET DLAF::SCALAPACK) @@ -36,4 +37,5 @@ if(SCALAPACK_FOUND) endif() target_link_libraries(DLAF::SCALAPACK INTERFACE "${SCALAPACK_LIBRARY}") + target_include_directories(DLAF::SCALAPACK INTERFACE "${SCALAPACK_INCLUDE_DIR}") endif() diff --git a/cmake/template/DLAFConfig.cmake.in b/cmake/template/DLAFConfig.cmake.in index ef33e5599a..99f39d8c2e 100644 --- a/cmake/template/DLAFConfig.cmake.in +++ b/cmake/template/DLAFConfig.cmake.in @@ -19,8 +19,6 @@ list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) # ===== VARIABLES set(DLAF_WITH_OPENMP @DLAF_WITH_OPENMP@) -set(DLAF_WITH_MKL @DLAF_WITH_MKL@) -set(DLAF_WITH_MKL_LEGACY @DLAF_WITH_MKL_LEGACY@) set(DLAF_WITH_CUDA @DLAF_WITH_CUDA@) set(DLAF_WITH_HIP @DLAF_WITH_HIP@) set(DLAF_WITH_GPU @DLAF_WITH_GPU@) @@ -53,42 +51,14 @@ if(DLAF_WITH_OPENMP) endif() # ----- LAPACK -if(DLAF_WITH_MKL) - set(MKL_INTERFACE "@MKL_INTERFACE@") - set(MKL_THREADING "@MKL_THREADING@") - set(MKL_MPI "@MKL_MPI@") - - find_dependency(MKL CONFIG) - - add_library(DLAF::LAPACK INTERFACE IMPORTED GLOBAL) - target_link_libraries(DLAF::LAPACK INTERFACE MKL::MKL) - - if(DLAF_WITH_SCALAPACK) - add_library(DLAF::SCALAPACK INTERFACE IMPORTED GLOBAL) - endif() -elseif(DLAF_WITH_MKL_LEGACY) - set(MKL_ROOT "@MKL_ROOT@") - set(MKL_CUSTOM_THREADING "@MKL_THREADING@") - - find_dependency(MKL) - - set(MKL_LAPACK_TARGET "@MKL_LAPACK_TARGET@") - add_library(DLAF::LAPACK INTERFACE IMPORTED GLOBAL) - target_link_libraries(DLAF::LAPACK INTERFACE ${MKL_LAPACK_TARGET}) - - if(DLAF_WITH_SCALAPACK) - set(MKL_SCALAPACK_TARGET "@MKL_SCALAPACK_TARGET@") - add_library(DLAF::SCALAPACK INTERFACE IMPORTED GLOBAL) - target_link_libraries(DLAF::SCALAPACK INTERFACE ${MKL_SCALAPACK_TARGET}) - endif() -else() - set(LAPACK_LIBRARY "@LAPACK_LIBRARY@") - find_dependency(LAPACK) - - if(DLAF_WITH_SCALAPACK) - set(SCALAPACK_LIBRARY "@SCALAPACK_LIBRARY@") - find_dependency(SCALAPACK) - endif() +set(LAPACK_LIBRARY "@LAPACK_LIBRARY@") +set(LAPACK_INCLUDE_DIR "@LAPACK_INCLUDE_DIR@") +find_dependency(LAPACK) + +if(DLAF_WITH_SCALAPACK) + set(SCALAPACK_LIBRARY "@SCALAPACK_LIBRARY@") + set(SCALAPACK_INCLUDE_DIR "@SCALAPACK_INCLUDE_DIR@") + find_dependency(SCALAPACK) endif() # ----- pika diff --git a/cmake/tests/mkl_set_num_threads.cpp b/cmake/tests/mkl_set_num_threads.cpp new file mode 100644 index 0000000000..a0eee9e1df --- /dev/null +++ b/cmake/tests/mkl_set_num_threads.cpp @@ -0,0 +1,15 @@ +// +// Distributed Linear Algebra with Future (DLAF) +// +// Copyright (c) 2018-2024, ETH Zurich +// All rights reserved. +// +// Please, refer to the LICENSE file in the root directory. +// SPDX-License-Identifier: BSD-3-Clause +// + +#include + +int main() { + [[maybe_unused]] auto mkl_num_threads = mkl_set_num_threads_local(1); +} diff --git a/spack/packages/dla-future/package.py b/spack/packages/dla-future/package.py index b7ba7501ae..0a41fa4596 100644 --- a/spack/packages/dla-future/package.py +++ b/spack/packages/dla-future/package.py @@ -184,7 +184,7 @@ def cmake_args(self): args.append(self.define_from_variant("BUILD_SHARED_LIBS", "shared")) # BLAS/LAPACK - if spec["lapack"].name in INTEL_MATH_LIBRARIES: + if spec.version <= Version("0.4") and spec["lapack"].name in INTEL_MATH_LIBRARIES: mkl_provider = spec["lapack"].name vmap = { @@ -246,7 +246,7 @@ def cmake_args(self): ) ) else: - args.append(self.define("DLAF_WITH_MKL", False)) + args.append(self.define("DLAF_WITH_MKL", spec["lapack"].name in INTEL_MATH_LIBRARIES)) args.append( self.define( "LAPACK_LIBRARY", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cdc1f1fd0c..4af59a4e25 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,16 @@ option(DLAF_ASSERT_ENABLE "Enable low impact assertions" ${DLAF_ASSERT_DEFAULT}) option(DLAF_ASSERT_MODERATE_ENABLE "Enable medium impact assertions" ${DLAF_ASSERT_MODERATE_DEFAULT}) option(DLAF_ASSERT_HEAVY_ENABLE "Enable high impact assertions" ${DLAF_ASSERT_HEAVY_DEFAULT}) +# We require separable compilation for CUDA with Umpire versions prior to 2024.02 (first 2024 version) +# because the libumpire.so library contains device code. In theory we only need it if +# UMPIRE_ENABLE_DEVICE_ALLOCATOR is enabled, but it's not exported by Umpire so we unconditionally use +# separable compilation before 2024 versions. Starting from 2024.02 the device code is in a separate +# library. +set(DLAF_WITH_SEPARABLE_COMPILATION OFF) +if(DLAF_WITH_CUDA AND Umpire_VERSION_MAJOR LESS 2024) + set(DLAF_WITH_SEPARABLE_COMPILATION ON) +endif() + # Define DLAF's PRIVATE properties add_library(dlaf.prop_private INTERFACE) target_compile_options(dlaf.prop_private INTERFACE -gz) @@ -93,8 +103,7 @@ target_compile_definitions( $<$:DLAF_ASSERT_MODERATE_ENABLE> $<$:DLAF_ASSERT_HEAVY_ENABLE> DLAF_FUNCTION_NAME=$,__PRETTY_FUNCTION__,__func__> - $<$:DLAF_WITH_MKL> - $<$:DLAF_WITH_MKL> + $<$:DLAF_WITH_MKL> $<$:DLAF_WITH_OPENMP> $<$:DLAF_WITH_GPU> $<$:DLAF_WITH_CUDA> @@ -175,7 +184,7 @@ function(DLAF_addSublibrary name) target_link_libraries(${lib_name} PUBLIC dlaf.prop) target_link_libraries(${lib_name} PUBLIC ${DLAF_ASL_LIBRARIES}) target_link_libraries(${lib_name} PRIVATE dlaf.prop_private) - if(DLAF_WITH_CUDA) + if(DLAF_WITH_SEPARABLE_COMPILATION) set_target_properties(${lib_name} PROPERTIES CUDA_SEPARABLE_COMPILATION ON) endif() endfunction() @@ -293,7 +302,7 @@ add_library( target_link_libraries(DLAF PUBLIC dlaf.prop) target_link_libraries(DLAF PRIVATE dlaf.prop_private) target_add_warnings(DLAF) -if(DLAF_WITH_CUDA) +if(DLAF_WITH_SEPARABLE_COMPILATION) set_target_properties(DLAF PROPERTIES CUDA_SEPARABLE_COMPILATION ON) endif()