Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ rust/target/

!rust/libs
/gen

# local native-build prefixes (macOS dev)
.local/
.local-ngt/
.worktrees

# Node tooling artifacts: textlint/cspell/prettier installs (bun add) create
Expand Down
54 changes: 43 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ LTO_FLAGS ?= $(if $(findstring clang,$(notdir $(CC))),-flto=thin,-flto=auto -ffa
# lld understands ThinLTO archives natively; only wire it up for clang.
LLD_FLAGS ?= $(if $(and $(findstring clang,$(notdir $(CC))),$(LLD)),-fuse-ld=lld)

# Native Darwin builds use Homebrew's native dependencies. These variables are
# intentionally overridable: callers can resolve them as an unprivileged user
# and pass the values to a build that uses SUDO for installation.
ifeq ($(GOOS),darwin)
OPENMP_PREFIX ?= $(shell brew --prefix libomp 2>/dev/null)
HDF5_PREFIX ?= $(shell brew --prefix hdf5 2>/dev/null)
ZLIB_PREFIX ?= $(shell brew --prefix zlib 2>/dev/null)
OPENMP_CFLAGS ?= -I$(OPENMP_PREFIX)/include
NATIVE_LTO_FLAGS ?= -flto=thin

LDFLAGS = -fPIC -pthread -std=c++17 -lc++ -lm -L$(OPENMP_PREFIX)/lib -Wl,-rpath,$(USR_LOCAL)/lib -Wl,-rpath,$(OPENMP_PREFIX)/lib -lomp -framework Accelerate -lpthread
NGT_LDFLAGS =
HDF5_LDFLAGS = -lhdf5 -lhdf5_hl -lz -lm
CGO_LDFLAGS = -L$(HDF5_PREFIX)/lib -L$(ZLIB_PREFIX)/lib $(HDF5_LDFLAGS)
FAISS_LDFLAGS =
FAISS_CMAKE_C_FLAGS = $(CFLAGS)
FAISS_CMAKE_CXX_FLAGS = $(CXXFLAGS) $(NATIVE_LTO_FLAGS) $(OPENMP_CFLAGS)
FAISS_CMAKE_EXTRA_FLAGS = -DOpenMP_ROOT=$(OPENMP_PREFIX)
else
OPENMP_CFLAGS =
NATIVE_LTO_FLAGS ?= $(LTO_FLAGS)

# NOTE: -ffast-math must NOT appear here. On the link line the compiler driver
# pulls in crtfastmath.o, whose global constructor (set_fast_math, sets the
# MXCSR FTZ/DAZ bits) runs before main and corrupts libgcc's static C++
Expand All @@ -202,19 +224,23 @@ LLD_FLAGS ?= $(if $(and $(findstring clang,$(notdir $(CC))),$(LLD)),-fuse-ld=lld
# reproduced locally). It buys no optimization at link time; per-TU fast-math
# for the hot C++ code already comes from NGT/faiss's own -Ofast.
LDFLAGS = -static -fPIC -pthread -std=gnu++23 -lstdc++ -lm -z relro -z now $(LTO_FLAGS) $(LLD_FLAGS) $(if $(MARCH),-march=$(MARCH)) $(if $(MTUNE),-mtune=$(MTUNE)) -fno-plt -O3 -fvisibility=hidden -ffp-contract=fast -fomit-frame-pointer -fmerge-all-constants -funroll-loops -falign-functions=32 -ffunction-sections -fdata-sections -Wl,--whole-archive -lpthread -Wl,--no-whole-archive

NGT_LDFLAGS = -fopenmp -lopenblas -llapack -lgfortran
FAISS_LDFLAGS = $(NGT_LDFLAGS)
# Resolves a shared libomp.so path only to satisfy CMake's find_package(OpenMP)
# configure-time probe when building NGT/faiss (-DOpenMP_omp_LIBRARY, tools.mk).
# The .so never reaches the shipped binary: NGT/faiss emit static .a archives
# with unresolved OpenMP symbols, and the final static cgo link resolves them
# via NGT_LDFLAGS' -fopenmp, which under clang -static pulls in libomp.a.
# Resolves a shared libomp.so path for CMake's Linux OpenMP probe.
LIBOMP ?= $(shell ldconfig -p 2>/dev/null | awk '/libomp\.so[^.].*=>/{print $$NF; exit}' | grep -v '^$$' || ls /usr/lib/llvm-*/lib/libomp.so 2>/dev/null | sort -V | tail -1)
HDF5_LDFLAGS = -lhdf5 -lhdf5_hl -lsz -laec -lz -ldl -lm
CGO_LDFLAGS = $(FAISS_LDFLAGS) $(HDF5_LDFLAGS)
FAISS_LDFLAGS = $(NGT_LDFLAGS)
FAISS_CMAKE_C_FLAGS = $(CFLAGS) $(LTO_FLAGS) $(if $(MARCH),-march=$(MARCH)) $(if $(MTUNE),-mtune=$(MTUNE)) -fopenmp
FAISS_CMAKE_CXX_FLAGS = $(CXXFLAGS) $(LTO_FLAGS) $(if $(MARCH),-march=$(MARCH)) $(if $(MTUNE),-mtune=$(MTUNE)) -fopenmp
FAISS_CMAKE_EXTRA_FLAGS = -DBLA_VENDOR=OpenBLAS
endif

# TEST_LDFLAGS without -static to avoid conflicts with CGO and glibc dynamic linking requirements
ifeq ($(GOOS),darwin)
TEST_LDFLAGS_BASE = $(LDFLAGS)
else
TEST_LDFLAGS_BASE = -fPIC -pthread -std=gnu++23 -lstdc++ -lm -z relro -z now $(LTO_FLAGS) $(LLD_FLAGS) $(if $(MARCH),-march=$(MARCH)) $(if $(MTUNE),-mtune=$(MTUNE)) -fno-plt -O3 -fvisibility=hidden -ffp-contract=fast -fomit-frame-pointer -fmerge-all-constants -funroll-loops -falign-functions=32 -ffunction-sections -fdata-sections
endif
TEST_LDFLAGS = $(TEST_LDFLAGS_BASE) $(CGO_LDFLAGS)

ifeq ($(GOARCH),amd64)
Expand All @@ -234,10 +260,6 @@ MARCH ?= armv8-a
MTUNE ?= generic
CFLAGS ?=
ifeq ($(GOOS),darwin)
HDF5_LDFLAGS = -lhdf5 -lhdf5_hl -lz -ldl -lm
CFLAGS = -I $(shell brew --prefix hdf5)/include
CGO_CFLAGS ?= $(CFLAGS)
CGO_LDFLAGS = -L $(shell brew --prefix hdf5)/lib -L $(shell brew --prefix zlib)/lib $(HDF5_LDFLAGS)
EXTLDFLAGS ?= -march=armv8-a
else
EXTLDFLAGS ?= -march=armv8-a -Wl,--no-keep-memory
Expand All @@ -253,6 +275,16 @@ EXTLDFLAGS ?= -Wl,--no-keep-memory
endif
endif

ifeq ($(GOOS),darwin)
# Keep the C++ standard explicit in cgo invocations; Faiss requires it when
# compiling through Go rather than through its CMake-generated flags.
CFLAGS := $(CFLAGS) -I$(HDF5_PREFIX)/include -I$(ZLIB_PREFIX)/include
CXXFLAGS := $(CXXFLAGS) -std=c++17
CGO_CFLAGS ?= $(CFLAGS) $(OPENMP_CFLAGS)
CGO_CXXFLAGS ?= $(CXXFLAGS) $(OPENMP_CFLAGS)
export CGO_CFLAGS CGO_CXXFLAGS
endif

# Base compile flags (the arch-gated guards above, without the per-build
# extras appended via CGO_ENV_VARS' $1). Consumed by libomp/install in
# Makefile.d/tools.mk; previously referenced but never defined, so that
Expand Down
10 changes: 5 additions & 5 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ GO_ENV_VARS = \
CGO_ENV_VARS = \
CGO_ENABLED=$(CGO_ENABLED) \
CGO_CFLAGS_ALLOW=".*" \
CGO_CFLAGS="$(CFLAGS) $1" \
CGO_CXXFLAGS="$(CXXFLAGS) $1" \
CGO_CFLAGS="$(CFLAGS) $(OPENMP_CFLAGS) $(NATIVE_LTO_FLAGS) $1" \
CGO_CXXFLAGS="$(CXXFLAGS) $(OPENMP_CFLAGS) $(NATIVE_LTO_FLAGS) $1" \
CGO_FFLAGS="$(CFLAGS) $1" \
CGO_LDFLAGS="$2"

Expand Down Expand Up @@ -224,7 +224,7 @@ define go-example-build
$(call go-base,build, \
$(call CGO_ENV_VARS,-DNGT_LARGE_DATASET,$3), \
, \
$(GO_LDFLAGS) $2 -extldflags '-static $3', \
$(GO_LDFLAGS) $2 -extldflags '$(if $(filter darwin,$(GOOS)),$3,-static $3)', \
osusergo netgo static_build$4, \
$(ROOTDIR)/$6, \
$(ROOTDIR)/example/client/main.go)
Expand All @@ -235,7 +235,7 @@ define go-e2e-build
$(call CGO_ENV_VARS,,$2), \
-c -v -race -mod=readonly, \
$(GO_LDFLAGS) -linkmode=external \
-extldflags '-static $2', \
-extldflags '$(if $(filter darwin,$(GOOS)),$2,-static $2)', \
e2e, \
$(ROOTDIR)/$3, \
$(ROOTDIR)/$1)
Expand Down Expand Up @@ -601,7 +601,7 @@ define cmake-install
$(SUDO) cmake --install $(TEMP_DIR)/$2/build $8
cd $(ROOTDIR)
rm -rf $(TEMP_DIR)/$2 $(TEMP_DIR)/$2-archive
$(SUDO) ldconfig
if command -v ldconfig >/dev/null 2>&1; then $(SUDO) ldconfig; fi
endef

# --- Others ---
Expand Down
36 changes: 22 additions & 14 deletions Makefile.d/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ $(LIB_PATH)/libomp.a: | ninja/install
# installs that do package a static libomp.a, avoiding the multi-minute build.
@SYSTEM_LIBOMP="$$(ls /usr/lib/llvm-*/lib/libomp.a /usr/lib/x86_64-linux-gnu/libomp.a /usr/lib/aarch64-linux-gnu/libomp.a 2>/dev/null | head -1 || true)"; \
if [ -n "$$SYSTEM_LIBOMP" ]; then \
$(SUDO) cp "$$SYSTEM_LIBOMP" "$(LIB_PATH)/libomp.a" && $(SUDO) ldconfig; \
$(SUDO) cp "$$SYSTEM_LIBOMP" "$(LIB_PATH)/libomp.a" && if command -v ldconfig >/dev/null 2>&1; then $(SUDO) ldconfig; fi; \
else \
command -v python3 >/dev/null 2>&1 || { command -v apt-get >/dev/null 2>&1 \
&& $(SUDO) apt-get update -qq \
Expand Down Expand Up @@ -397,7 +397,7 @@ $(LIB_PATH)/libomp.a: | ninja/install
&& cmake --build $(TEMP_DIR)/libomp/openmp/build --parallel $(CORES) \
&& $(SUDO) cmake --install $(TEMP_DIR)/libomp/openmp/build \
&& rm -rf $(TEMP_DIR)/libomp $(TEMP_DIR)/libomp-archive \
&& $(SUDO) ldconfig; \
&& if command -v ldconfig >/dev/null 2>&1; then $(SUDO) ldconfig; fi; \
fi

.PHONY: ngt/install
Expand All @@ -419,8 +419,9 @@ $(USR_LOCAL)/include/NGT/Capi.h: | ninja/install $(if $(findstring clang,$(notdi
-DCMAKE_AR=$$(command -v llvm-ar 2>/dev/null || ls /usr/bin/llvm-ar-* 2>/dev/null | sort -V | tail -1 | grep . || command -v gcc-ar 2>/dev/null || ls /usr/bin/gcc-ar-* 2>/dev/null | sort -V | tail -1 | grep . || command -v ar) \
-DCMAKE_CXX_COMPILER_AR=$$(command -v llvm-ar 2>/dev/null || ls /usr/bin/llvm-ar-* 2>/dev/null | sort -V | tail -1 | grep . || command -v gcc-ar 2>/dev/null || ls /usr/bin/gcc-ar-* 2>/dev/null | sort -V | tail -1 | grep . || command -v ar) \
-DCMAKE_RANLIB=$$(command -v llvm-ranlib 2>/dev/null || ls /usr/bin/llvm-ranlib-* 2>/dev/null | sort -V | tail -1 | grep . || command -v gcc-ranlib 2>/dev/null || ls /usr/bin/gcc-ranlib-* 2>/dev/null | sort -V | tail -1 | grep . || command -v ranlib) \
-DCMAKE_C_FLAGS="$(CFLAGS) $(LTO_FLAGS) $(if $(filter Linux,$(UNAME)),-fopenmp)" \
-DCMAKE_CXX_FLAGS="$(CXXFLAGS) $(LTO_FLAGS) $(if $(filter Linux,$(UNAME)),-fopenmp)" \
-DCMAKE_C_FLAGS="$(CFLAGS) $(NATIVE_LTO_FLAGS) $(OPENMP_CFLAGS)" \
-DCMAKE_CXX_FLAGS="$(CXXFLAGS) $(NATIVE_LTO_FLAGS) $(OPENMP_CFLAGS)" \
$(if $(filter darwin,$(GOOS)),-DOpenMP_ROOT="$(OPENMP_PREFIX)" -DCMAKE_INSTALL_RPATH="@loader_path/../lib",) \
$(if $(and $(findstring clang,$(notdir $(CC))),$(filter Linux,$(UNAME))), \
-DOpenMP_CXX_FLAGS="-fopenmp" \
-DOpenMP_C_FLAGS="-fopenmp" \
Expand All @@ -432,15 +433,21 @@ $(USR_LOCAL)/include/NGT/Capi.h: | ninja/install $(if $(findstring clang,$(notdi
-DCMAKE_USE_PTHREADS_INIT=1 \
-DTHREADS_PREFER_PTHREAD_FLAG=OFF \
$(if $(OPENBLAS_PATH),-DBLAS_LIBRARIES="$(OPENBLAS_PATH)" -DLAPACK_LIBRARIES="$(OPENBLAS_PATH)",) \
-DCMAKE_EXE_LINKER_FLAGS="$(NGT_LDFLAGS)$(if $(filter ld.lld lld,$(notdir $(LLD))), -fuse-ld=lld)" \
-DCMAKE_SHARED_LINKER_FLAGS="$(NGT_LDFLAGS)$(if $(filter ld.lld lld,$(notdir $(LLD))), -fuse-ld=lld)" \
-DCMAKE_MODULE_LINKER_FLAGS="$(NGT_LDFLAGS)$(if $(filter ld.lld lld,$(notdir $(LLD))), -fuse-ld=lld)" \
-DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS) $(NGT_LDFLAGS)$(if $(and $(filter-out darwin,$(GOOS)),$(filter ld.lld lld,$(notdir $(LLD)))), -fuse-ld=lld)" \
-DCMAKE_SHARED_LINKER_FLAGS="$(LDFLAGS) $(NGT_LDFLAGS)$(if $(and $(filter-out darwin,$(GOOS)),$(filter ld.lld lld,$(notdir $(LLD)))), -fuse-ld=lld)" \
-DCMAKE_MODULE_LINKER_FLAGS="$(LDFLAGS) $(NGT_LDFLAGS)$(if $(and $(filter-out darwin,$(GOOS)),$(filter ld.lld lld,$(notdir $(LLD)))), -fuse-ld=lld)" \
$(NGT_EXTRA_CMAKE_FLAGS), \
mkdir -p $(TEMP_DIR)/ngt/build/bin/ngt $(TEMP_DIR)/ngt/build/bin/qbg && touch $(TEMP_DIR)/ngt/build/bin/ngt/ngt $(TEMP_DIR)/ngt/build/bin/qbg/qbg, \
v$(NGT_VERSION), \
, \
ngt)

# Discover and install Faiss headers under $(USR_LOCAL)/include while
# preserving failures without relying on GNU install -D.
define FAISS_HEADER_INSTALL
cd $(TEMP_DIR)/faiss && find faiss -name '*.h' -exec sh -c 'for src do dst="$(USR_LOCAL)/include/$$src"; $(SUDO) mkdir -p "$$(dirname "$$dst")" && $(SUDO) install -m 0644 "$$src" "$$dst" || exit 1; done' sh {} +
endef

.PHONY: faiss/install
## install Faiss
faiss/install: $(LIB_PATH)/libfaiss.a
Expand All @@ -466,25 +473,26 @@ $(LIB_PATH)/libfaiss.a: | ninja/install $(if $(findstring clang,$(notdir $(CC)))
$(call cmake-install,https://github.com/facebookresearch/faiss/archive/v$(FAISS_VERSION).tar.gz,faiss, \
-DFAISS_ENABLE_PYTHON=OFF \
-DFAISS_ENABLE_GPU=OFF \
$(if $(OPENBLAS_PATH),-DBLAS_PREFER_THREADED="$(OPENBLAS_PATH)" -DBLAS_LIBRARIES="$(OPENBLAS_PATH)" -DLAPACK_LIBRARIES="$(OPENBLAS_PATH)",) \
$(if $(filter-out darwin,$(GOOS)),$(if $(OPENBLAS_PATH),-DBLAS_PREFER_THREADED="$(OPENBLAS_PATH)" -DBLAS_LIBRARIES="$(OPENBLAS_PATH)" -DLAPACK_LIBRARIES="$(OPENBLAS_PATH)",),) \
-DCMAKE_CXX_SCAN_FOR_MODULES=OFF \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
-DCMAKE_C_FLAGS="$(CFLAGS) $(LTO_FLAGS) $(if $(MARCH),-march=$(MARCH)) $(if $(MTUNE),-mtune=$(MTUNE)) $(if $(filter Linux,$(UNAME)),-fopenmp)" \
-DCMAKE_CXX_FLAGS="$(CXXFLAGS) $(LTO_FLAGS) $(if $(MARCH),-march=$(MARCH)) $(if $(MTUNE),-mtune=$(MTUNE)) $(if $(filter Linux,$(UNAME)),-fopenmp)" \
-DCMAKE_C_FLAGS="$(FAISS_CMAKE_C_FLAGS)" \
-DCMAKE_CXX_FLAGS="$(FAISS_CMAKE_CXX_FLAGS)" \
$(if $(and $(findstring clang,$(notdir $(CC))),$(filter Linux,$(UNAME))), \
-DOpenMP_CXX_FLAGS="-fopenmp" \
-DOpenMP_C_FLAGS="-fopenmp" \
-DOpenMP_CXX_LIB_NAMES="omp" \
-DOpenMP_C_LIB_NAMES="omp" \
$(if $(LIBOMP),-DOpenMP_omp_LIBRARY="$(LIBOMP)")) \
$(FAISS_CMAKE_EXTRA_FLAGS) \
-DCMAKE_THREAD_LIBS_INIT="-lpthread" \
-DCMAKE_HAVE_THREADS_LIBRARY=1 \
-DCMAKE_USE_PTHREADS_INIT=1 \
-DTHREADS_PREFER_PTHREAD_FLAG=OFF \
-DCMAKE_EXE_LINKER_FLAGS="$(FAISS_LDFLAGS)$(if $(filter ld.lld lld,$(notdir $(LLD))), -fuse-ld=lld)" \
-DCMAKE_SHARED_LINKER_FLAGS="$(FAISS_LDFLAGS)$(if $(filter ld.lld lld,$(notdir $(LLD))), -fuse-ld=lld)" \
-DCMAKE_MODULE_LINKER_FLAGS="$(FAISS_LDFLAGS)$(if $(filter ld.lld lld,$(notdir $(LLD))), -fuse-ld=lld)", \
cd $(TEMP_DIR)/faiss && $(SUDO) find faiss -name '*.h' -exec install -D -m 0644 {} $(USR_LOCAL)/include/{} \;, \
-DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS) $(FAISS_LDFLAGS)$(if $(and $(filter-out darwin,$(GOOS)),$(filter ld.lld lld,$(notdir $(LLD)))), -fuse-ld=lld)" \
-DCMAKE_SHARED_LINKER_FLAGS="$(LDFLAGS) $(FAISS_LDFLAGS)$(if $(and $(filter-out darwin,$(GOOS)),$(filter ld.lld lld,$(notdir $(LLD)))), -fuse-ld=lld)" \
-DCMAKE_MODULE_LINKER_FLAGS="$(LDFLAGS) $(FAISS_LDFLAGS)$(if $(and $(filter-out darwin,$(GOOS)),$(filter ld.lld lld,$(notdir $(LLD)))), -fuse-ld=lld)", \
$(FAISS_HEADER_INSTALL), \
, \
, \
faiss)
Expand Down
39 changes: 38 additions & 1 deletion docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This document describes how to set up the development environment and how to dev
#### OS

- When using Docker related environment, you can use any OS that supports Docker.
- When using native environment, `Linux` is required.
- When using native environment, `Linux` or `macOS` (Darwin; `arm64`/Apple Silicon and `amd64`) are supported.

#### Architecture

Expand All @@ -20,6 +20,43 @@ But you can also build and test `Vald` on `arm64` with the same way as described

This is the easiest way to start developing `Vald`. You can just open our [devcontainer.json](https://github.com/vdaas/vald/blob/main/.devcontainer/devcontainer.json) with `VS Code` and go.

### macOS (Darwin) native build

Vald can be built and tested natively on macOS (Apple Silicon and Intel). It uses
Comment thread
aaf2tbz marked this conversation as resolved.
**Apple clang** (from the Xcode Command Line Tools) as the C/C++ compiler,
[Homebrew](https://brew.sh) for the remaining native dependencies, and Apple's
`Accelerate.framework` for BLAS/LAPACK. The C/C++ libraries (NGT, Faiss, HDF5,
zlib) are built from source into `/usr/local` by the Makefile, which requires
privileged install steps.

```bash
# 1. Xcode Command Line Tools — REQUIRED: provides Apple clang and the macOS SDK
xcode-select --install
clang --version # verify: should print "Apple clang version ..."

# 2. Homebrew dependencies
brew install go protobuf buf cmake hdf5 zlib libomp

# 3. Resolve Homebrew prefixes as the current user, then let Make elevate only
# the filesystem install commands. Do not run the entire Makefile as root.
OPENMP_PREFIX="$(brew --prefix libomp)" \
HDF5_PREFIX="$(brew --prefix hdf5)" \
ZLIB_PREFIX="$(brew --prefix zlib)" \
SUDO=sudo make ngt/install hdf5/install faiss/install

# 4. Run the unit tests
make test
```

> **Compiler:** the build uses Apple clang from step 1 — `brew install llvm` is
> **not** required. (Homebrew `llvm` is only needed if you explicitly want LLVM's
> `clang`/`llvm-ar`; in that case `brew install llvm` and add
> `$(brew --prefix llvm)/bin` to your `PATH` first.) On Darwin the Makefile
> resolves OpenMP and HDF5/ZLIB headers through the prefixes above, uses Apple
> thin-LTO (`-flto=thin`), and `Accelerate.framework` for BLAS/LAPACK — so
> `OpenBLAS`/`lapack`/`gcc` (gfortran) are **not** required. On Linux the original
> GNU toolchain flags are unchanged.

### Other

We don't officially have a setup documentation for now, but you can take a look at the [`Dockerfile`](https://github.com/vdaas/vald/blob/main/dockers/dev/Dockerfile).
Expand Down
12 changes: 6 additions & 6 deletions internal/core/algorithm/faiss/Capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ int faiss_add_ivfpq(
try {
//printf("is_trained: %d\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->is_trained);
//printf("ntotal: %ld\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->ntotal);
(static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->add_with_ids(nb, xb, xids);
(static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->add_with_ids(nb, xb, reinterpret_cast<const faiss::idx_t*>(xids));
//printf("is_trained: %d\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->is_trained);
//printf("ntotal: %ld\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->ntotal);
} catch(std::exception &err) {
Expand All @@ -369,7 +369,7 @@ int faiss_add_binaryivf(
//fflush(stdout);

try {
(static_cast<faiss::IndexBinaryIVF*>(st->faiss_index))->add_with_ids(nb, xb, xids);
(static_cast<faiss::IndexBinaryIVF*>(st->faiss_index))->add_with_ids(nb, xb, reinterpret_cast<const faiss::idx_t*>(xids));
} catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
Expand Down Expand Up @@ -423,7 +423,7 @@ bool faiss_search_ivfpq(
//printf("is_trained: %d\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->is_trained);
//printf("ntotal: %ld\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->ntotal);
(static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->nprobe = nprobe;
(static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->search(nq, xq, k, D, I);
(static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->search(nq, xq, k, D, reinterpret_cast<faiss::idx_t*>(I));
//printf("I=\n");
//for(int i = 0; i < nq; i++) {
// for(int j = 0; j < k; j++) {
Expand Down Expand Up @@ -463,7 +463,7 @@ bool faiss_search_binaryivf(
int32_t* tmpD = new int32_t[nq*k];
try {
(static_cast<faiss::IndexBinaryIVF*>(st->faiss_index))->nprobe = nprobe;
(static_cast<faiss::IndexBinaryIVF*>(st->faiss_index))->search(nq, xq, k, tmpD, I);
(static_cast<faiss::IndexBinaryIVF*>(st->faiss_index))->search(nq, xq, k, tmpD, reinterpret_cast<faiss::idx_t*>(I));
} catch(std::exception &err) {
delete[] tmpD;
std::stringstream ss;
Expand Down Expand Up @@ -512,7 +512,7 @@ int faiss_remove_ivfpq(
try {
//printf("is_trained: %d\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->is_trained);
//printf("ntotal: %ld\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->ntotal);
faiss::IDSelectorArray sel(size, ids);
faiss::IDSelectorArray sel(size, reinterpret_cast<const faiss::idx_t*>(ids));
(static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->remove_ids(sel);
//printf("is_trained: %d\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->is_trained);
//printf("ntotal: %ld\n", (static_cast<faiss::IndexIVFPQ*>(st->faiss_index))->ntotal);
Expand All @@ -535,7 +535,7 @@ int faiss_remove_binaryivf(
//fflush(stdout);

try {
faiss::IDSelectorArray sel(size, ids);
faiss::IDSelectorArray sel(size, reinterpret_cast<const faiss::idx_t*>(ids));
(static_cast<faiss::IndexBinaryIVF*>(st->faiss_index))->remove_ids(sel);
} catch(std::exception &err) {
std::stringstream ss;
Expand Down