GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit ceb649b5 authored by Christoph Conrads's avatar Christoph Conrads
Browse files

CMake: improve build system

* allow OpenBLAS and MKL as BLAS implementations
* fix build when METIS is installed in non-standard folders
* allow user to pass non-standard search paths for every dependency
parent 631c6139
# Copyright 2016 Christoph Conrads
# Copyright 2016, 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -9,16 +9,11 @@ project(dcgeig VERSION 2.0.0)
# set variables
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -std=c++11 -pedantic")
# options
option(USE_MKL "Link against Intel MKL" OFF)
set(MKL_INCLUDE_DIR "/opt/intel/mkl/include"
CACHE PATH "Path to Intel MKL include directory")
set(MKL_LIBRARY_PATH "/opt/intel/mkl/lib/intel64"
CACHE PATH "Path to Intel MKL libraries")
# command line options
option(BE_QUIET "Tell CMake to be quiet" OFF)
option(BUILD_TESTING "Build tests" OFF)
......@@ -27,7 +22,6 @@ IF(BE_QUIET)
set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
ENDIF(BE_QUIET)
IF(BUILD_TESTING)
enable_testing()
ENDIF(BUILD_TESTING)
......
......@@ -25,7 +25,7 @@ You need the following software:
- git
- bash
BLAS and LAPACK can also be provided by Intel MKL 11.2 (or newer) and
BLAS and LAPACK can be provided by OpenBLAS or by Intel MKL 11.2 or newer and
instructions for this build are given below. Note that NumPy and SciPy need to
be linked against Intel MKL, too, if you want to see any speed-up. Instructions
for such a build can be found here:
......@@ -71,9 +71,7 @@ Installation with Intel MKL
- Configure the build with cmake:
cmake \
-DCMAKE_INSTALL_PREFIX="${prefixdir}" \
-DUSE_MKL=ON \
-DMKL_INCLUDE_DIR="${MKLROOT}/include" \
-DMKL_LIBRARY_PATH="${MKLROOT}/lib/intel64" \
-DBLAS=mkl -DMKL_ROOT="$MKLROOT" \
"${sourcedir}"
- Build the solvers:
......
# Copyright 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set(BLAS "openblas" CACHE STRING "Select the BLAS implementation")
if("${BLAS}" STREQUAL "openblas")
find_package(OpenBLAS REQUIRED)
set(LINALG_LIBRARIES ${OPENBLAS_LIBRARY})
set(LINALG_INCLUDE_DIRS ${OPENBLAS_INCLUDE_DIR})
set(LINALG_LINKER_FLAGS ${OPENBLAS_LINKER_FLAGS})
elseif("${BLAS}" STREQUAL "mkl")
find_package(MKL REQUIRED)
set(LINALG_LIBRARIES ${MKL_LIBRARIES})
set(LINALG_INCLUDE_DIRS ${MKL_INCLUDE_DIRS})
set(LINALG_LINKER_FLAGS ${MKL_LINKER_FLAGS})
else()
message(FATAL_ERROR "Unknown BLAS implementation '${BLAS}'")
endif()
# Copyright 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set(MKL_ROOT "/opt/intel/mkl" CACHE PATH "The Intel MKL root folder")
find_path(
MKL_INCLUDE_DIR
NAMES mkl.h
HINTS "${MKL_ROOT}"
PATH_SUFFIXES include
)
find_library(
MKL_LIBRARY
NAMES mkl_rt
HINTS "${MKL_ROOT}"
PATH_SUFFIXES "lib/intel64"
)
find_library(LIBPTHREAD NAMES pthread)
find_library(LIBM NAMES m)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
MKL
REQUIRED_VARS MKL_INCLUDE_DIR MKL_LIBRARY LIBPTHREAD LIBM
)
if(MKL_FOUND)
set(MKL_LIBRARIES ${MKL_LIBRARY} ${LIBPTHREAD} ${LIBPTHREAD})
set(MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR})
set(MKL_LINKER_FLAGS "-Wl,--no-as-needed")
endif()
mark_as_advanced(MKL_INCLUDE_DIR MKL_LIBRARY MKL_LINKER_FLAGS)
# Copyright 2016 Christoph Conrads
# Copyright 2016, 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
find_path(METIS_INCLUDE_DIR NAMES metis.h)
find_library(METIS_LIBRARY NAMES metis)
set(METIS_ROOT "" CACHE PATH "The METIS root folder")
find_path(
METIS_INCLUDE_DIR
NAMES metis.h
HINTS "${METIS_ROOT}"
PATH_SUFFIXES include
)
find_library(
METIS_LIBRARY
NAMES metis
HINTS "${METIS_ROOT}"
PATH_SUFFIXES lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
......
# Copyright 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set(OPENBLAS_ROOT "" CACHE PATH "The OpenBLAS root folder")
if(NOT "${OPENBLAS_ROOT}" STREQUAL "")
set(_OPENBLAS_PKG_CONFIG_PATH "$ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${OPENBLAS_ROOT}/lib/pkgconfig:${_OPENBLAS_PKG_CONFIG_PATH}")
endif()
find_package(PkgConfig)
pkg_check_modules(_PC_OPENBLAS REQUIRED openblas)
if(NOT "${OPENBLAS_ROOT}" STREQUAL "")
set(ENV{PKG_CONFIG_PATH} "${_OPENBLAS_PKG_CONFIG_PATH}")
endif()
find_path(
OPENBLAS_INCLUDE_DIR
NAMES openblas_config.h
PATHS "${_PC_OPENBLAS_INCLUDE_DIRS}"
NO_DEFAULT_PATH
)
find_library(
OPENBLAS_LIBRARY
NAMES openblas
PATHS "${_PC_OPENBLAS_LIBRARY_DIRS}"
NO_DEFAULT_PATH
)
set(OPENBLAS_LINKER_FLAGS ${_PC_OPENBLAS_LDFLAGS_OTHER})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
OpenBLAS
REQUIRED_VARS OPENBLAS_INCLUDE_DIR OPENBLAS_LIBRARY
)
# Copyright 2016 Christoph Conrads
# Copyright 2016, 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if(USE_MKL)
if("${BLAS}" STREQUAL "mkl")
set(HAS_INTEL_MKL True)
set(HAS_GGSVD3 False)
else(USE_MKL)
else()
set(HAS_INTEL_MKL False)
set(HAS_GGSVD3 True)
endif(USE_MKL)
endif()
configure_file(config.h.in config.h)
......
/*
* Copyright 2016 Christoph Conrads
* Copyright 2016, 2018 Christoph Conrads
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -8,7 +8,7 @@
#ifndef CONFIG_H
#define CONFIG_H
#cmakedefine USE_MKL
#cmakedefine HAS_INTEL_MKL
#cmakedefine HAS_GGSVD3
#endif
/*
* Copyright 2015-2016 Christoph Conrads
* Copyright 2015-2016, 2018 Christoph Conrads
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -9,7 +9,7 @@
#include <config.h>
#ifdef USE_MKL
#ifdef HAS_INTEL_MKL
# include <mkl.h>
#else
# include <lapacke.h>
......
/*
* Copyright 2015-2016 Christoph Conrads
* Copyright 2015-2016, 2018 Christoph Conrads
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -13,7 +13,7 @@
# include <algorithm>
#endif
#ifdef USE_MKL
#ifdef HAS_INTEL_MKL
# include <mkl.h>
#else
# include <lapacke.h>
......@@ -44,7 +44,7 @@ namespace lapack
template<typename T>
T* return_not_null(T* p)
{
#ifdef USE_MKL
#ifdef HAS_INTEL_MKL
return p ? p : (T*)-1;
#else
return p;
......@@ -350,7 +350,7 @@ inline float lanhe(
{
assert( (std::toupper(norm) != 'I') || work );
#ifdef USE_MKL
#ifdef HAS_INTEL_MKL
// work around a bug with Intel MKL 11.3 Update 2
const int num_threads = MKL_Set_Num_Threads_Local(1);
const float ret = slansy(&norm, &uplo, &n, A, &lda, work);
......@@ -367,7 +367,7 @@ inline double lanhe(
{
assert( (std::toupper(norm) != 'I') || work );
#ifdef USE_MKL
#ifdef HAS_INTEL_MKL
// work around a bug with Intel MKL 11.3 Update 2
const int num_threads = MKL_Set_Num_Threads_Local(1);
const double ret = dlansy(&norm, &uplo, &n, A, &lda, work);
......@@ -418,6 +418,8 @@ inline integer_t lascl(
#ifdef HAS_INTEL_MKL
inline void lascl2(
integer_t m, integer_t n, const float* D, float* X, integer_t ldx)
{
......@@ -430,6 +432,24 @@ inline void lascl2(
dlascl2_(&m, &n, D, X, &ldx);
}
#else
template<typename T>
void lascl2(
integer_t m, integer_t n, const T* D, T* X, integer_t ldx)
{
for(ssize_t j = 0; j < n; ++j)
{
for(ssize_t i = 0; i < m; ++i)
{
ssize_t k = i + (j-1) * ldx;
X[k] *= D[k];
}
}
}
#endif
inline void laset(
......
/*
* Copyright 2015 Christoph Conrads
* Copyright 2015, 2018 Christoph Conrads
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -12,6 +12,7 @@
#include <algorithm>
#include <cmath>
#include "lapack.hpp"
#include <limits>
......
# Copyright 2016 Christoph Conrads
# Copyright 2016, 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -42,6 +42,7 @@ add_custom_command(
add_library(metis SHARED metis.c)
set_target_properties(metis PROPERTIES PREFIX "")
target_compile_options(metis PUBLIC ${CYTHON_CFLAGS})
target_include_directories(metis PUBLIC ${METIS_INCLUDE_DIRS})
target_include_directories(metis PUBLIC ${PYTHON_INCLUDE_DIRS})
target_include_directories(metis PUBLIC ${NUMPY_INCLUDE_DIRS})
target_link_libraries(metis PUBLIC ${PYTHON_LIBRARIES})
......
# Copyright 2016 Christoph Conrads
# Copyright 2016, 2018 Christoph Conrads
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
IF(USE_MKL)
include_directories(${MKL_INCLUDE_DIR})
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${MKL_LIBRARY_PATH})
find_library(MKL_RT "mkl_rt")
find_library(PTHREAD "pthread")
find_library(LIBM "m")
set(LINALG_LIBS ${MKL_RT} ${PTHREAD} ${LIBM})
set(CMAKE_SHARED_LINKER_FLAGS
" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed")
ELSE(USE_MKL)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
set(LINALG_LIBS ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
ENDIF(USE_MKL)
find_package(LinAlg REQUIRED)
add_library(solvers SHARED
deflate_gep.cpp
......@@ -29,7 +13,9 @@ add_library(solvers SHARED
solve_gep_with_gsvd.cpp
solve_gep_with_qr_csd.cpp)
target_include_directories(solvers PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(solvers ${LINALG_LIBS})
target_include_directories(solvers PUBLIC ${LINALG_INCLUDE_DIRS})
target_link_libraries(solvers PUBLIC ${LINALG_LIBRARIES})
target_link_libraries(solvers INTERFACE ${LINALG_LINKER_FLAGS})
set_target_properties(solvers PROPERTIES OUTPUT_NAME "hpsd_gep_solvers")
install(TARGETS solvers DESTINATION lib)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment