From 670f852030b065ead1d7ef44b453565c3124ed55 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Sun, 19 May 2024 13:52:12 -0400 Subject: [PATCH] Correct ARM builds to not have faiss --- cpp/bench/ann/CMakeLists.txt | 7 ++ cpp/cmake/patches/faiss_override.json | 9 +++ cpp/cmake/thirdparty/get_faiss.cmake | 92 +++++++++++++-------------- 3 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 cpp/cmake/patches/faiss_override.json diff --git a/cpp/bench/ann/CMakeLists.txt b/cpp/bench/ann/CMakeLists.txt index f489cc62c6..91ccb5fe57 100644 --- a/cpp/bench/ann/CMakeLists.txt +++ b/cpp/bench/ann/CMakeLists.txt @@ -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 diff --git a/cpp/cmake/patches/faiss_override.json b/cpp/cmake/patches/faiss_override.json new file mode 100644 index 0000000000..19dad362b9 --- /dev/null +++ b/cpp/cmake/patches/faiss_override.json @@ -0,0 +1,9 @@ +{ + "packages" : { + "faiss" : { + "version": "1.7.4", + "git_url": "https://github.com/facebookresearch/faiss.git", + "git_tag": "main" + } + } +} diff --git a/cpp/cmake/thirdparty/get_faiss.cmake b/cpp/cmake/thirdparty/get_faiss.cmake index 2ab606b9be..b22225d9cd 100644 --- a/cpp/cmake/thirdparty/get_faiss.cmake +++ b/cpp/cmake/thirdparty/get_faiss.cmake @@ -24,6 +24,9 @@ function(find_and_configure_faiss) LIBRARY_NAMES faiss ) + 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) @@ -31,46 +34,49 @@ function(find_and_configure_faiss) 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" + ) - 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 $) - 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 $) - 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 $) - endif() + 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 $) + 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 $) + 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 $) + endif() if(faiss_ADDED) rapids_export(BUILD faiss @@ -80,7 +86,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 "$,faiss::faiss_avx2>" PARENT_SCOPE) elseif(PKG_ENABLE_GPU AND PKG_BUILD_STATIC_LIBS) @@ -93,18 +99,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} +)