From bc929fb16bcb2324123060bdee2dccc9037c5782 Mon Sep 17 00:00:00 2001 From: yudong Date: Thu, 17 Apr 2025 01:19:32 +0000 Subject: [PATCH] knowhere support riscv Signed-off-by: yudong --- cmake/libs/libfaiss.cmake | 28 +++++++++++++++++++++++++++- cmake/utils/platform_check.cmake | 6 ++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cmake/libs/libfaiss.cmake b/cmake/libs/libfaiss.cmake index 2756fb577..07ee3d875 100644 --- a/cmake/libs/libfaiss.cmake +++ b/cmake/libs/libfaiss.cmake @@ -101,7 +101,11 @@ if(__AARCH64) target_link_libraries(knowhere_utils PUBLIC glog::glog) endif() - +if(__RISCV64) + set(UTILS_SRC src/simd/hook.cc src/simd/distances_ref.cc) + add_library(knowhere_utils STATIC ${UTILS_SRC}) + target_link_libraries(knowhere_utils PUBLIC glog::glog) +endif() # ToDo: Add distances_vsx.cc for powerpc64 SIMD acceleration if(__PPC64) @@ -192,6 +196,28 @@ if(__AARCH64) target_compile_definitions(faiss PRIVATE FINTEGER=int) endif() +if(__RISCV64) + knowhere_file_glob(GLOB FAISS_AVX_SRCS thirdparty/faiss/faiss/impl/*avx.cpp) + + list(REMOVE_ITEM FAISS_SRCS ${FAISS_AVX_SRCS}) + add_library(faiss STATIC ${FAISS_SRCS}) + + target_compile_options( + faiss + PRIVATE $<$: + -Wno-sign-compare + -Wno-unused-variable + -Wno-reorder + -Wno-unused-local-typedefs + -Wno-unused-function + -Wno-strict-aliasing>) + + add_dependencies(faiss knowhere_utils) + target_link_libraries(faiss PUBLIC OpenMP::OpenMP_CXX ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} knowhere_utils) + target_compile_definitions(faiss PRIVATE FINTEGER=int) +endif() + if(__PPC64) knowhere_file_glob(GLOB FAISS_AVX_SRCS thirdparty/faiss/faiss/impl/*avx.cpp) list(REMOVE_ITEM FAISS_SRCS ${FAISS_AVX_SRCS}) diff --git a/cmake/utils/platform_check.cmake b/cmake/utils/platform_check.cmake index 0604cb79c..ac14d017a 100644 --- a/cmake/utils/platform_check.cmake +++ b/cmake/utils/platform_check.cmake @@ -4,11 +4,13 @@ macro(detect_target_arch) check_symbol_exists(__aarch64__ "" __AARCH64) check_symbol_exists(__x86_64__ "" __X86_64) check_symbol_exists(__powerpc64__ "" __PPC64) + check_symbol_exists(__riscv "" __RISCV64) if(NOT __AARCH64 AND NOT __X86_64 - AND NOT __PPC64) - message(FATAL "knowhere only support amd64, ppc64 and arm64 architecture.") + AND NOT __PPC64 + AND NOT __RISCV64) + message(FATAL "knowhere only support amd64, ppc64, riscv64 and arm64 architecture.") endif() endmacro()