Skip to content

Commit

Permalink
reflect upstream build changes for separating libfaiss/libfaiss_avx2
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Jun 2, 2021
1 parent 484bfe4 commit 2f7e0b3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
8 changes: 7 additions & 1 deletion recipe/build-lib.bat
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ cmake -B _build_%CF_FAISS_BUILD% ^
.
if %ERRORLEVEL% neq 0 exit 1

cmake --build _build_%CF_FAISS_BUILD% --config Release -j %CPU_COUNT%
if "%CF_FAISS_BUILD%"=="avx2" (
set "TARGET=faiss_avx2"
) else (
set "TARGET=faiss"
)

cmake --build _build_%CF_FAISS_BUILD% --target %TARGET% --config Release -j %CPU_COUNT%
if %ERRORLEVEL% neq 0 exit 1

cmake --install _build_%CF_FAISS_BUILD% --config Release --prefix %PREFIX%
Expand Down
9 changes: 7 additions & 2 deletions recipe/build-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ cmake -B _build_${CF_FAISS_BUILD} \
${CUDA_CONFIG_ARGS+"${CUDA_CONFIG_ARGS[@]}"} \
.

cmake --build _build_${CF_FAISS_BUILD} -j $CPU_COUNT
if [[ $CF_FAISS_BUILD == avx2 ]]; then
TARGET="faiss_avx2"
else
TARGET="faiss"
fi

cmake --build _build_${CF_FAISS_BUILD} --target ${TARGET} -j $CPU_COUNT
cmake --install _build_${CF_FAISS_BUILD} --prefix $PREFIX
# will be reused in build-pkg.sh
cmake --install _build_${CF_FAISS_BUILD} --prefix _libfaiss_${CF_FAISS_BUILD}_stage/
14 changes: 10 additions & 4 deletions recipe/build-pkg.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ if "%cuda_compiler_version%"=="None" (
set "CUDAToolkit_ROOT=%CUDA_PATH%"
)

if "%CF_FAISS_BUILD%"=="avx2" (
set "TARGET=faiss_avx2"
) else (
set "TARGET=faiss"
)

:: Build vanilla version (no avx2), see build-lib.bat
cmake -B _build_python_generic ^
-Dfaiss_ROOT=_libfaiss_generic_stage ^
Expand All @@ -25,7 +31,7 @@ cmake -B _build_python_generic ^
faiss/python
if %ERRORLEVEL% neq 0 exit 1

cmake --build _build_python_generic --config Release -j %CPU_COUNT%
cmake --build _build_python_generic --target %TARGET% --config Release -j %CPU_COUNT%
if %ERRORLEVEL% neq 0 exit 1

:: Build version with avx2 support, see build-lib.bat
Expand All @@ -38,12 +44,12 @@ cmake -B _build_python_avx2 ^
faiss/python
if %ERRORLEVEL% neq 0 exit 1

cmake --build _build_python_avx2 --config Release -j %CPU_COUNT%
cmake --build _build_python_avx2 --target %TARGET% --config Release -j %CPU_COUNT%
if %ERRORLEVEL% neq 0 exit 1

:: copy generated swig module with avx2-support to specifically named file, cf.
:: https://github.com/facebookresearch/faiss/blob/v1.7.0/faiss/python/setup.py#L25-L26
copy _build_python_avx2\swigfaiss.py _build_python_generic\swigfaiss_avx2.py
:: https://github.com/facebookresearch/faiss/blob/v1.7.1/faiss/python/setup.py#L37-L40
copy _build_python_avx2\swigfaiss_avx2.py _build_python_generic\swigfaiss_avx2.py
copy _build_python_avx2\Release\_swigfaiss_avx2.pyd _build_python_generic\Release\_swigfaiss_avx2.pyd
if %ERRORLEVEL% neq 0 exit 1

Expand Down
14 changes: 10 additions & 4 deletions recipe/build-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ else
FAISS_ENABLE_GPU="OFF"
fi

if [[ $CF_FAISS_BUILD == avx2 ]]; then
TARGET="swigfaiss_avx2"
else
TARGET="swigfaiss_avx2"
fi

# Build vanilla version (no avx2), see build-lib.sh
cmake -B _build_python_generic \
-Dfaiss_ROOT=_libfaiss_generic_stage/ \
-DFAISS_ENABLE_GPU=${FAISS_ENABLE_GPU} \
-DCMAKE_BUILD_TYPE=Release \
-DPython_EXECUTABLE="${PYTHON}" \
faiss/python
cmake --build _build_python_generic -j $CPU_COUNT
cmake --build _build_python_generic --target ${TARGET} -j $CPU_COUNT

# Build version with avx2 support, see build-lib.sh
cmake -B _build_python_avx2 \
Expand All @@ -33,11 +39,11 @@ cmake -B _build_python_avx2 \
-DCMAKE_BUILD_TYPE=Release \
-DPython_EXECUTABLE="${PYTHON}" \
faiss/python
cmake --build _build_python_avx2 -j $CPU_COUNT
cmake --build _build_python_avx2 --target ${TARGET} -j $CPU_COUNT

# copy generated swig module with avx2-support to specifically named file, cf.
# https://github.com/facebookresearch/faiss/blob/v1.7.0/faiss/python/setup.py#L25-L26
cp _build_python_avx2/swigfaiss.py _build_python_generic/swigfaiss_avx2.py
# https://github.com/facebookresearch/faiss/blob/v1.7.1/faiss/python/setup.py#L37-L40
cp _build_python_avx2/swigfaiss_avx2.py _build_python_generic/swigfaiss_avx2.py
cp _build_python_avx2/_swigfaiss_avx2.so _build_python_generic/_swigfaiss_avx2.so

# Build actual python module.
Expand Down

0 comments on commit 2f7e0b3

Please sign in to comment.