Skip to content

Instantly share code, notes, and snippets.

@mdouze
Created September 6, 2022 09:28
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mdouze/2b96e804ee2825e72323c0a296061c7e to your computer and use it in GitHub Desktop.
Save mdouze/2b96e804ee2825e72323c0a296061c7e to your computer and use it in GitHub Desktop.
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
bash ./Miniconda3-latest-MacOSX-arm64.sh
. $HOME/miniconda3/etc/profile.d/conda.sh
conda install python
conda install numpy
conda install swig
conda install cmake
export PATH=$HOME/miniconda3/bin:$PATH
git clone https://github.com/facebookresearch/faiss.git
cd faiss
cmake -B build -DBUILD_TESTING=ON -DFAISS_ENABLE_GPU=OFF \
-DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_C_API=ON \
-DPython_EXECUTABLE=$(which python)
make -k -C build -j faiss
# C++ tests do not work
# make -C build test
make -C build -j swigfaiss
cd build/faiss/python
python3 setup.py build
cd -
cd tests
PYTHONPATH=../build/faiss/python/build/lib/ python3 -m unittest discover
@yunjiangster
Copy link

How did you solve the following issue

-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindOpenMP.cmake:545 (find_package_handle_standard_args)
  faiss/CMakeLists.txt:240 (find_package)

@yunjiangster
Copy link

OK I figured it out.

conda install libomp

cmake -B build -DBUILD_TESTING=ON -DFAISS_ENABLE_GPU=OFF \
     -DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_C_API=ON \
     -DPython_EXECUTABLE=$(which python) \
    -DOpenMP_C_FLAGS=-fopenmp=lomp -DOpenMP_CXX_FLAGS=-fopenmp=lomp \
    -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
    -DOpenMP_libomp_LIBRARY="$HOME/miniconda3/lib/libomp.dylib" \
    -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp $HOME/miniconda3/lib/libomp.dylib \
    -I$HOME/miniconda3/include" -DOpenMP_CXX_LIB_NAMES="libomp" \
    -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp  -I$HOME/miniconda3/include"

@moscicky
Copy link

or install via brew:

brew install libomp

and add:

    -DOpenMP_C_FLAGS=-fopenmp=lomp \
    -DOpenMP_CXX_FLAGS=-fopenmp=lomp \
    -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
    -DOpenMP_libomp_LIBRARY="/opt/homebrew/opt/libomp/lib/libomp.dylib" \
    -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp /opt/homebrew/opt/libomp/lib/libomp.dylib \
    -I/opt/homebrew/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="libomp" \
    -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp  --I/opt/homebrew/opt/libomp/include"

@bastos
Copy link

bastos commented Mar 22, 2023

✌️

brew install miniconda
brew install libomp

conda install python
conda install numpy
conda install swig
conda install cmake

cmake -B build -DBUILD_TESTING=ON -DFAISS_ENABLE_GPU=OFF \
  -DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_C_API=ON \
  -DPython_EXECUTABLE=$(which python) \
  -DOpenMP_C_FLAGS=-fopenmp=lomp \
  -DOpenMP_CXX_FLAGS=-fopenmp=lomp \
  -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" \
  -DOpenMP_libomp_LIBRARY="/opt/homebrew/opt/libomp/lib/libomp.dylib" \
  -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp /opt/homebrew/opt/libomp/lib/libomp.dylib \
    -I/opt/homebrew/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="libomp" \
  -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp  --I/opt/homebrew/opt/libomp/include"

make -k -C build -j faiss
make -C build -j swigfaiss

cd build/faiss/python
python3 setup.py build
cd - 
cd tests
PYTHONPATH=../build/faiss/python/build/lib/ python3 -m unittest discover

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment