编译Faiss
从GitCode获取Faiss开源代码,安装必要的依赖工具和库后编译Faiss。
- 获取Faiss开源代码,标签为v1.8.0。假设代码存放于“/path/to/faiss”。
git clone --branch v1.8.0 --single-branch https://github.com/facebookresearch/faiss.git
- 获取基于鲲鹏优化的补丁文件0001-boostsra-faiss-1.8.0.patch,标签为v1.8.0-2512。假设存放于“/path/to/faiss-patch”。
git clone --branch v1.8.0-2512 https://gitcode.com/boostkit/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”。
- 安装补丁文件0001-boostsra-faiss-1.8.0.patch。
cd /path/to/faiss patch -p1 < /path/to/faiss-patch/0001-boostsra-faiss-1.8.0.patch
- 编译Faiss代码获取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
- 可通过在编译时添加编译选项-DCMAKE_INSTALL_PREFIX=/path/to/faiss/install设置“/path/to/faiss/install”以指定安装路径,默认安装路径为“/usr/local”。
- 编译选项-DMKL_LIBRARIES需指定为步骤4中OpenBLAS的安装路径。
- 若出现“CMake 3.23.1 or higher is required. You are running version 3.22.0”相关报错,可修改“/path/to/faiss/CMakeLists.txt”文件第21行内容,将“cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)”修改为“cmake_minimum_required(VERSION 3.22.0 FATAL_ERROR)”。
父主题: 安装配置环境