From 66905e96e6178b5a91ac98b56e11f79bc4f25f9d Mon Sep 17 00:00:00 2001 From: Weslley S Pereira Date: Fri, 8 Sep 2023 12:32:31 -0600 Subject: [PATCH] More changes to improve flags BLAS++ and LAPACK++ --- .github/workflows/cmake.yml | 66 +++++++++++++------ CMakeLists.txt | 122 +++++++++++++++++++++++++----------- 2 files changed, 132 insertions(+), 56 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b4ac8164b9..35ab8a7da1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -162,8 +162,13 @@ jobs: strategy: fail-fast: false matrix: - sharedlib: [ ON, OFF ] + sharedlib: [ OFF, ON ] lapackpp: [ OFF ] + optblas: [ OFF, ON ] + optlapack: [ OFF, ON ] + exclude: + - optblas: ON + optlapack: ON steps: @@ -174,12 +179,9 @@ jobs: uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3 - name: Install the Basics - # Adding some noise to the system: libopenblas-dev liblapack-dev should not - # be linked to BLAS++ or LAPACK++. run: | sudo apt update - sudo apt install -y cmake gfortran - sudo apt purge libopenblas-dev liblapack-dev + sudo apt install -y cmake gfortran libopenblas-dev - name: Configure CMake run: > @@ -192,26 +194,54 @@ jobs: -D BUILD_SHARED_LIBS:BOOL=${{ matrix.sharedlib }} -D BLAS++:BOOL=ON -D LAPACK++:BOOL=${{ matrix.lapackpp }} + -D USE_OPTIMIZED_BLAS:BOOL=${{ matrix.optblas }} + -D USE_OPTIMIZED_LAPACK:BOOL=${{ matrix.optlapack }} - name: Build run: cmake --build build --config ${{env.BUILD_TYPE}} - - name: Check dependencies of BLAS++ + - name: Check dependencies of BLAS++ on BLAS working-directory: ${{github.workspace}}/build run: | - blaspp_blas=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/libblas" | { grep -v grep || true; }) - echo "blaspp_blas: $blaspp_blas" - if [[ -z $blaspp_blas ]]; then - echo "BLAS++ dependency to BLAS is not correct!" - echo "CMake could not find ${{github.workspace}}/build/lib/libblas in lib/cmake/blaspp/blasppConfig.cmake" - exit 1 + configFile="lib/cmake/blaspp/blasppConfig.cmake" + if [[ ${{ matrix.optblas }} == 'ON' ]]; then + if grep -q "openblas" $configFile; then + echo "BLAS++ dependency to BLAS is correct." + else + echo "CMake could not find openblas in $configFile:" + cat $configFile + exit 1 + fi + else + if grep -q "${{github.workspace}}/build/lib/libblas" $configFile; then + echo "BLAS++ dependency to BLAS is correct." + else + echo "CMake could not find ${{github.workspace}}/build/lib/libblas in $configFile:" + cat $configFile + exit 1 + fi fi - blaspp_lapack=$(cat lib/cmake/blaspp/blasppConfig.cmake | grep "${{github.workspace}}/build/lib/liblapack" | { grep -v grep || true; }) - echo "blaspp_lapack: $blaspp_lapack" - if [[ -z $blaspp_lapack ]]; then - echo "BLAS++ dependency to LAPACK is not correct!" - echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in lib/cmake/blaspp/blasppConfig.cmake" - exit 1 + + - name: Check dependencies of BLAS++ on LAPACK + working-directory: ${{github.workspace}}/build + run: | + configFile="lib/cmake/blaspp/blasppConfig.cmake" + if [[ ${{ matrix.optblas }} == 'ON' ]]; then + if grep -q "openblas" $configFile; then + echo "BLAS++ dependency to LAPACK is correct." + else + echo "CMake could not find openblas in $configFile:" + cat $configFile + exit 1 + fi + else + if grep -q "${{github.workspace}}/build/lib/liblapack" $configFile; then + echo "BLAS++ dependency to LAPACK is correct." + else + echo "CMake could not find ${{github.workspace}}/build/lib/liblapack in $configFile:" + cat $configFile + exit 1 + fi fi - name: Install diff --git a/CMakeLists.txt b/CMakeLists.txt index 0701dedf6c..8effd6c325 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -512,21 +512,55 @@ if (BLAS++ OR LAPACK++) endif() # Adds target blaspp - add_custom_target( blaspp ALL + add_custom_target( blaspp ALL DEPENDS blaspp-cmd ) + add_custom_command( OUTPUT blaspp-cmd + WORKING_DIRECTORY "${blaspp_SOURCE_DIR}" + COMMENT "Building BLAS++" ) + + # Set up information about the BLAS and LAPACK libraries + if(NOT BLAS_FOUND) + if(NOT LATESTLAPACK_FOUND) + add_custom_command( OUTPUT blaspp-cmd APPEND + COMMAND ${CMAKE_COMMAND} + -B "${blaspp_BINARY_DIR}" + -D BLAS_LIBRARIES="$${BLAS_Fortran_LIB}" + -D LAPACK_LIBRARIES="$" ) + else() + add_custom_command( OUTPUT blaspp-cmd APPEND + COMMAND ${CMAKE_COMMAND} + -B "${blaspp_BINARY_DIR}" + -D BLAS_LIBRARIES="$${BLAS_Fortran_LIB}" + -D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" ) + endif() + else() + if(NOT LATESTLAPACK_FOUND) + add_custom_command( OUTPUT blaspp-cmd APPEND + COMMAND ${CMAKE_COMMAND} + -B "${blaspp_BINARY_DIR}" + -D BLAS_LIBRARIES="${BLAS_LIBRARIES}" + -D LAPACK_LIBRARIES="$${BLAS_Fortran_LIB}" ) + else() + add_custom_command( OUTPUT blaspp-cmd APPEND + COMMAND ${CMAKE_COMMAND} + -B "${blaspp_BINARY_DIR}" + -D BLAS_LIBRARIES="${BLAS_LIBRARIES}" + -D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" ) + endif() + endif() + + # Setup remaining configuration options and installation + add_custom_command( OUTPUT blaspp-cmd APPEND COMMAND ${CMAKE_COMMAND} - -B "${blaspp_BINARY_DIR}" - -D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}" - -D blas_libraries_cached="" - "-DBLAS_LIBRARIES=\"$,${BLAS_LIBRARIES},$>${BLAS_Fortran_LIB}\"" - -D lapack_libraries_cached="" - "-DLAPACK_LIBRARIES=\"$,${LAPACK_LIBRARIES},$>\"" - -D build_tests=OFF - -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} + -B "${blaspp_BINARY_DIR}" + -D CMAKE_INSTALL_PREFIX="${blaspp_BINARY_DIR}" + -D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib" + -D blas_libraries_cached="" + -D lapack_libraries_cached="" + -D build_tests=OFF + -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} COMMAND ${CMAKE_COMMAND} --build "${blaspp_BINARY_DIR}" --target install - WORKING_DIRECTORY "${blaspp_SOURCE_DIR}" - COMMENT "Building BLAS++" ) # Set up dependencies @@ -549,19 +583,36 @@ if (LAPACK++) endif() # Adds target lapackpp - add_custom_target( lapackpp ALL - COMMAND ${CMAKE_COMMAND} + add_custom_target( lapackpp ALL DEPENDS lapackpp-cmd ) + add_custom_command( OUTPUT lapackpp-cmd + WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}" + COMMENT "Building LAPACK++" ) + + # Set up information about the LAPACK library + if(NOT LATESTLAPACK_FOUND) + add_custom_command( OUTPUT lapackpp-cmd APPEND + COMMAND ${CMAKE_COMMAND} -B "${lapackpp_BINARY_DIR}" - -D CMAKE_INSTALL_PREFIX="${PROJECT_BINARY_DIR}" - -D lapack_libraries_cached="" - "-DLAPACK_LIBRARIES=\"$,${LAPACK_LIBRARIES},$>\"" - -D build_tests=OFF - -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} + -D LAPACK_LIBRARIES="$${BLAS_Fortran_LIB}" ) + else() + add_custom_command( OUTPUT lapackpp-cmd APPEND + COMMAND ${CMAKE_COMMAND} + -B "${lapackpp_BINARY_DIR}" + -D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" ) + endif() + + # Setup remaining configuration options and installation + add_custom_command( OUTPUT lapackpp-cmd APPEND + COMMAND ${CMAKE_COMMAND} + -B "${lapackpp_BINARY_DIR}" + -D CMAKE_INSTALL_PREFIX="${lapackpp_BINARY_DIR}" + -D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib" + -D lapack_libraries_cached="" + -D build_tests=OFF + -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} COMMAND ${CMAKE_COMMAND} --build "${lapackpp_BINARY_DIR}" --target install - WORKING_DIRECTORY "${lapackpp_SOURCE_DIR}" - COMMENT "Building LAPACK++" ) # Set up dependencies @@ -675,14 +726,14 @@ install(FILES ) if (LAPACK++) install( - DIRECTORY "${LAPACK_BINARY_DIR}/lib/" - DESTINATION ${CMAKE_INSTALL_LIBDIR} - FILES_MATCHING REGEX "liblapackpp.(a|so)$" + DIRECTORY "${LAPACK_BINARY_DIR}/lib/" + DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING REGEX "liblapackpp.(a|so)$" ) - write_basic_package_version_file( - "lapackppConfigVersion.cmake" - VERSION 2023.08.25 - COMPATIBILITY AnyNewerVersion + install( + DIRECTORY "${lapackpp_BINARY_DIR}/include/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING REGEX "\\.(h|hh)$" ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake" @@ -692,23 +743,18 @@ if (LAPACK++) endif() if (BLAS++) - install( - DIRECTORY "${LAPACK_BINARY_DIR}/lib/" - DESTINATION ${CMAKE_INSTALL_LIBDIR} - FILES_MATCHING REGEX "libblaspp.(a|so)$" - ) - write_basic_package_version_file( - "blasppConfigVersion.cmake" - VERSION 2023.08.25 - COMPATIBILITY AnyNewerVersion - ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/blaspp/blasppConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/" ) install( - DIRECTORY "${PROJECT_BINARY_DIR}/include/" + DIRECTORY "${LAPACK_BINARY_DIR}/lib/" + DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING REGEX "libblaspp.(a|so)$" + ) + install( + DIRECTORY "${blaspp_BINARY_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING REGEX "\\.(h|hh)$" )