Skip to content

Commit 29d61e4

Browse files
committed
feat: faiss dep binding with CSR reordering
1 parent 70adecb commit 29d61e4

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

Makefile

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
CXX := g++
22
CXXFLAGS := -std=c++17 -O3 -fPIC -march=native
3+
4+
# Python / pybind11 include flags
35
PYBIND11_INCLUDES := $(shell python3 -m pybind11 --includes)
4-
PYTHON_INCLUDE := $(shell python3-config --includes)
5-
PYTHON_LIB := $(shell python3-config --ldflags)
6-
FAISS_ROOT := extern/faiss/build/install
6+
PYTHON_INCLUDE := $(shell python3-config --includes)
7+
PYTHON_LIB := $(shell python3-config --ldflags)
8+
9+
# Faiss submodule install path
10+
FAISS_ROOT := extern/faiss/build/install
711

12+
# Project includes
813
PROJECT_INCLUDE := -I./include -I./include/zenann
914

10-
ALL_INCLUDES := $(PYBIND11_INCLUDES) $(PYTHON_INCLUDE) $(PROJECT_INCLUDE)
15+
# Aggregate includes
16+
ALL_INCLUDES := $(PYBIND11_INCLUDES) $(PYTHON_INCLUDE) $(PROJECT_INCLUDE) -I$(FAISS_ROOT)/include
17+
18+
# Python linking flags only (faiss linked below)
1119
ALL_LIBS := $(PYTHON_LIB)
1220

13-
ALL_INCLUDES += -I$(FAISS_ROOT)/include
14-
ALL_LIBS += -L$(FAISS_ROOT)/lib -lfaiss
21+
# Source files
22+
SOURCES := \
23+
src/IndexBase.cpp \
24+
src/IVFFlatIndex.cpp \
25+
src/KDTreeIndex.cpp \
26+
src/HNSWIndex.cpp \
27+
python/zenann_pybind.cpp
1528

16-
SOURCES := src/IndexBase.cpp src/IVFFlatIndex.cpp src/KDTreeIndex.cpp python/zenann_pybind.cpp
29+
# Extension suffix (.so or .cpython-XYm-x86_64-linux-gnu.so, etc.)
1730
EXT_SUFFIX := $(shell python3-config --extension-suffix)
1831
TARGET := build/zenann$(EXT_SUFFIX)
1932

33+
# Platform‐specific linker flags
2034
UNAME_S := $(shell uname -s)
2135
ifeq ($(UNAME_S),Darwin)
36+
# on macOS use dynamic_lookup
2237
LDFLAGS := -undefined dynamic_lookup
38+
else
39+
# on Linux embed rpath to pick up our extern/faiss libfaiss.so
40+
LDFLAGS := -Wl,-rpath,$$ORIGIN/../extern/faiss/build/install/lib
2341
endif
2442

2543
.PHONY: all clean prepare
@@ -29,8 +47,13 @@ all: prepare $(TARGET)
2947
prepare:
3048
mkdir -p build
3149

50+
# Build the Python extension, linking against our Faiss
3251
$(TARGET): $(SOURCES)
33-
$(CXX) $(CXXFLAGS) $(ALL_INCLUDES) -shared -o $@ $(SOURCES) $(ALL_LIBS) $(LDFLAGS)
52+
$(CXX) $(CXXFLAGS) $(ALL_INCLUDES) -shared -o $@ \
53+
$(SOURCES) \
54+
-L$(FAISS_ROOT)/lib -lfaiss \
55+
$(ALL_LIBS) \
56+
$(LDFLAGS)
3457

3558
clean:
3659
rm -rf build
68.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)