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 compile against lapack-3.10.0 - part 1 #21114
Conversation
Fixes #21116 |
This change breaks Linux builds - LAPACK becomes disabled. |
actually, it fixes linux builds. On systems with modern versions of lapack. |
I assume for this to be accepted it has to work with both old and modern versions of LAPACK? Could this be done by checking for both #ifdef OPENCV_USE_OLD_LAPACK
# define LAPACK_sposv_ sposv_
#endif ? |
@dwardor could you please add checks (to stay compatible with older lapack versions)? And also merge another PR (the part2) here, as, actually, it seems to be related to the same exact issue, so no need to split it to another PR, IMO. |
@dwardor, thank you for the patch! I'm sure, it's useful, but I think we need to do it in a proper way:
then you should define or not OPENCV_USE_LAPACK_PREFIX, depending on the version. |
Just pushed a new version that should be more generic per vpisarev's recommendations
This still works on gentoo with lapack 3.10.0 by configuring OPENCV_USE_LAPACK_PREFIX=ON via ebuild Tried but failed to figure out how to test lapack version in OpenCVFindLAPACK.cmake (am a cmake noob). |
CMakeLists.txt
Outdated
@@ -527,6 +527,8 @@ OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target | |||
OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) | |||
OCV_OPTION(ENABLE_FLAKE8 "Add target with Python flake8 checker" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) | |||
|
|||
OCV_OPTION(OPENCV_USE_LAPACK_PREFIX "Use LAPACK_ prefix for function calls with lapack >= 3.9.1." OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about setting it to "ON" based on detected lapack version (to ease downstream maintenance work)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great to me! Just haven't figured out how to do it
This autodetects LAPACK_VERSION, at least on my gentoo box, and activates OPENCV_USE_LAPACK_PREFIX automatically... I've only used LAPACK_FUNC to the function that strictly need it... My gut feeling is :
|
Been looking through all lapack-release versions... and c/c++ interfaces appeared back in 3.4.0 :
So just using LAPACK_xxxx in opencv source and letting the preprocessor macros do their job is the universal solution for anything above lapack-3.4.0. Am I right in saying no one is compiling opencv vs. anything <3.4.0 as it contains no c/c++ interface ? LAPACK_NAME(lcname,UCNAME) was replaced by LAPACK_GLOBAL(lcname,UCNAME) in lapack-3.4.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for update!
Please take a look on comments below.
cmake/OpenCVFindLAPACK.cmake
Outdated
@@ -156,8 +163,16 @@ if(WITH_LAPACK) | |||
if(WIN32 AND NOT OPENCV_LAPACK_SHARED_LIBS) | |||
set(BLA_STATIC 1) | |||
endif() | |||
find_package(LAPACK) | |||
find_package(LAPACK CONFIG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONFIG
Why do we need to block CMake's LAPACK module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just use CONFIG so as to have access to LAPACK_VERSION. If I don't add CONFIG LAPACK_VERSION is undefined.
cmake/OpenCVFindLAPACK.cmake
Outdated
#ifdef OPENCV_USE_LAPACK_PREFIX | ||
#define LAPACK_FUNC(f) LAPACK_##f | ||
#else | ||
#define LAPACK_FUNC(f) f##_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK_FUNC
Please use OPENCV_
/ OCV_
prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
cmake/OpenCVFindLAPACK.cmake
Outdated
@@ -51,6 +51,13 @@ macro(ocv_lapack_check) | |||
if(NOT "${OPENCV_CBLAS_H_PATH_${_lapack_impl}}" STREQUAL "${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}") | |||
list(APPEND _lapack_content "#include \"${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}\"") | |||
endif() | |||
list(APPEND _lapack_content " | |||
#ifdef OPENCV_USE_LAPACK_PREFIX | |||
#define LAPACK_FUNC(f) LAPACK_##f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-DOPENCV_USE_LAPACK_PREFIX=LAPACK_
It makes sense to define prefix in CMake.
Moreover, we don't need global compiler definition at all.
It is a generated file. So generate this content through CMake conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will remove the global alltogether and generate based in CMake conditions
I'd prefer we use #21291 instead of this as per #21114 (comment) Update : #21291 is dead due to imcompatibility with Accelerate LAPACK implementation so this pullrequest seems the way to move forward |
Only issue seems to be Mac build (just a warning ?)... @alalek I don't know how to debug this as I don't have a Mac... |
Fix compilation against lapack >= 3.9.1 and 3.10.0 while not breaking older versions OpenCVFindLAPACK.cmake & CMakeLists.txt: determine OPENCV_USE_LAPACK_PREFIX from LAPACK_VERSION hal_internal.cpp : Only apply LAPACK_FUNC to functions whose number of inputs depends on LAPACK_FORTRAN_STR_LEN in lapack >= 3.9.1 lapack_check.cpp : remove LAPACK_FUNC which is not OK as function are not used with input parameters (so lapack.h preprocessing of "LAPACK_xxxx(...)" is not applicable with lapack >= 3.9.1 If not removed lapack_check fails so LAPACK is deactivated in build (not want we want) use OCV_ prefix and don't use Global, instead generate OCV_LAPACK_FUNC depending on CMake Conditions Remove CONFIG from find_package(LAPACK) and use LAPACK_GLOBAL and LAPACK_NAME to figure out if using netlib's reference LAPACK implementation and how to #define OCV_LAPACK_FUNC(f)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the various pointers on the way. @alalek will this also make it into opencv:4.x ? |
Changes to 4.x will be propagated automatically during the next "Merge-3.4" PR: https://github.com/opencv/opencv/wiki/Branches |
TODO:
update builders configuration (to resolve Mac builder report) if it is not caused byremovedCONFIG
usage in find_packageCONFIG
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.