diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ece7a1c37a02c925f2e0bdde16a47962be6e240..9e2810ba8adb60b5bf282b58b3b4461fd88b0d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ Please mark all change in change log and use the issue from GitHub - \#2039 Support Milvus run on SSE CPUs - \#2149 Merge server_cpu_config.template and server_gpu_config.template - \#2153 Upgrade thirdparty oatpp to v1.0.0 -- \#2167 Merge config file +- \#2167 Merge log_config.conf with server_config.yaml ## Task diff --git a/core/src/config/Config.cpp b/core/src/config/Config.cpp index 5108fbbccaaa257b9e08219a1ff2dba7e0b8f74f..5397777f2344aaab847452a5c8fd523823f2623d 100644 --- a/core/src/config/Config.cpp +++ b/core/src/config/Config.cpp @@ -113,8 +113,8 @@ const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD = "use_blas_threshold"; const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT = "1100"; const char* CONFIG_ENGINE_OMP_THREAD_NUM = "omp_thread_num"; const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0"; -const char* CONFIG_ENGINE_USE_AVX512 = "use_avx512"; -const char* CONFIG_ENGINE_USE_AVX512_DEFAULT = "true"; +const char* CONFIG_ENGINE_SIMD_TYPE = "simd_type"; +const char* CONFIG_ENGINE_SIMD_TYPE_DEFAULT = "auto"; const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD = "gpu_search_threshold"; const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT = "1000"; @@ -338,8 +338,8 @@ Config::ValidateConfig() { int64_t engine_omp_thread_num; CONFIG_CHECK(GetEngineConfigOmpThreadNum(engine_omp_thread_num)); - bool engine_use_avx512; - CONFIG_CHECK(GetEngineConfigUseAVX512(engine_use_avx512)); + std::string engine_simd_type; + CONFIG_CHECK(GetEngineConfigSimdType(engine_simd_type)); #ifdef MILVUS_GPU_VERSION int64_t engine_gpu_search_threshold; @@ -450,7 +450,7 @@ Config::ResetDefaultConfig() { /* engine config */ CONFIG_CHECK(SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT)); CONFIG_CHECK(SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT)); - CONFIG_CHECK(SetEngineConfigUseAVX512(CONFIG_ENGINE_USE_AVX512_DEFAULT)); + CONFIG_CHECK(SetEngineConfigSimdType(CONFIG_ENGINE_SIMD_TYPE_DEFAULT)); /* wal config */ CONFIG_CHECK(SetWalConfigEnable(CONFIG_WAL_ENABLE_DEFAULT)); @@ -577,8 +577,8 @@ Config::SetConfigCli(const std::string& parent_key, const std::string& child_key status = SetEngineConfigUseBlasThreshold(value); } else if (child_key == CONFIG_ENGINE_OMP_THREAD_NUM) { status = SetEngineConfigOmpThreadNum(value); - } else if (child_key == CONFIG_ENGINE_USE_AVX512) { - status = SetEngineConfigUseAVX512(value); + } else if (child_key == CONFIG_ENGINE_SIMD_TYPE) { + status = SetEngineConfigSimdType(value); #ifdef MILVUS_GPU_VERSION } else if (child_key == CONFIG_ENGINE_GPU_SEARCH_THRESHOLD) { status = SetEngineConfigGpuSearchThreshold(value); @@ -1315,11 +1315,12 @@ Config::CheckEngineConfigOmpThreadNum(const std::string& value) { } Status -Config::CheckEngineConfigUseAVX512(const std::string& value) { - if (!ValidationUtil::ValidateStringIsBool(value).ok()) { - std::string msg = - "Invalid engine config: " + value + ". Possible reason: engine_config.use_avx512 is not a boolean."; - return Status(SERVER_INVALID_ARGUMENT, msg); +Config::CheckEngineConfigSimdType(const std::string& value) { + fiu_return_on("check_config_simd_type_fail", + Status(SERVER_INVALID_ARGUMENT, "engine_config.simd_type is not one of avx512, avx2, sse and auto.")); + + if (value != "avx512" && value != "avx2" && value != "sse" && value != "auto") { + return Status(SERVER_INVALID_ARGUMENT, "engine_config.simd_type is not one of avx512, avx2, sse and auto."); } return Status::OK(); } @@ -1927,12 +1928,9 @@ Config::GetEngineConfigOmpThreadNum(int64_t& value) { } Status -Config::GetEngineConfigUseAVX512(bool& value) { - std::string str = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_USE_AVX512, CONFIG_ENGINE_USE_AVX512_DEFAULT); - CONFIG_CHECK(CheckEngineConfigUseAVX512(str)); - std::transform(str.begin(), str.end(), str.begin(), ::tolower); - value = (str == "true" || str == "on" || str == "yes" || str == "1"); - return Status::OK(); +Config::GetEngineConfigSimdType(std::string& value) { + value = GetConfigStr(CONFIG_ENGINE, CONFIG_ENGINE_SIMD_TYPE, CONFIG_ENGINE_SIMD_TYPE_DEFAULT); + return CheckEngineConfigSimdType(value); } #ifdef MILVUS_GPU_VERSION @@ -2333,9 +2331,9 @@ Config::SetEngineConfigOmpThreadNum(const std::string& value) { } Status -Config::SetEngineConfigUseAVX512(const std::string& value) { - CONFIG_CHECK(CheckEngineConfigUseAVX512(value)); - return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_AVX512, value); +Config::SetEngineConfigSimdType(const std::string& value) { + CONFIG_CHECK(CheckEngineConfigSimdType(value)); + return SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_SIMD_TYPE, value); } /* tracing config */ diff --git a/core/src/config/Config.h b/core/src/config/Config.h index c74e75d9ce81865b9749514932977b6bb39ef165..543bd6c61ff909ebb5f14fd4280cb8a8fe786749 100644 --- a/core/src/config/Config.h +++ b/core/src/config/Config.h @@ -109,8 +109,8 @@ extern const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD; extern const char* CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT; extern const char* CONFIG_ENGINE_OMP_THREAD_NUM; extern const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT; -extern const char* CONFIG_ENGINE_USE_AVX512; -extern const char* CONFIG_ENGINE_USE_AVX512_DEFAULT; +extern const char* CONFIG_ENGINE_SIMD_TYPE; +extern const char* CONFIG_ENGINE_SIMD_TYPE_DEFAULT; extern const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD; extern const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT; @@ -284,7 +284,7 @@ class Config { Status CheckEngineConfigOmpThreadNum(const std::string& value); Status - CheckEngineConfigUseAVX512(const std::string& value); + CheckEngineConfigSimdType(const std::string& value); #ifdef MILVUS_GPU_VERSION Status @@ -413,7 +413,7 @@ class Config { Status GetEngineConfigOmpThreadNum(int64_t& value); Status - GetEngineConfigUseAVX512(bool& value); + GetEngineConfigSimdType(std::string& value); #ifdef MILVUS_GPU_VERSION Status @@ -534,7 +534,7 @@ class Config { Status SetEngineConfigOmpThreadNum(const std::string& value); Status - SetEngineConfigUseAVX512(const std::string& value); + SetEngineConfigSimdType(const std::string& value); /* tracing config */ Status diff --git a/core/src/index/archive/KnowhereResource.cpp b/core/src/index/archive/KnowhereResource.cpp index 07fb6d784c2a95448d49ba2bc983f6a3ddda91a1..698a3f76495f290888d855202083bde0bc0a9897 100644 --- a/core/src/index/archive/KnowhereResource.cpp +++ b/core/src/index/archive/KnowhereResource.cpp @@ -35,11 +35,28 @@ constexpr int64_t M_BYTE = 1024 * 1024; Status KnowhereResource::Initialize() { server::Config& config = server::Config::GetInstance(); - bool use_avx512 = true; - CONFIG_CHECK(config.GetEngineConfigUseAVX512(use_avx512)); - faiss::faiss_use_avx512 = use_avx512; + std::string simd_type; + CONFIG_CHECK(config.GetEngineConfigSimdType(simd_type)); + if (simd_type == "avx512") { + faiss::faiss_use_avx512 = true; + faiss::faiss_use_avx2 = false; + faiss::faiss_use_sse = false; + } else if (simd_type == "avx2") { + faiss::faiss_use_avx512 = false; + faiss::faiss_use_avx2 = true; + faiss::faiss_use_sse = false; + } else if (simd_type == "sse") { + faiss::faiss_use_avx512 = false; + faiss::faiss_use_avx2 = false; + faiss::faiss_use_sse = true; + } else { + faiss::faiss_use_avx512 = true; + faiss::faiss_use_avx2 = true; + faiss::faiss_use_sse = true; + } std::string cpu_flag; if (faiss::hook_init(cpu_flag)) { + std::cout << "FAISS hook " << cpu_flag << std::endl; LOG_ENGINE_DEBUG_ << "FAISS hook " << cpu_flag; } else { return Status(KNOWHERE_UNEXPECTED_ERROR, "FAISS hook fail, CPU not supported!"); diff --git a/core/src/index/thirdparty/faiss/FaissHook.cpp b/core/src/index/thirdparty/faiss/FaissHook.cpp index 3da223e9ff5bad1d1480a4909ec8f4ed24f4bb38..0c30a5ceb8932310311416475bdb2f0539611d2e 100644 --- a/core/src/index/thirdparty/faiss/FaissHook.cpp +++ b/core/src/index/thirdparty/faiss/FaissHook.cpp @@ -17,6 +17,8 @@ namespace faiss { bool faiss_use_avx512 = true; +bool faiss_use_avx2 = true; +bool faiss_use_sse = true; /* set default to AVX */ fvec_func_ptr fvec_inner_product = fvec_inner_product_avx; @@ -41,11 +43,15 @@ bool support_avx512() { } bool support_avx2() { + if (!faiss_use_avx2) return false; + InstructionSet& instruction_set_inst = InstructionSet::GetInstance(); return (instruction_set_inst.AVX2()); } -bool support_sse42() { +bool support_sse() { + if (!faiss_use_sse) return false; + InstructionSet& instruction_set_inst = InstructionSet::GetInstance(); return (instruction_set_inst.SSE42()); } @@ -80,7 +86,7 @@ bool hook_init(std::string& cpu_flag) { sq_sel_quantizer = sq_select_quantizer_avx; cpu_flag = "AVX2"; - } else if (support_sse42()) { + } else if (support_sse()) { /* for IVFFLAT */ fvec_inner_product = fvec_inner_product_sse; fvec_L2sqr = fvec_L2sqr_sse; diff --git a/core/src/index/thirdparty/faiss/FaissHook.h b/core/src/index/thirdparty/faiss/FaissHook.h index ca2a421ccd7cf84c9f16649cc51e683a2e8a2b8c..dfd25a9d3aae46481c48c0ae2a4e64d5faee560b 100644 --- a/core/src/index/thirdparty/faiss/FaissHook.h +++ b/core/src/index/thirdparty/faiss/FaissHook.h @@ -17,6 +17,8 @@ typedef Quantizer* (*sq_sel_func_ptr)(QuantizerType, size_t, const std::vector