Skip to content

Commit f65108b

Browse files
authored
[1.7.1] Fix LAPACK functionality detection from static OpenBLAS (pytorch#48819)
Summary: BLAS `sgemm_` only depends on pthreads, but LAPACK `cheev_` also depends on libm Pull Request resolved: pytorch#46710 Reviewed By: walterddr Differential Revision: D24476082 Pulled By: malfet fbshipit-source-id: e0b91116f18bbcdabb1f99c2ec9d98283df4393f
1 parent 1d9b64d commit f65108b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

cmake/Dependencies.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,7 @@ if(NOT INTERN_BUILD_MOBILE)
16231623
find_package(LAPACK)
16241624
if(LAPACK_FOUND)
16251625
set(USE_LAPACK 1)
1626+
list(APPEND Caffe2_PRIVATE_DEPENDENCY_LIBS ${LAPACK_LIBRARIES})
16261627
endif()
16271628

16281629
if(NOT USE_CUDA)

cmake/Modules/FindBLAS.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ if((NOT BLAS_LIBRARIES)
153153
BLAS
154154
sgemm
155155
""
156-
"openblas;pthread")
156+
"openblas;pthread;m")
157157
if(BLAS_LIBRARIES)
158158
set(BLAS_INFO "open")
159159
endif(BLAS_LIBRARIES)

cmake/Modules/FindLAPACK.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ if(BLAS_FOUND)
123123
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "open"))
124124
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
125125
check_function_exists("cheev_" OPEN_LAPACK_WORKS)
126+
if(OPEN_LAPACK_WORKS)
127+
check_function_exists("cgesdd_" LAPACK_CGESDD_WORKS)
128+
if(NOT LAPACK_CGESDD_WORKS)
129+
find_library(GFORTRAN_LIBRARY
130+
NAMES libgfortran.a gfortran
131+
PATHS /usr/lib/gcc/aarch64-linux-gnu/9/
132+
/usr/lib/gcc/x86_64-redhat-linux/9/
133+
/usr/lib/gcc/aarch64-linux-gnu/8/
134+
/usr/lib/gcc/x86_64-redhat-linux/8/
135+
/usr/lib/gcc/aarch64-linux-gnu/7/
136+
/usr/lib/gcc/x86_64-redhat-linux/7/
137+
)
138+
list(APPEND CMAKE_REQUIRED_LIBRARIES "${GFORTRAN_LIBRARY}")
139+
unset(LAPACK_CGESDD_WORKS CACHE)
140+
check_function_exists("cgesdd_" LAPACK_CGESDD_WORKS)
141+
if(LAPACK_CGESDD_WORKS)
142+
list(APPEND LAPACK_LIBRARIES "${GFORTRAN_LIBRARY}")
143+
else()
144+
message(WARNING "OpenBlas has been compiled with Lapack support, but cgesdd can not be used")
145+
set(OPEN_LAPACK_WORKS NO)
146+
endif()
147+
endif()
148+
endif()
149+
126150
set(CMAKE_REQUIRED_LIBRARIES)
127151
if(OPEN_LAPACK_WORKS)
128152
SET(LAPACK_INFO "open")

0 commit comments

Comments
 (0)