diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index af32680e2342d2ba09fb88ba6828dd98505df564..06511ae01b945e3c8ff48b6f0579e7a121cd4ea9 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -27,6 +27,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-470 - Drop index success, which table not created - MS-471 - code coverage run failed - MS-492 - Drop index failed if index have been created with index_type: FLAT +- MS-493 - Knowhere unittest crash ## Improvement - MS-327 - Clean code for milvus @@ -85,6 +86,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-455 - Distribute tasks by minimal cost in scheduler - MS-460 - Put transport speed as weight when choosing neighbour to execute task - MS-459 - Add cache for pick function in tasktable +- MS-476 - Improve search performance - MS-482 - Change search stream transport to unary in grpc - MS-487 - Define metric type in CreateTable - MS-488 - Improve code format in scheduler diff --git a/cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h b/cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h index 22c43292da673bd54abe6c208237255ee59a6b0c..3a62addf94bf55c07dd33a04e5bd22e4b17a67e7 100644 --- a/cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h +++ b/cpp/src/core/include/knowhere/index/vector_index/gpu_ivf.h @@ -9,7 +9,7 @@ namespace zilliz { namespace knowhere { struct Resource { - Resource(std::shared_ptr &r): faiss_res(r) { + explicit Resource(std::shared_ptr &r): faiss_res(r) { static int64_t global_id = 0; id = global_id++; } @@ -32,6 +32,11 @@ class FaissGpuResourceMgr { static FaissGpuResourceMgr & GetInstance(); + // Free gpu resource, avoid cudaGetDevice error when deallocate. + // this func should be invoke before main return + void + Free(); + void AllocateTempMem(ResPtr &resource, const int64_t& device_id, const int64_t& size); diff --git a/cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp b/cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp index 26fcd6a74977846be45e5f0ca4c87012ebaaacf3..0546674e78aaa6f94ff43b929111bad4475bf2e4 100644 --- a/cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp +++ b/cpp/src/core/src/knowhere/index/vector_index/gpu_ivf.cpp @@ -282,7 +282,7 @@ void FaissGpuResourceMgr::InitResource() { for(auto& device : devices_params_) { auto& resource_vec = idle_[device.first]; - for (int i = 0; i < device.second.resource_num; ++i) { + for (int64_t i = 0; i < device.second.resource_num; ++i) { auto res = std::make_shared(); // TODO(linxj): enable set pinned memory @@ -351,6 +351,18 @@ void FaissGpuResourceMgr::MoveToIdle(const int64_t &device_id, const ResPtr &res idle_[device_id].insert(it, res); } +void FaissGpuResourceMgr::Free() { + for (auto &item : in_use_) { + auto& res_vec = item.second; + res_vec.clear(); + } + for (auto &item : idle_) { + auto& res_vec = item.second; + res_vec.clear(); + } + is_init = false; +} + void GPUIndex::SetGpuDevice(const int &gpu_id) { gpu_id_ = gpu_id; } diff --git a/cpp/src/core/test/test_idmap.cpp b/cpp/src/core/test/test_idmap.cpp index 25f8f762f38e63be2a0fb87e7d8cfb549203bfd3..90546429b698c98983ae2648cbcc0b8946b6067f 100644 --- a/cpp/src/core/test/test_idmap.cpp +++ b/cpp/src/core/test/test_idmap.cpp @@ -26,6 +26,11 @@ class IDMAPTest : public DataGen, public ::testing::Test { Init_with_default(); index_ = std::make_shared(); } + + void TearDown() override { + FaissGpuResourceMgr::GetInstance().Free(); + } + protected: IDMAPPtr index_ = nullptr; }; diff --git a/cpp/src/core/test/test_ivf.cpp b/cpp/src/core/test/test_ivf.cpp index 23847f7a16a173440a7474d842f0ab2e0bc736f2..9ebcf767d91cba391fb5980f39006fa5f9ad1e74 100644 --- a/cpp/src/core/test/test_ivf.cpp +++ b/cpp/src/core/test/test_ivf.cpp @@ -7,13 +7,11 @@ #include #include -#include #include #include #include #include -#include #include "knowhere/index/vector_index/gpu_ivf.h" #include "knowhere/index/vector_index/ivf.h" @@ -58,6 +56,9 @@ class IVFTest index_ = IndexFactory(index_type); FaissGpuResourceMgr::GetInstance().InitDevice(device_id, 1024*1024*200, 1024*1024*300, 2); } + void TearDown() override { + FaissGpuResourceMgr::GetInstance().Free(); + } protected: std::string index_type; @@ -369,6 +370,7 @@ class GPURESTEST void TearDown() override { delete ids; delete dis; + FaissGpuResourceMgr::GetInstance().Free(); } protected: diff --git a/cpp/src/server/Server.cpp b/cpp/src/server/Server.cpp index 2df42791309f4b842a41af978441b769d3e1ba59..955c55d954d9692af00fdc5f785f672224a5df8b 100644 --- a/cpp/src/server/Server.cpp +++ b/cpp/src/server/Server.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "knowhere/index/vector_index/gpu_ivf.h" #include "metrics/Metrics.h" #include "DBWrapper.h" @@ -232,6 +233,7 @@ Server::StopService() { grpc::GrpcMilvusServer::StopService(); DBWrapper::GetInstance().StopService(); engine::StopSchedulerService(); + knowhere::FaissGpuResourceMgr::GetInstance().Free(); // free gpu resource. } } diff --git a/cpp/unittest/CMakeLists.txt b/cpp/unittest/CMakeLists.txt index ff78178dfbe8c82faf45a9f41bd8a71fe5b2a5b1..ac666c86a999b45ad2d453af0d021e9ba7923363 100644 --- a/cpp/unittest/CMakeLists.txt +++ b/cpp/unittest/CMakeLists.txt @@ -40,7 +40,7 @@ set(unittest_libs add_subdirectory(server) add_subdirectory(db) -#add_subdirectory(knowhere) +add_subdirectory(knowhere) add_subdirectory(metrics) #add_subdirectory(scheduler) #add_subdirectory(storage) \ No newline at end of file diff --git a/cpp/unittest/knowhere/knowhere_test.cpp b/cpp/unittest/knowhere/knowhere_test.cpp index 8d2524276c5028f471d9e88bc7e15aaf92e900d6..2bd4bddc70a0da459b15271b512ac6b796eaa899 100644 --- a/cpp/unittest/knowhere/knowhere_test.cpp +++ b/cpp/unittest/knowhere/knowhere_test.cpp @@ -40,6 +40,9 @@ class KnowhereWrapperTest index_ = GetVecIndexFactory(index_type); } + void TearDown() override { + zilliz::knowhere::FaissGpuResourceMgr::GetInstance().Free(); + } void AssertResult(const std::vector &ids, const std::vector &dis) { EXPECT_EQ(ids.size(), nq * k);