Faiss使能KRL
用户可通过使能KRL算子的形式对开源Faiss的HNSW、PQFS、IVFPQ、IVFPQFS算法进行加速。获取开源Faiss代码,合入Faiss 1.8.0使能KRL所需的补丁文件,最后编译出使能KRL后的动态库文件。
操作步骤
- 从GitHub仓下载开源Faiss源代码,标签为v1.8.0。保存在编译机器可访问的路径中,假设位于“/path/to/faiss-1.8.0”。
1git clone --branch v1.8.0 --single-branch https://github.com/facebookresearch/faiss.git
- 安装Make、CMake、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依赖数学库,从Github仓下载开源OpenBLAS源代码,标签为v0.3.29。保存在编译机器可访问的路径中,假设位于“/path/to/OpenBLAS-0.3.29”。
git clone --branch v0.3.29 --single-branch https://github.com/OpenMathLib/OpenBLAS.git
- 编译源代码获取libopenblas.so。
cd /path/to/OpenBLAS-0.3.29/OpenBLAS make make install
可通过make install PREFIX=/path/to/openblas/install设置“/path/to/openblas/install”以指定安装路径,默认安装路径为“/opt/OpenBLAS”。
- 安装Faiss 1.8.0使能KRL所需的补丁文件0001-faiss1.8.0-add-krl.patch,该文件由获取软件包解压软件包后获得的。
cd /path/to/faiss-1.8.0/faiss patch -p1 < 0001-faiss-1.8.0-add-krl.patch
- 编译Faiss代码获取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
- 可通过在编译时添加编译选项-DCMAKE_INSTALL_PREFIX=/path/to/faiss/install设置“/path/to/faiss/install”以指定安装路径,默认安装路径为“/usr/local”。
- 编译选项-DMKL_LIBRARIES需指定为步骤3中OpenBLAS的安装路径。
父主题: KRL使用说明