From 512fe6233c44c9724bc628310bcff42491b4a408 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Sat, 14 Mar 2020 18:03:23 +0800 Subject: [PATCH] #1649 fix Milvus crash on old cpu (#1652) * #1649 fix Milvus crash on old cpu Signed-off-by: yudong.cai * #1649 update debug log Signed-off-by: yudong.cai * retry CI Signed-off-by: yudong.cai --- CHANGELOG.md | 1 + core/src/index/thirdparty/faiss/FaissHook.cpp | 17 ++++++++--------- core/src/index/thirdparty/faiss/FaissHook.h | 2 +- core/src/wrapper/KnowhereResource.cpp | 9 +++++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5b4998c..b4ebd329 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Please mark all change in change log and use the issue from GitHub - \#1546 Move Config.cpp to config directory - \#1547 Rename storage/file to storage/disk and rename classes - \#1548 Move store/Directory to storage/Operation and add FSHandler +- \#1649 Fix Milvus crash on old CPU ## Task diff --git a/core/src/index/thirdparty/faiss/FaissHook.cpp b/core/src/index/thirdparty/faiss/FaissHook.cpp index 0e462e4d..08e70469 100644 --- a/core/src/index/thirdparty/faiss/FaissHook.cpp +++ b/core/src/index/thirdparty/faiss/FaissHook.cpp @@ -48,7 +48,7 @@ bool support_sse() { return (instruction_set_inst.SSE()); } -std::string hook_init() { +bool hook_init(std::string& cpu_flag) { static std::mutex hook_mutex; std::lock_guard lock(hook_mutex); @@ -64,8 +64,7 @@ std::string hook_init() { sq_get_distance_computer_IP = sq_get_distance_computer_IP_avx512; sq_sel_quantizer = sq_select_quantizer_avx512; - std::cout << "FAISS hook AVX512" << std::endl; - return "AVX512"; + cpu_flag = "AVX512"; } else if (support_avx()) { /* for IVFFLAT */ fvec_inner_product = fvec_inner_product_avx; @@ -78,8 +77,7 @@ std::string hook_init() { sq_get_distance_computer_IP = sq_get_distance_computer_IP_avx; sq_sel_quantizer = sq_select_quantizer_avx; - std::cout << "FAISS hook AVX" << std::endl; - return "AVX"; + cpu_flag = "AVX"; } else if (support_sse()) { /* for IVFFLAT */ fvec_inner_product = fvec_inner_product_sse; @@ -92,12 +90,13 @@ std::string hook_init() { sq_get_distance_computer_IP = sq_get_distance_computer_IP_sse; sq_sel_quantizer = sq_select_quantizer_sse; - std::cout << "FAISS hook SSE" << std::endl; - return "SSE"; + cpu_flag = "SSE"; } else { - FAISS_ASSERT_MSG(false, "CPU not supported!"); - return "UNSUPPORTED"; + cpu_flag = "UNSUPPORTED"; + return false; } + + return true; } } // namespace faiss diff --git a/core/src/index/thirdparty/faiss/FaissHook.h b/core/src/index/thirdparty/faiss/FaissHook.h index 11666f96..ca2a421c 100644 --- a/core/src/index/thirdparty/faiss/FaissHook.h +++ b/core/src/index/thirdparty/faiss/FaissHook.h @@ -29,6 +29,6 @@ extern sq_sel_func_ptr sq_sel_quantizer; extern bool support_avx512(); -extern std::string hook_init(); +extern bool hook_init(std::string& cpu_flag); } // namespace faiss diff --git a/core/src/wrapper/KnowhereResource.cpp b/core/src/wrapper/KnowhereResource.cpp index 734272ab..3e4888b7 100644 --- a/core/src/wrapper/KnowhereResource.cpp +++ b/core/src/wrapper/KnowhereResource.cpp @@ -17,6 +17,7 @@ #include "config/Config.h" #include "faiss/FaissHook.h" #include "scheduler/Utils.h" +#include "utils/Error.h" #include "utils/Log.h" #include @@ -37,8 +38,12 @@ KnowhereResource::Initialize() { bool use_avx512 = true; CONFIG_CHECK(config.GetEngineConfigUseAVX512(use_avx512)); faiss::faiss_use_avx512 = use_avx512; - std::string type = faiss::hook_init(); - ENGINE_LOG_DEBUG << "FAISS hook " << type; + std::string cpu_flag; + if (faiss::hook_init(cpu_flag)) { + ENGINE_LOG_DEBUG << "FAISS hook " << cpu_flag; + } else { + return Status(KNOWHERE_UNEXPECTED_ERROR, "FAISS hook fail, CPU not supported!"); + } #ifdef MILVUS_GPU_VERSION bool enable_gpu = false; -- GitLab