diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d1d377e9e..0af71617b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Please mark all change in change log and use the issue from GitHub - \#1752 Add api GetVectorsByID - \#1962 Add api HasPartition - \#1965 FAISS/NSG/HNSW/ANNOY use unified distance calculation algorithm +- \#2054 Check if CPU instruction sets are illegal - \#2064 Warn when use SQLite as metadata management ## Improvement diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index 6d5c7cd0d2..9542de83a1 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -77,11 +77,13 @@ set(thirdparty_files ) aux_source_directory(${MILVUS_ENGINE_SRC}/server server_service_files) +aux_source_directory(${MILVUS_ENGINE_SRC}/server/init server_init_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/delivery/request delivery_request_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/delivery/hybrid_request delivery_hybrid_request_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/delivery/strategy delivery_strategy_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/delivery delivery_files) set(server_files + ${server_init_files} ${server_service_files} ${delivery_request_files} ${delivery_hybrid_request_files} diff --git a/core/src/main.cpp b/core/src/main.cpp index e3483651de..c64eb516ac 100644 --- a/core/src/main.cpp +++ b/core/src/main.cpp @@ -19,6 +19,7 @@ #include "server/Server.h" #include "src/version.h" #include "utils/SignalUtil.h" +#include "utils/Status.h" INITIALIZE_EASYLOGGINGPP diff --git a/core/src/server/Server.cpp b/core/src/server/Server.cpp index 3a6c99ff45..863e81c41a 100644 --- a/core/src/server/Server.cpp +++ b/core/src/server/Server.cpp @@ -12,8 +12,8 @@ #include "server/Server.h" #include -#include #include +#include #include "config/Config.h" #include "index/archive/KnowhereResource.h" @@ -21,6 +21,7 @@ #include "scheduler/SchedInst.h" #include "server/DBWrapper.h" #include "server/grpc_impl/GrpcServer.h" +#include "server/init/CpuChecker.h" #include "server/web_impl/WebServer.h" #include "src/version.h" //#include "storage/s3/S3ClientWrapper.h" @@ -195,6 +196,10 @@ Server::Start() { #else LOG_SERVER_INFO_ << "CPU edition"; #endif + s = CpuChecker::CheckCpuInstructionSet(); + if (!s.ok()) { + return s; + } /* record config and hardware information into log */ LogConfigInFile(config_filename_); LogCpuInfo(); diff --git a/core/src/server/init/CpuChecker.cpp b/core/src/server/init/CpuChecker.cpp new file mode 100644 index 0000000000..cfdcf26ddb --- /dev/null +++ b/core/src/server/init/CpuChecker.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#include "server/init/CpuChecker.h" + +#include +#include +#include + +#include "faiss/FaissHook.h" +#include "faiss/utils/instruction_set.h" +#include "utils/Log.h" +#include "utils/StringHelpFunctions.h" + +namespace milvus { +namespace server { + +Status +CpuChecker::CheckCpuInstructionSet() { + std::vector instruction_sets; + + auto& instruction_set_inst = faiss::InstructionSet::GetInstance(); + if (faiss::support_avx512()) { + instruction_sets.emplace_back("avx512"); + } + if (instruction_set_inst.AVX2()) { + instruction_sets.emplace_back("avx2"); + } + if (instruction_set_inst.SSE42()) { + instruction_sets.emplace_back("sse4_2"); + } + + if (instruction_sets.empty()) { + std::string msg = + "CPU instruction sets are not supported. Ensure the CPU supports at least one of the following instruction " + "sets: sse4_2, avx2, avx512"; + LOG_SERVER_FATAL_ << msg; + std::cerr << msg << std::endl; + return Status(SERVER_UNEXPECTED_ERROR, msg); + } + + std::string instruction_sets_msg; + StringHelpFunctions::MergeStringWithDelimeter(instruction_sets, ", ", instruction_sets_msg); + std::string msg = "Supported CPU instruction sets: " + instruction_sets_msg; + LOG_SERVER_INFO_ << msg; + LOG_ENGINE_DEBUG_ << msg; + std::cout << msg << std::endl; + + return Status::OK(); +} + +} // namespace server +} // namespace milvus diff --git a/core/src/server/init/CpuChecker.h b/core/src/server/init/CpuChecker.h new file mode 100644 index 0000000000..f459f63740 --- /dev/null +++ b/core/src/server/init/CpuChecker.h @@ -0,0 +1,26 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#pragma once + +#include "utils/Status.h" + +namespace milvus { +namespace server { + +class CpuChecker { + public: + static Status + CheckCpuInstructionSet(); +}; + +} // namespace server +} // namespace milvus diff --git a/core/src/utils/CommonUtil.h b/core/src/utils/CommonUtil.h index 31e2df4e08..402168b276 100644 --- a/core/src/utils/CommonUtil.h +++ b/core/src/utils/CommonUtil.h @@ -51,8 +51,10 @@ class CommonUtil { static void ConvertTime(tm time_struct, time_t& time_integer); +#ifdef MILVUS_ENABLE_PROFILING static std::string GetCurrentTimeStr(); +#endif static void EraseFromCache(const std::string& item_key); diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index 09e87aa956..93eb9809fc 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -66,6 +66,7 @@ set(thirdparty_files ) aux_source_directory(${MILVUS_ENGINE_SRC}/server server_files) +aux_source_directory(${MILVUS_ENGINE_SRC}/server/init server_init_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/grpc_impl grpc_impl_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/grpc_impl/interceptor grpc_interceptor_files) aux_source_directory(${MILVUS_ENGINE_SRC}/server/context server_context_files) @@ -146,6 +147,7 @@ set(common_files ${wrapper_files} ${storage_files} ${helper_files} + ${server_init_files} ${server_context_files} ${tracing_files} ${codecs_files}