diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 7ecac566bb583a0d95a55c167d808b12fcd777ee..c52c9e357f164f1178aaf3ba94172a8042eaec2a 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -17,6 +17,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-26 - cmake. Add thirdparty packages - MS-31 - cmake: add prometheus - MS-33 - cmake: add -j4 to make third party packages build faster +- MS-27 - support gpu config and disable license build config in cmake ### Task diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index f4e32948dd72136eecb44f706c2eb857c2ff2300..58ba3aea7de7454f34e94748619fdee060273ca3 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -58,10 +58,10 @@ endif() if(CMAKE_BUILD_TYPE STREQUAL "Release") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp") - if (GPU_VERSION STREQUAL "ON") - set(ENABLE_LICENSE "ON") - add_definitions("-DENABLE_LICENSE") - endif () + # if (GPU_VERSION STREQUAL "ON") + # set(ENABLE_LICENSE "ON") + # add_definitions("-DENABLE_LICENSE") + # endif () else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -DELPP_THREAD_SAFE -fopenmp") endif() diff --git a/cpp/src/wrapper/IndexBuilder.cpp b/cpp/src/wrapper/IndexBuilder.cpp index 240cf95bfb92f9f9790ed217fbe89e1768436996..9470a33b29967d6f3e3e17f46d72d817da8e2bb8 100644 --- a/cpp/src/wrapper/IndexBuilder.cpp +++ b/cpp/src/wrapper/IndexBuilder.cpp @@ -6,14 +6,19 @@ #include "mutex" + #ifdef GPU_VERSION #include -#include "faiss/gpu/GpuIndexIVFFlat.h" -#include "faiss/gpu/GpuAutoTune.h" +#include +#include #endif -#include "faiss/IndexFlat.h" +#include +#include + + +#include "server/ServerConfig.h" #include "IndexBuilder.h" @@ -21,6 +26,31 @@ namespace zilliz { namespace vecwise { namespace engine { +class GpuResources { + public: + static GpuResources &GetInstance() { + static GpuResources instance; + return instance; + } + + void SelectGpu() { + using namespace zilliz::vecwise::server; + ServerConfig &config = ServerConfig::GetInstance(); + ConfigNode server_config = config.GetConfig(CONFIG_SERVER); + gpu_num = server_config.GetInt32Value("gpu_index", 0); + } + + int32_t GetGpu() { + return gpu_num; + } + + private: + GpuResources() : gpu_num(0) { SelectGpu(); } + + private: + int32_t gpu_num; +}; + using std::vector; static std::mutex gpu_resource; @@ -44,7 +74,7 @@ Index_ptr IndexBuilder::build_all(const long &nb, std::lock_guard lk(gpu_resource); faiss::gpu::StandardGpuResources res; - auto device_index = faiss::gpu::index_cpu_to_gpu(&res, 0, ori_index); + auto device_index = faiss::gpu::index_cpu_to_gpu(&res, GpuResources::GetInstance().GetGpu(), ori_index); if (!device_index->is_trained) { nt == 0 || xt == nullptr ? device_index->train(nb, xb) : device_index->train(nt, xt); diff --git a/cpp/src/wrapper/IndexBuilder.h b/cpp/src/wrapper/IndexBuilder.h index e4819326b3fbdfdef4358bbf9348b059caed6ae4..996e3970e393ff6f62d0dac6388425e42b1ce44a 100644 --- a/cpp/src/wrapper/IndexBuilder.h +++ b/cpp/src/wrapper/IndexBuilder.h @@ -32,14 +32,14 @@ class IndexBuilder { const long &nt = 0, const std::vector &xt = std::vector()); - void train(const long &nt, - const std::vector &xt); - - Index_ptr add(const long &nb, - const std::vector &xb, - const std::vector &ids); - - void set_build_option(const Operand_ptr &opd); + //void train(const long &nt, + // const std::vector &xt); + // + //Index_ptr add(const long &nb, + // const std::vector &xb, + // const std::vector &ids); + // + //void set_build_option(const Operand_ptr &opd); protected: