asg017 / sqlite-vss

A SQLite extension for efficient vector search, based on Faiss!
MIT License
1.59k stars 59 forks source link

Compile failure on M1 Mac: Missing OpenMP #44

Closed zackangelo closed 1 year ago

zackangelo commented 1 year ago

Trying to compile from source on Mac OS X Ventura (M1), getting this error:

❯ make loadable
cmake -B build; make -C build
CMake Error at /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/FindOpenMP.cmake:577 (find_package_handle_standard_args)
  vendor/faiss/faiss/CMakeLists.txt:253 (find_package)

-- Configuring incomplete, errors occurred!
make[1]: *** No targets specified and no makefile found.  Stop.
make: *** [dist/debug/vector0.dylib] Error 2

Any ideas? I've tried installing libomp using homebrew but that didn't seem to help.

zackangelo commented 1 year ago

I can build faiss in ./vendor/faiss manually and it works using this command:

LDFLAGS="-L/opt/homebrew/opt/llvm/lib" CPPFLAGS="-I/opt/homebrew/opt/llvm/include" CXX=/opt/homebrew/opt/llvm/bin/clang++ CC=/opt/homebrew/opt/llvm/bin/clang cmake -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=OFF -B build .

When I try to specify those same environment variables for make loadable, it doesn't work.

zackangelo commented 1 year ago

Was able to get it to compile, but had to compile faiss separately (and comment out out the add_subdirectory call).

I also had to change this line to omit the avx2 version of the faiss library: https://github.com/asg017/sqlite-vss/blob/2d0dd01d3dfaf76a1bd4fe7225c4d71c8d011977/CMakeLists.txt#L52

I don't know anything about CMake, but it seems like hard coding an Intel-specific library name would cause problems on ARM macs?

asg017 commented 1 year ago

Hey @zackangelo , apologies for that, I've been meaning to update the docs for compiling sqlite-vss on a Mac M1. A few questions:

  1. Can you try the following flags with make loadable?
export CC="/opt/homebrew/opt/llvm/bin/clang"
export CXX="/opt/homebrew/opt/llvm/bin/clang++"
export LDFLAGS="-L/opt/homebrew/opt/libomp/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libomp/include"

They are almost the same as the ones you list, but the LDFLAGS and CPPFLAGS are referencing libomp instead of llvm

  1. Can you try downloading the pre-compiled sqlite-vss-v0.1.1-alpha.13-loadable-macos-aarch64.tar.gz and see if you can load those vector0.dylib and vss0.dylib extensions? You might have to curl or wget that file directly instead of downloading manually through the browser, to avoid CSP stuff. Those are pre-compiled on a M2 machine and I'm not sure if they'll work probably on an M1

And re faiss_avx2: that's odd, it seems to work on my M2. Not sure if the Rosetta in M2 is able to translate avx2 while M1 can't, I'm not familiar with that. If it doesn't work with the new env vars, try replacing that like with faiss instead of faiss_avx2 and see if that works as expected

zackangelo commented 1 year ago

Thanks for the help! I'll try those env vars little later today.

I did try downloading the pre-compiled version, but the archive only contained vector0.dylib, it was missing vss0.dylib.

asg017 commented 1 year ago

The latest "alpha' releases should have both vector0.dylib and vss0.dylib, you can try here with sqlite-vss-v0.1.1-alpha.13-loadable-macos-aarch64.tar.gz https://github.com/asg017/sqlite-vss/releases/tag/v0.1.1-alpha.13

I'll be publishing v0.1.1 soon