Skip to content

Commit

Permalink
Correct ARM builds to not have faiss
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed May 20, 2024
1 parent e84609c commit a353891
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 48 deletions.
7 changes: 7 additions & 0 deletions cpp/bench/ann/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ set(RAFT_ANN_BENCH_USE_FAISS ON)
set(RAFT_FAISS_ENABLE_GPU ON)
set(RAFT_USE_FAISS_STATIC ON)

# Faiss doesn't support ARM currently
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(RAFT_ANN_BENCH_USE_FAISS OFF)
set(RAFT_FAISS_ENABLE_GPU OFF)
set(RAFT_USE_FAISS_STATIC OFF)
endif()

if(BUILD_CPU_ONLY)

# Include necessary logging dependencies
Expand Down
9 changes: 9 additions & 0 deletions cpp/cmake/patches/faiss_override.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"packages" : {
"faiss" : {
"version": "1.7.4",
"git_url": "https://github.com/facebookresearch/faiss.git",
"git_tag": "main"
}
}
}
95 changes: 47 additions & 48 deletions cpp/cmake/thirdparty/get_faiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,62 @@ function(find_and_configure_faiss)
LIBRARY_NAMES faiss
)

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(faiss version repository tag shallow exclude)

include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake")
rapids_cpm_generate_patch_command(faiss ${version} patch_command)

set(BUILD_SHARED_LIBS ON)
if (PKG_BUILD_STATIC_LIBS)
set(BUILD_SHARED_LIBS OFF)
set(CPM_DOWNLOAD_faiss ON)
endif()

include(cmake/modules/FindAVX)

# Link against AVX CPU lib if it exists
set(RAFT_FAISS_OPT_LEVEL "generic")
if(CXX_AVX2_FOUND)
set(RAFT_FAISS_OPT_LEVEL "avx2")
endif()

rapids_cpm_find(faiss ${PKG_VERSION}
GLOBAL_TARGETS faiss faiss_avx2 faiss_gpu faiss::faiss faiss::faiss_avx2
CPM_ARGS
GIT_REPOSITORY ${PKG_REPOSITORY}
GIT_TAG ${PKG_PINNED_TAG}
EXCLUDE_FROM_ALL ${PKG_EXCLUDE_FROM_ALL}
OPTIONS
"FAISS_ENABLE_GPU ${PKG_ENABLE_GPU}"
"FAISS_ENABLE_PYTHON OFF"
"FAISS_OPT_LEVEL ${RAFT_FAISS_OPT_LEVEL}"
"FAISS_USE_CUDA_TOOLKIT_STATIC ${CUDA_STATIC_RUNTIME}"
"BUILD_TESTING OFF"
"CMAKE_MESSAGE_LOG_LEVEL VERBOSE"
)
rapids_cpm_find(faiss ${version}
GLOBAL_TARGETS faiss faiss_avx2 faiss_gpu faiss::faiss faiss::faiss_avx2
CPM_ARGS
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow} ${patch_command}
EXCLUDE_FROM_ALL ${exclude}
OPTIONS
"FAISS_ENABLE_GPU ${PKG_ENABLE_GPU}"
"FAISS_ENABLE_PYTHON OFF"
"FAISS_OPT_LEVEL ${RAFT_FAISS_OPT_LEVEL}"
"FAISS_USE_CUDA_TOOLKIT_STATIC ${CUDA_STATIC_RUNTIME}"
"BUILD_TESTING OFF"
"CMAKE_MESSAGE_LOG_LEVEL VERBOSE"
)

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(hnswlib)

if(TARGET faiss AND NOT TARGET faiss::faiss)
add_library(faiss::faiss ALIAS faiss)
# We need to ensure that faiss has all the conda information. So we use this approach so that
# faiss will have the conda includes/link dirs
target_link_libraries(faiss PRIVATE $<TARGET_NAME_IF_EXISTS:conda_env>)
endif()
if(TARGET faiss_avx2 AND NOT TARGET faiss::faiss_avx2)
add_library(faiss::faiss_avx2 ALIAS faiss_avx2)
# We need to ensure that faiss has all the conda information. So we use this approach so that
# faiss will have the conda includes/link dirs
target_link_libraries(faiss_avx2 PRIVATE $<TARGET_NAME_IF_EXISTS:conda_env>)
endif()
if(TARGET faiss_gpu AND NOT TARGET faiss::faiss_gpu)
add_library(faiss::faiss_gpu ALIAS faiss_gpu)
# We need to ensure that faiss has all the conda information. So we use this approach so that
# faiss will have the conda includes/link dirs
target_link_libraries(faiss_gpu PRIVATE $<TARGET_NAME_IF_EXISTS:conda_env>)
endif()
if(TARGET faiss AND NOT TARGET faiss::faiss)
add_library(faiss::faiss ALIAS faiss)
# We need to ensure that faiss has all the conda information. So we use this approach so that
# faiss will have the conda includes/link dirs
target_link_libraries(faiss PRIVATE $<TARGET_NAME_IF_EXISTS:conda_env>)
endif()
if(TARGET faiss_avx2 AND NOT TARGET faiss::faiss_avx2)
add_library(faiss::faiss_avx2 ALIAS faiss_avx2)
# We need to ensure that faiss has all the conda information. So we use this approach so that
# faiss will have the conda includes/link dirs
target_link_libraries(faiss_avx2 PRIVATE $<TARGET_NAME_IF_EXISTS:conda_env>)
endif()
if(TARGET faiss_gpu AND NOT TARGET faiss::faiss_gpu)
add_library(faiss::faiss_gpu ALIAS faiss_gpu)
# We need to ensure that faiss has all the conda information. So we use this approach so that
# faiss will have the conda includes/link dirs
target_link_libraries(faiss_gpu PRIVATE $<TARGET_NAME_IF_EXISTS:conda_env>)
endif()

if(faiss_ADDED)
rapids_export(BUILD faiss
Expand All @@ -80,7 +89,7 @@ function(find_and_configure_faiss)
endif()

# Need to tell CMake to rescan the link group of faiss::faiss_gpu and faiss
# so that we get proper link order
# so that we get proper link order when they are static
if(PKG_ENABLE_GPU AND PKG_BUILD_STATIC_LIBS AND TARGET faiss::faiss_avx2)
set(RAFT_FAISS_TARGETS "$<LINK_GROUP:RESCAN,$<LINK_LIBRARY:WHOLE_ARCHIVE,faiss_gpu>,faiss::faiss_avx2>" PARENT_SCOPE)
elseif(PKG_ENABLE_GPU AND PKG_BUILD_STATIC_LIBS)
Expand All @@ -93,18 +102,8 @@ function(find_and_configure_faiss)

endfunction()

if(NOT RAFT_FAISS_GIT_TAG)
set(RAFT_FAISS_GIT_TAG main)
endif()

if(NOT RAFT_FAISS_GIT_REPOSITORY)
set(RAFT_FAISS_GIT_REPOSITORY https://github.com/facebookresearch/faiss.git)
endif()

find_and_configure_faiss(VERSION 1.7.4
REPOSITORY ${RAFT_FAISS_GIT_REPOSITORY}
PINNED_TAG ${RAFT_FAISS_GIT_TAG}
BUILD_STATIC_LIBS ${RAFT_USE_FAISS_STATIC}
EXCLUDE_FROM_ALL ${RAFT_EXCLUDE_FAISS_FROM_ALL}
ENABLE_GPU ${RAFT_FAISS_ENABLE_GPU})

find_and_configure_faiss(
BUILD_STATIC_LIBS ${RAFT_USE_FAISS_STATIC}
ENABLE_GPU ${RAFT_FAISS_ENABLE_GPU}
)

0 comments on commit a353891

Please sign in to comment.