-
-
Notifications
You must be signed in to change notification settings - Fork 55.6k
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
core: deployment compatibility for old mac after Accelerate New LAPACK fix #25625
core: deployment compatibility for old mac after Accelerate New LAPACK fix #25625
Conversation
@seanm Feel free to review. |
@asmorkalov We may need to explicitly add build option |
cmake/OpenCVFindLAPACK.cmake
Outdated
if(LAPACK_IMPL STREQUAL "LAPACK/Apple" AND NOT IOS) # https://github.com/opencv/opencv/issues/24660 | ||
# Get macOS version | ||
execute_process(COMMAND sw_vers -productVersion | ||
OUTPUT_VARIABLE MACOS_VERSION | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
# Enable Accelerate New LAPACK if macOS >= 13.3 | ||
if (MACOS_VERSION VERSION_GREATER "13.3" OR MACOS_VERSION VERSION_EQUAL "13.3") | ||
# Enable Accelerate New LAPACK if target macOS >= 13.3 | ||
if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_GREATER "13.3" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_EQUAL "13.3") | ||
message(STATUS "LAPACK(${LAPACK_IMPL}): Accelerate New LAPACK is enabled.") |
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.
Something else has just occurred to me: this won't work on other Darwin variants (iOS, tvOS, visionOS, etc) because they have different version numbers.
For this reason, the NOT IOS
check would be better as IS MACOS
.
Another alternative is not to do any of this guessing and just let the user/programmer define ACCELERATE_NEW_LAPACK
and ACCELERATE_LAPACK_ILP64
if he wants them.
The most important part is that OpenCV's code contains various #ifdef ACCELERATE_NEW_LAPACK
conditions to support the newer mode (which I believe you did already).
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.
@asmorkalov What do you think?
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.
Friendly ping. (Our build is broken because of this...)
@fengyuentau maybe it would be good to squash your two commits?
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 think the most straightforward and flexible way is to define CMake dependent option for ACCELERATE_LAPACK_NEW
usage and give it reasonable default.
Minimal example:
cmake_minimum_required(VERSION 3.16)
project(LapackOptionCheck LANGUAGES CXX)
include(CMakeDependentOption)
message(STATUS "Current system name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Current system version: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
# Minimal platform versions to use with new interfaces (taken from
# vecLib/blas_new.h availability check)
# macos(13.3), ios(16.4), watchos(9.4), tvos(16.4)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(_min_target_os_version "13.3")
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(_min_target_os_version "16.4")
elseif(CMAKE_SYSTEM_NAME STREQUAL "watchOS")
set(_min_target_os_version "9.4")
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
set(_min_target_os_version "16.4")
else()
# visioOS has at least version 1.0
set(_min_target_os_version "1.0")
endif()
message(STATUS "Min target system version: ${_min_target_os_version}")
if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_GREATER_EQUAL ${_min_target_os_version})
set(_has_required_min_os_version TRUE)
else()
set(_has_required_min_os_version FALSE)
endif()
cmake_dependent_option(OCV_OSX_USE_ACCELERATE_NEW_LAPACK
"Use new BLAS/LAPACK interfaces from Accelerate framework on Apple platform"
ON "APPLE;_has_required_min_os_version" OFF
)
message(STATUS "OCV_OSX_USE_ACCELERATE_NEW_LAPACK: ${OCV_OSX_USE_ACCELERATE_NEW_LAPACK}")
if(OCV_OSX_USE_ACCELERATE_NEW_LAPACK)
message(STATUS "OpenCV will be built with enabled ACCELERATE_NEW_LAPACK")
endif()
Different cases
Everything is default and minimal system version requirement is fulfilled
cmake . -Bbuild
-- Current system name: Darwin
-- Current system version: 13.5
-- Min target system version: 13.3
-- OCV_OSX_USE_ACCELERATE_NEW_LAPACK: ON
-- OpenCV will be built with enabled ACCELERATE_NEW_LAPACK
Minimal system version requirement is fulfilled, but new interface is manually disabled
cmake -DOCV_OSX_USE_ACCELERATE_NEW_LAPACK=OFF . -Bbuild
-- Current system name: Darwin
-- Current system version: 13.5
-- Min target system version: 13.3
-- OCV_OSX_USE_ACCELERATE_NEW_LAPACK: OFF
Everything is default and minimal system version requirement is not fulfilled
cmake -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 . -Bbuild
-- Current system name: iOS
-- Current system version: 15.0
-- Min target system version: 16.4
-- OCV_OSX_USE_ACCELERATE_NEW_LAPACK: OFF
Minimal system version requirement is not fulfilled, so new new interface is manually enabled.
cmake -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 -DOCV_OSX_USE_ACCELERATE_NEW_LAPACK=ON . -Bbuild
-- Current system name: iOS
-- Current system version: 15.0
-- Min target system version: 16.4
-- OCV_OSX_USE_ACCELERATE_NEW_LAPACK: OFF
I guess @seanm wants the old default which builds without Accelerate New LAPACK. I think the problem is how we do with default building:
|
From the evolution point of view, defaults should give better experience out of the box, backward capability can be kept with the manually specified option. If we take a look to Apple realm, new option is set to |
No, I just want to be able to deploy to older versions of macOS. @VadimLevin's example code above looks good to me.
Ultimately, OpenCV should, by default, use @fengyuentau will you update this PR with @VadimLevin's example logic? |
I cannot recall the equivalent in OpenCV CMake. We have only |
It is built-in CMake variable describing target OS, why it should be avoided? |
I thought it was for build host. No problem then. Verified with |
@fengyuentau can you squash into 1 commit?, I think it would be easier to review the final result integrated. |
Not a big fan of squashing as it loses commit history and admin can always merge with squashing. Didn't the tab |
endif() | ||
if(LAPACK_IMPL STREQUAL "LAPACK/Apple" AND OPENCV_OSX_USE_ACCELERATE_NEW_LAPACK) | ||
message(STATUS "LAPACK(${LAPACK_IMPL}): Accelerate New LAPACK is enabled.") | ||
set(LAPACK_TRY_COMPILE_DEF "-DACCELERATE_NEW_LAPACK") |
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 don't think it's necessary to try-compile this, but I guess it's not harmful.
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.
Just to keep aligned with what we are doing.
Sure, but in this case the history is not valuable, as it was all WIP changes.
Never used that before, but it was useful, thanks. This change lgtm and I think it can be merged. (The try-compile I think is unnecessary, but I don't feel strongly about it). |
Attempt to fix #24804 (comment)
We may need to explicitly add build option
-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0
or environment variable (export MACOSX_DEPLOYMENT_TARGET=12.0
) for mac builds (python package most probably) on builders with new macOS (>= 13.3).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.