faisss的重建之路

haojunyu 4447a37477 add indexflat 6 months ago
.devcontainer 4447a37477 add indexflat 6 months ago
.vscode 4447a37477 add indexflat 6 months ago
faiss_study 4447a37477 add indexflat 6 months ago
.clang-format 6da45b4df9 init commit 6 months ago
.dockerignore 6da45b4df9 init commit 6 months ago
.gitignore 5753dd5ec0 comment exception 6 months ago
CMakeLists.txt 4447a37477 add indexflat 6 months ago
Makefile 4447a37477 add indexflat 6 months ago
README.md 4447a37477 add indexflat 6 months ago

README.md

faiss_study

编译

# cmake 构建
cmake -B build .  -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=ON

# 编译
make -C build faiss_study

# python
make -C build swigfaiss
cd build/faiss/python && python3 setup.py install

CMake 构建的选项:

  • -DFAISS_ENABLE_GPU=OFF 是否(ON/OFF)构建 GPU 版本
  • -DFAISS_ENABLE_PYTHON=OFF 是否(ON/OFF)构建 python
  • -DBUILD_TESTING=OFF in order to disable building C++ tests,
  • -DBUILD_SHARED_LIBS=ON in order to build a shared library (possible values are ON and OFF),
  • optimization-related options:
  • -DCMAKE_BUILD_TYPE=Release in order to enable generic compiler optimization options (enables -O3 on gcc for instance),
  • -DFAISS_OPT_LEVEL=avx2 in order to enable the required compiler flags to generate code using optimized SIMD instructions (possible values are generic, sse4, and avx2, by increasing order of optimization),
  • BLAS-related options:
  • -DBLA_VENDOR=Intel10_64_dyn -DMKL_LIBRARIES=/path/to/mkl/libs to use the Intel MKL BLAS implementation, which is significantly faster than OpenBLAS (more information about the values for the BLA_VENDOR option can be found in the CMake docs),
  • GPU-related options:
  • -DCUDAToolkit_ROOT=/path/to/cuda-10.1 in order to hint to the path of the CUDA toolkit (for more information, see CMake docs),
  • -DCMAKE_CUDA_ARCHITECTURES="75;72" for specifying which GPU architectures to build against (see CUDA docs to determine which architecture(s) you should pick),
  • python-related options:
  • -DPython_EXECUTABLE=/path/to/python3.7 in order to build a python interface for a different python than the default one (see CMake docs).

python集成 (可选)

$ make -C build -j swigfaiss
$ (cd build/faiss/python && python setup.py install)
# vscode中使用的编译命令(amd64)
$ make -C build swigfaiss
$ cd build/faiss/python && python3 setup.py install

The first command builds the python bindings for Faiss, while the second one generates and installs the python package.

安装库和头文件(可选)

$ make -C build install
# vscode中使用的编译命令(amd64)
$ make -C build install

This will make the compiled library (either libfaiss.a or libfaiss.so on Linux) available system-wide, as well as the C++ headers. This step is not needed to install the python package only.