faiss icon indicating copy to clipboard operation
faiss copied to clipboard

Linking CXX executable faiss_test fails : ../faiss/libfaiss_avx2.so: undefined reference to `sgeqrf_'

Open averatio opened this issue 2 years ago • 4 comments
trafficstars

Summary

Platform

OS:[ ] Linux Debian Python 3.10

Faiss version: 1.7.3

Installed from: source code

Faiss compilation options: cmake -B build . -DFAISS_ENABLE_GPU=OFF -DBLA_VENDOR=Intel10_64_dyn -DFAISS_OPT_LEVEL=avx2 -DBUILD_SHARED_LIBS=ON -DFAISS_ENABLE_C_API=ON -DMKL_LIBRARIES=$MKL_HOME

Running on:

  • [x ] CPU
  • [ ] GPU

Interface:

  • [x ] C++
  • [ ] Python

Reproduction instructions

Hi All All this works:

cmake -B build . -DFAISS_ENABLE_GPU=OFF -DBLA_VENDOR=Intel10_64_dyn -DFAISS_OPT_LEVEL=avx2 -DBUILD_SHARED_LIBS=ON -DFAISS_ENABLE_C_API=ON -DMKL_LIBRARIES=$MKL_HOME
make -C build -j faiss
make -C build -j swigfaiss
(cd build/faiss/python && python setup.py install)

Python faiss lib works, however,

make -C build install

fails with link error:

Linking CXX executable faiss_test
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sgeqrf_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sgesvd_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `dsyev_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `dgemm_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `dgetrf_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sgetrf_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `ssyrk_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sgelsd_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `dgesvd_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sgemm_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sorgqr_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `sgetri_'
/usr/bin/ld: ../faiss/libfaiss_avx2.so: undefined reference to `dgetri_'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/faiss_test.dir/build.make:358: tests/faiss_test] Error 1
make[2]: Leaving directory '/faiss-1.7.3/build'
make[1]: Leaving directory '/faiss-1.7.3/build'
make[1]: *** [CMakeFiles/Makefile2:1593: tests/CMakeFiles/faiss_test.dir/all] Error 2
make: Leaving directory '/faiss-1.7.3/build'
make: *** [Makefile:146: all] Error 2

I looked at various mailing lists and found some guidance but no advice worked yet. Any clue or advice will be greatly appreciated.

regards

averatio avatar Feb 01 '23 08:02 averatio

This is an MKL linking issue

mdouze avatar Feb 13 '23 03:02 mdouze

Did you manage to resolve this? I have a similar linking problem.

(What is MKL?)

arjenpdevries avatar May 20 '23 14:05 arjenpdevries

@averatio @mdouze @arjenpdevries I spent some time finding a solution to this problem. After building cmake 3.26 from source, and then reading the source for cmake, I found an obscure reference to the need to use a specific environment setup script in /opt/intel.

The full build process (minus cmake) is here:

https://github.com/artificialwisdomai/origin/wiki/Build-from-source

Thank you -steve

sdake avatar Jun 11 '23 12:06 sdake

This seems to be an issue that occurs when DBUILD_TESTING=ON, and it's a problem with a missing link to liblapack. If you set DBUILD_TESTING to OFF, libfaiss_avx2.so will be generated successfully, but it reports this error when it is used. This problem occurs because in faiss/faiss/CMakeLists.txt, it checks if MKL is found, and if it is found, it doesn't link LAPACK, but when compiling the test, it need this. My solution is to make it link LAPACK under the condition that MKL_FOUND=True in this CMakeLists.txt: ''' if(MKL_FOUND) target_link_libraries(faiss PRIVATE ${MKL_LIBRARIES}) target_link_libraries(faiss_avx2 PRIVATE ${MKL_LIBRARIES}) target_link_libraries(faiss_avx512 PRIVATE ${MKL_LIBRARIES}) find_package(LAPACK REQUIRED) target_link_libraries(faiss PRIVATE ${LAPACK_LIBRARIES}) target_link_libraries(faiss_avx2 PRIVATE ${LAPACK_LIBRARIES}) target_link_libraries(faiss_avx512 PRIVATE ${LAPACK_LIBRARIES}) else() ... ''' I tried many other attempts to solve this issue, but this is what I think is the most crucial.

Dtristone avatar Mar 19 '24 09:03 Dtristone