Those instructions are working for me as of January 2017, 2018. Using Homebrew and maOS 10.13.2
xcode-select --install
brew install llvm
Make sure /usr/local/opt/llvm/bin
is in your PATH
brew install openblas
Go into your conda environment and run
conda install swig
which swig
should show the path to your swig install in your environment.
git clone https://github.com/facebookresearch/faiss.git
Open the IndexScalarQuantizer.cpp and comment out the include <malloc.h> instruction:
--- a/IndexScalarQuantizer.cpp
+++ b/IndexScalarQuantizer.cpp
@@ -11,7 +11,7 @@
#include <cstdio>
#include <algorithm>
-#include <malloc.h>
+//#include <malloc.h>
#include <omp.h>
Create a makefile.inc in the root directory of faiss with the following content:
# -*- makefile -*-
CC=/usr/local/opt/llvm/bin/clang++
CFLAGS=-fPIC -m64 -Wall -g -O3 -msse4 -mpopcnt -fopenmp -Wno-sign-compare -I/usr/local/opt/llvm/include -std=c++11 -I/usr/local/opt/openblas/include
LDFLAGS=-g -fPIC -fopenmp -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/opt/openblas/lib
# common mac flags
SHAREDEXT=dylib
SHAREDFLAGS=-Wl,-F. -bundle -undefined dynamic_lookup
FAISSSHAREDFLAGS=-dynamiclib
BLASCFLAGS=-DFINTEGER=int
BLASLDFLAGS=/usr/local/opt/openblas/lib/libopenblas.dylib
SWIGEXEC=$(shell which swig)
PYTHON_INC=$(shell python -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())")
NUMPY_INC=$(shell python -c "import numpy ; print(numpy.get_include())")
PYTHONCFLAGS=-I${PYTHON_INC} -I${NUMPY_INC}
Go into the faiss directory and run:
make tests/test_blas
Then run:
./tests/test_blas
Run:
make
A basic usage example is in
tests/demo_ivfpq_indexing
Run in ~10s on a 2017 Macbook Pro
Run:
make py
and test:
python -c "import faiss"
In order to use faiss in your own code, you'll have the copy the files in faiss/python to your own project. See more details here: https://github.com/facebookresearch/faiss/blob/master/INSTALL.md#python