Enabling KRL in Faiss
You can enable the KRL operators to accelerate Faiss-supported algorithms, including HNSW, PQFS, IVFPQ, and IVFPQFS. Obtain the open source Faiss 1.8.0 code, apply the patch required for enabling KRL, and compile the dynamic library with KRL acceleration enabled.
Procedure
- Download the Faiss source code from the GitHub repository using the v1.8.0 tag. Save the file to a path, for example, /path/to/faiss-1.8.0, that can be accessed by a compilation computer.
1git clone --branch v1.8.0 --single-branch https://github.com/facebookresearch/faiss.git
- 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
- 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, for example, /path/to/OpenBLAS-0.3.29, that can be accessed by the compilation computer.
git clone --branch v0.3.29 --single-branch https://github.com/OpenMathLib/OpenBLAS.git
- 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.
- Install the patch file 0001-faiss1.8.0-add-krl.patch file. The patch file is obtained from the extracted package in Obtaining the Software Package.
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: Using KRL