Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2017 23:42
Show Gist options
  • Save anonymous/1c69d086db5b7aa69542cc735c5b92c5 to your computer and use it in GitHub Desktop.
Save anonymous/1c69d086db5b7aa69542cc735c5b92c5 to your computer and use it in GitHub Desktop.
function install_faiss() {
pyenv shell rise
pip install numpy
sudo apt-get install -y \
build-essential \
libopenblas-dev \
gfortran \
swig
PREFIX_MAIN=$(pyenv virtualenv-prefix)
SITE_PACKAGES=$(venv_site_packages)
PYTHON_NUMPY_INCLUDE_DIR="${SITE_PACKAGES}/numpy/core/include/"
PYTHON_INCLUDE_DIR="$(echo "${PREFIX_MAIN}/include/python"*"m")/"
# Download Facebook Faiss library source code
cd "${CODE_PATH}"
git clone --depth 1 https://github.com/facebookresearch/faiss.git -b "${FAISS_BRANCH}"
cd "${CODE_PATH}/faiss"
# Setup makefile
cp example_makefiles/makefile.inc.Linux makefile.inc
echo "PYTHONCFLAGS=-I${PYTHON_INCLUDE_DIR} -I${PYTHON_NUMPY_INCLUDE_DIR}" \
>> makefile.inc
export BLASLDFLAGS="/usr/lib/libopenblas.so.0"
# Compile faiss
make -j "${NPROC}"
# Create python bindings
make py
if is_cuda_compatible; then
# Compile GPU version
cd "${CODE_PATH}/faiss/gpu"
make -j "${NPROC}"
make py
cd "${CODE_PATH}/faiss"
else
echo "No NVIDIA GPU detected, skipping faiss gpu install"
fi
# Copy python modules to python system path
cp -- *.py *.so "$(venv_site_packages)/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment