Enabling KRL in Faiss
Faiss integrates with KRL to enhance the performance of the HNSW, PQFS, IVFPQ, and IVFPQFS algorithms. Users obtain the open source Faiss 1.8.0 code, integrate a patch for enabling KRL, and compile the code to obtain the dynamic library files with KRL performance enhanced.
- Download the Faiss source code from the GitHub repository using the v1.8.0 tag. Save the file to a path accessible to a compilation computer, such as /path/to/faiss-1.8.0.
1git clone --branch v1.8.0 --single-branch https://github.com/facebookresearch/faiss.git
- Install Make, CMake, and GCC 12.
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
- 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 compilation computer, such as /path/to/OpenBLAS-0.3.29.
git clone --branch v0.3.29 --single-branch https://github.com/OpenMathLib/OpenBLAS.git
- Compile the source code to generate the libopenblas.so dynamic library file.
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.
- Unzip BoostKit-boostsra-krl_1.0.0.zip to obtain the patch file 0001-faiss-1.8.0-add-krl.patch required for enabling KRL. Integrate the patch file.
cd /path/to/faiss-1.8.0/faiss patch -p1 < 0001-faiss-1.8.0-add-krl.patch
- Compile the Faiss code to obtain libfaiss.so.
1 2 3 4 5 6 7 8 9 10 11 12
export KRL_PATH=/usr/local/sra_krl cd /path/to/faiss-1.8.0 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 3.
Parent topic: Installing and Configuring the Environment