Rate This Document
Findability
Accuracy
Completeness
Readability

Compiling Faiss

Obtain the Faiss open source code from GitCode, install the required dependencies, and then compile Faiss.

  1. Obtain the Faiss open source code. The tag is v1.8.0. Assume that the code is stored in /path/to/faiss.
    git clone --branch v1.8.0 --single-branch https://github.com/facebookresearch/faiss.git
  2. Obtain the patch file 0001-boostsra-faiss-1.8.0.patch optimized for Kunpeng. The tag is v1.8.0-2512. Assume that the patch file is stored in /path/to/faiss-patch.
    git clone --branch v1.8.0-2512 https://gitcode.com/boostkit/faiss.git
  3. Install Make, CMake, and GCC.
    yum install make cmake gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-libstdc++-static gcc-toolset-12-gcc-gfortran
    export PATH=/opt/openEuler/gcc-toolset-12/root/usr/bin/:$PATH
    export LD_LIBRARY_PATH=/opt/openEuler/gcc-toolset-12/root/usr/lib64/:$LD_LIBRARY_PATH
  4. Faiss depends on the math library. Download the open source OpenBLAS source code from the GitHub repository using the v0.3.29 tag. Save the file to a path accessible to the compiler, such as /path/to/OpenBLAS-0.3.29.
    git clone --branch v0.3.29 --single-branch https://github.com/OpenMathLib/OpenBLAS.git
  5. Compile the source code to obtain libopenblas.so.
    cd /path/to/OpenBLAS-0.3.29/OpenBLAS
    make
    make install

    You can run the make install PREFIX=/path/to/openblas/install command to specify the installation path /path/to/openblas/install. The default installation path is /opt/OpenBLAS.

  6. Install the patch file 0001-boostsra-faiss-1.8.0.patch.
    cd /path/to/faiss
    patch -p1 < /path/to/faiss-patch/0001-boostsra-faiss-1.8.0.patch
  7. Compile the Faiss code to obtain libfaiss.so.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    cd /path/to/faiss
    cmake -B build . \
      -DFAISS_ENABLE_GPU=OFF \
      -DBUILD_TESTING=OFF \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DFAISS_OPT_LEVEL=generic \
      -DFAISS_ENABLE_PYTHON=OFF \
      -DMKL_LIBRARIES=/opt/OpenBLAS/lib/libopenblas.so
    make -C build -j faiss
    make -C build install
    
    • You can add the compilation option -DCMAKE_INSTALL_PREFIX=/path/to/faiss/install to specify the installation path /path/to/faiss/install. The default installation path is /usr/local.
    • The compilation option -DMKL_LIBRARIES must be set to the installation path of OpenBLAS in step 4.
    • If the error message "CMake 3.23.1 or higher is required. You are running version 3.22.0" is displayed, change cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR) to cmake_minimum_required(VERSION 3.22.0 FATAL_ERROR) in line 21 of the /path/to/faiss/CMakeLists.txt file.