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

Fix BLAS++ and LAPACK++ build #903

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

weslleyspereira
Copy link
Collaborator

@weslleyspereira weslleyspereira commented Aug 30, 2023

In the current LAPACK master, building with BLAS++ flag ON causes the following error in CMake:

[build] [ 47%] Building CXX object test/CMakeFiles/tester.dir/test.cc.o
[build] In file included from /home/weslleyp/storage/lapack/build_RelWithDebInfo/blaspp-prefix/src/blaspp/test/test.cc:12:
[build] /home/weslleyp/storage/lapack/build_RelWithDebInfo/blaspp-prefix/src/blaspp/test/test.hh:9:10: fatal error: testsweeper.hh: No such file or directory
[build]     9 | #include "testsweeper.hh"
[build]       |          ^~~~~~~~~~~~~~~~
[build] compilation terminated.
[build] make[2]: *** [test/CMakeFiles/tester.dir/build.make:76: test/CMakeFiles/tester.dir/test.cc.o] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:154: test/CMakeFiles/tester.dir/all] Error 2
[build] make: *** [Makefile:136: all] Error 2
[build] ninja: build stopped: subcommand failed.
[proc] The command: /usr/local/bin/cmake --build /home/weslleyp/storage/lapack/build_RelWithDebInfo --config Release --target all -- exited with code: 1

There is some issue in BLAS++ (https://bitbucket.org/icl/lapackpp/downloads/lapackpp-2020.10.02.tar.gz) so that it can't find testsweeper.hh. I can give more details about my system configuration.

The point is: we actually don't need to build the BLAS++ tests to obtain libblaspp. Thus, this PR solves the issue by adding -Dbuild_tests=OFF to the configuration step of BLAS++ and LAPACK++ in LAPACK.

Closes #905.

@weslleyspereira
Copy link
Collaborator Author

weslleyspereira commented Aug 30, 2023

I have two other concerns related to my last message:

  1. We are using an old version of BLAS++ and LAPACK++ (2020.10.02). Is that intentional?
  2. We have no tests in cmake.yml with BLAS++=ON and LAPACK++=ON.

@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Attention: 176 lines in your changes are missing coverage. Please review.

Comparison is base (90398ae) 0.00% compared to head (ef44890) 0.00%.
Report is 24 commits behind head on master.

❗ Current head ef44890 differs from pull request most recent head 7f2c622. Consider uploading reports for the commit 7f2c622 to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           master     #903    +/-   ##
========================================
  Coverage    0.00%    0.00%            
========================================
  Files        1918     1918            
  Lines      188653   188757   +104     
========================================
- Misses     188653   188757   +104     
Files Coverage Δ
SRC/cgedmd.f90 0.00% <ø> (ø)
SRC/cgedmdq.f90 0.00% <ø> (ø)
SRC/dgedmdq.f90 0.00% <ø> (ø)
SRC/sgedmdq.f90 0.00% <ø> (ø)
SRC/zgedmdq.f90 0.00% <ø> (ø)
SRC/clarfgp.f 0.00% <0.00%> (ø)
SRC/dlarfgp.f 0.00% <0.00%> (ø)
SRC/slarfgp.f 0.00% <0.00%> (ø)
SRC/zlarfgp.f 0.00% <0.00%> (ø)
SRC/dgedmd.f90 0.00% <0.00%> (ø)
... and 16 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mgates3
Copy link
Contributor

mgates3 commented Aug 31, 2023

1. We are using an old version of BLAS++ and LAPACK++ (2010.10.02). Is that intentional?

2020.10.02. You had me worried for a minute.

I think that was just what was available at the time. Perhaps we could use a release branch or tag to refer to the latest release. Is there a standard convention for that in Git? I just added the release branch, but we can do whatever seems best.

We can update the release version, I'm just not excited about updating LAPACK every time that BLAS++ and LAPACK++ are updated.

@weslleyspereira
Copy link
Collaborator Author

Sorry for the "2010", @mgates3. Not intentional. I fixed my message above.

So, I have an idea on how we could make it easy to

I think that was just what was available at the time. Perhaps we could use a release branch or tag to refer to the latest release. Is there a standard convention for that in Git? I just added the release branch, but we can do whatever seems best.

We can update the release version, I'm just not excited about updating LAPACK every time that BLAS++ and LAPACK++ are updated.

Ok. Thanks. We could at least try to update these dependencies whenever we release LAPACK, or whenever BLAS++ and LAPACK++ have a major update regarding the wrappers. I am also not too excited to update LAPACK every time that BLAS++ and LAPACK++ are updated. I was just surprised it was using a release from almost 3 years ago.

@weslleyspereira
Copy link
Collaborator Author

Now, about my second bullet: We have no tests in cmake.yml with BLAS++=ON and LAPACK++=ON. This is more worrisome to me. Yesterday, I was trying to use those flags and end up finding out that sometimes BLAS++ links with a BLAS library outside the repository, and I think that was not the plan when the flags were added. I will create an issue with more details.

@weslleyspereira
Copy link
Collaborator Author

I updated this PR so that it solves #905. It should be ready for review.

Note that the changes do not add tests for the flag LAPACK++ because of icl-utk-edu/lapackpp#44.

Copy link
Contributor

@mgates3 mgates3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I coded up some changes in this commit. These work on my Mac with this configuration:

cmake -D BLAS++=true -D LAPACK++=true \
      -D USE_OPTIMIZED_BLAS=true -D BLA_VENDOR=Apple \
      -D CMAKE_INSTALL_PREFIX=${HOME}/install-lapack -B build
cd build
make
make install

Haven't tried other configurations or elsewhere yet.

lapackpp
GIT_REPOSITORY https://github.com/icl-utk-edu/lapackpp
GIT_TAG 62680a16a9aba2a426e3d089dd13e18bfd140c74 # v2023.08.25
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want blaspp 91dd418fa910498cc03dee397826099914cc3185
and lapackpp 88088c33cd9467475e8f139f42d158620f11e64d
which have the fixes for Fortran strlen.

We will likely do a SLATE / BLAS++ / LAPACK++ bug fix release this month, but perhaps for that just update LAPACK right before the SC23 release.

# TODO: This is incomplete. Fill in the other cases.
set(BLAS_Fortran_LIB "")
endif()
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this when using Reference BLAS, is that why it checks NOT BLAS_FOUND?

When I tried to compile, linking with liblapack.a also needed -lgfortran, but since I used optimized BLAS, BLAS_FOUND was true and BLAS_Fortran_LIB was empty.

BTW, setting it to empty in the else case is redundant with set above if.

CMakeLists.txt Outdated
-D CMAKE_INSTALL_PREFIX="${blaspp_BINARY_DIR}"
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
-D blas_libraries_cached=""
-D lapack_libraries_cached=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was it needed to set blas_libraries_cached and lapack_libraries_cached? These are internal variables to the BLAS++ and LAPACK++ CMake scripts and subject to change.

Is this from having 2 COMMAND cmake above in the add_custom_command? Better to have only 1 COMMAND cmake so it searches correctly the first time.

(The additional COMMAND cmake --build below seems fine.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I need to set blas_libraries_cached and lapack_libraries_cached even if we configure cmake 2x. I needed it at some point of writing the PR, but I can't reproduce it anymore.

CMakeLists.txt Outdated
COMMAND ${CMAKE_COMMAND}
-B "${lapackpp_BINARY_DIR}"
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, this can be simplified.

CMakeLists.txt Outdated
-B "${lapackpp_BINARY_DIR}"
-D CMAKE_INSTALL_PREFIX="${lapackpp_BINARY_DIR}"
-D CMAKE_INSTALL_LIBDIR="${PROJECT_BINARY_DIR}/lib"
-D lapack_libraries_cached=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, shouldn't set internal variables.

CMakeLists.txt Outdated
# Setup remaining configuration options and installation
add_custom_command( OUTPUT lapackpp-cmd APPEND
COMMAND ${CMAKE_COMMAND}
-B "${lapackpp_BINARY_DIR}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, LAPACK++ couldn't find BLAS++. I found it easier to install them in the same directory. Maybe setting CMAKE_PREFIX_PATH would also work.

CMakeLists.txt Outdated
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "liblapackpp.(a|so)$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be other lapackpp files. Matching on just lapackpp would capture everything. For instance:

-- Installing: /.../lapack/build4/lib/cmake/lapackpp/lapackppTargets.cmake
-- Installing: /.../lapack/build4/lib/cmake/lapackpp/lapackppTargets-noconfig.cmake
-- Installing: /.../lapack/build4/lib/cmake/lapackpp/lapackppConfig.cmake
-- Installing: /.../lapack/build4/lib/cmake/lapackpp/lapackppConfigVersion.cmake

CMakeLists.txt Outdated
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfigVersion.cmake"
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple other files; see above for easier fix.

CMakeLists.txt Outdated
-D BLAS_LIBRARIES="${BLAS_LIBRARIES}"
-D LAPACK_LIBRARIES="${LAPACK_LIBRARIES}" )
endif()
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 add_custom_command blocks are quite redundant. May I suggest setting some variables to have one 1 instance? See my top-level review comment for suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redundancy is because we cannot use CMake generator expressions (e.g., $<TARGET_FILE:${LAPACKLIB}>) to set CMake variables at configuration time. See https://stackoverflow.com/questions/51353110/how-do-i-output-the-result-of-a-generator-expression-in-cmake. There is certainly a better way to do this, but I couldn't figure it out.

CMakeLists.txt Outdated
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfigVersion.cmake"
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/lapackpp/lapackppConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
)

endif()
if (BLAS++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LAPACK++ requires BLAS++, so as above, I think this should be if (BLAS++ OR LAPACK++).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With cmake -D LAPACK++=on .., this will build BLAS++ and LAPACK++, but doesn't install libblaspp.a. Changing to if (BLAS++ or LAPACK++) fixes the issue. Can be merged with if block below (line 650).

@weslleyspereira
Copy link
Collaborator Author

Even with the changes from this commit. I am still having trouble to use the flag LAPACK++. See icl-utk-edu/lapackpp#50

@weslleyspereira
Copy link
Collaborator Author

The AppVeyor script needs some change. I will open an issue for that.

This PR is ready to be merged.

@weslleyspereira
Copy link
Collaborator Author

@mgates3, could you review the current stage of this PR. I think this is ready to merge. Thanks!

Copy link
Contributor

@mgates3 mgates3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the patch that worked for me:

sh leconte lapack> git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 17609c05d..89db6a866 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -633,21 +633,19 @@ install(FILES
 
 if (LAPACK++)
   install(
-    DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
+    DIRECTORY "${LAPACK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/"
     DESTINATION ${CMAKE_INSTALL_LIBDIR}
     FILES_MATCHING REGEX "lapackpp"
   )
 endif()
 
-if (BLAS++)
+if (BLAS++ OR LAPACK++)
   install(
-    DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
+    DIRECTORY "${LAPACK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/"
     DESTINATION ${CMAKE_INSTALL_LIBDIR}
     FILES_MATCHING REGEX "blaspp"
   )
-endif()
 
-if (BLAS++ OR LAPACK++)
   install(
     DIRECTORY "${LAPACK_BINARY_DIR}/include/"
     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"

Otherwise, looks good. I tested on macOS with GNU compilers and OpenBLAS, and on Linux (Redhat) with GNU compilers, Intel MKL, and CUDA.

One minor issue, on Linux it said

-- Build files have been written to: /home/mgates/repos/lapack/build2/_deps/lapackpp-build
gmake[3]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.

and then run make in serial instead of parallel, so it was rather slow. Not a big deal.

CMakeLists.txt Outdated
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING REGEX "libblaspp.(a|so)$"
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, it put them in ${LAPACK_BINARY_DIR}/lib64, so it find libblaspp.a and liblapackpp.a to install:

sh leconte build2> pwd
/home/mgates/repos/lapack/build2

sh leconte build2> ls lib lib64
lib:
liblapack.a

lib64:
cmake  libblaspp.a  liblapackpp.a

sh leconte build2> ls ~/install-test/lib64/
cmake  liblapack.a  pkgconfig

On macOS, it put them in ${LAPACK_BINARY_DIR}/lib, and everything worked (with previously mentioned fix about if (BLAS++ or LAPACK++)):

pangolin lapack/build3> pwd
/Users/mgates/Documents/lapack/build3

pangolin lapack/build3> ls lib
cmake/  libblaspp.a  liblapack.a  liblapackpp.a

pangolin lapack/build3> ls ~/install-test/lib/
cmake/  libblaspp.a  liblapack.a  liblapackpp.a  pkgconfig/

CMakeLists.txt Outdated
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/lapackpp/lapackppConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/"
DIRECTORY "${LAPACK_BINARY_DIR}/lib/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as below; use ${CMAKE_INSTALL_LIBDIR}.

@mgates3
Copy link
Contributor

mgates3 commented Nov 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flag BLAS++ seems not to be working properly
2 participants