From f9f336efc3f47543834ba8e212d8f5d3aae0bbe1 Mon Sep 17 00:00:00 2001 From: Yu Kun Date: Thu, 10 Oct 2019 15:31:39 +0800 Subject: [PATCH 1/2] Add ToIndexData for CopyToIndexFileToGpu Former-commit-id: 901d2113cb3530b7425f267b34f42e99439b6e0c --- cpp/src/db/engine/ExecutionEngineImpl.cpp | 9 +++------ cpp/src/wrapper/VecImpl.h | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cpp/src/db/engine/ExecutionEngineImpl.cpp b/cpp/src/db/engine/ExecutionEngineImpl.cpp index 5f43b41dd2..141a3913ff 100644 --- a/cpp/src/db/engine/ExecutionEngineImpl.cpp +++ b/cpp/src/db/engine/ExecutionEngineImpl.cpp @@ -243,12 +243,9 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id) { Status ExecutionEngineImpl::CopyToIndexFileToGpu(uint64_t device_id) { - auto index = cache::GpuCacheMgr::GetInstance(device_id)->GetIndex(location_); - bool already_in_cache = (index != nullptr); - if (!already_in_cache) { - cache::DataObjPtr obj = std::make_shared(nullptr, PhysicalSize()); - milvus::cache::GpuCacheMgr::GetInstance(device_id)->InsertItem(location_, obj); - } + auto to_index_data = std::make_shared(PhysicalSize()); + cache::DataObjPtr obj = std::static_pointer_cast(to_index_data); + milvus::cache::GpuCacheMgr::GetInstance(device_id)->InsertItem(location_, obj); return Status::OK(); } diff --git a/cpp/src/wrapper/VecImpl.h b/cpp/src/wrapper/VecImpl.h index 2be822084f..cb0172ba11 100644 --- a/cpp/src/wrapper/VecImpl.h +++ b/cpp/src/wrapper/VecImpl.h @@ -111,5 +111,16 @@ class BFIndex : public VecIndexImpl { GetRawIds(); }; +class ToIndexData : public cache::DataObj { + public: + ToIndexData(int64_t size) : size_(size) {} + + int64_t + Size() override {return size_;} + + private: + int64_t size_; +}; + } // namespace engine } // namespace milvus From 762fc164cc925330675d5b49e59c2648b2773641 Mon Sep 17 00:00:00 2001 From: Yu Kun Date: Thu, 10 Oct 2019 15:34:26 +0800 Subject: [PATCH 2/2] clang tidy and clang format Former-commit-id: 2bee4aa19cf50687308cf94dc4a7c9a735386789 --- cpp/src/cache/DataObj.h | 2 - cpp/src/db/engine/ExecutionEngineImpl.cpp | 100 +++++++++++----------- cpp/src/wrapper/VecImpl.h | 7 +- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/cpp/src/cache/DataObj.h b/cpp/src/cache/DataObj.h index abd504f590..fa4959e847 100644 --- a/cpp/src/cache/DataObj.h +++ b/cpp/src/cache/DataObj.h @@ -17,7 +17,6 @@ #pragma once - #include namespace milvus { @@ -27,7 +26,6 @@ class DataObj { public: virtual int64_t Size() = 0; - }; using DataObjPtr = std::shared_ptr; diff --git a/cpp/src/db/engine/ExecutionEngineImpl.cpp b/cpp/src/db/engine/ExecutionEngineImpl.cpp index 141a3913ff..77c6942dd2 100644 --- a/cpp/src/db/engine/ExecutionEngineImpl.cpp +++ b/cpp/src/db/engine/ExecutionEngineImpl.cpp @@ -93,56 +93,56 @@ ExecutionEngineImpl::CreatetVecIndex(EngineType type) { void ExecutionEngineImpl::HybridLoad() { -// if (index_type_ != EngineType::FAISS_IVFSQ8Hybrid) { -// return; -// } -// -// const std::string key = location_ + ".quantizer"; -// std::vector gpus; -// -// // cache hit -// { -// int64_t selected = -1; -// void* quantizer = nullptr; -// for (auto& gpu : gpus) { -// auto cache = cache::GpuCacheMgr::GetInstance(gpu); -// if (auto quan = cache->GetIndex(key)) { -// selected = gpu; -// quantizer = quan; -// } -// } -// -// if (selected != -1) { -// // set quantizer into index; -// return; -// } -// } -// -// // cache miss -// { -// std::vector all_free_mem; -// for (auto& gpu : gpus) { -// auto cache = cache::GpuCacheMgr::GetInstance(gpu); -// auto free_mem = cache->CacheCapacity() - cache->CacheUsage(); -// all_free_mem.push_back(free_mem); -// } -// -// auto max_e = std::max_element(all_free_mem.begin(), all_free_mem.end()); -// auto best = std::distance(all_free_mem.begin(), max_e); -// -// // load to best device; -// // cache quantizer -// } -// -// // if index_type == Hybrid -// -// // 1. quantizer in which gpu -// -// // 2.1 which gpu cache best -// -// // 2.2 load to that gpu cache -// -// // set quantizer into index + // if (index_type_ != EngineType::FAISS_IVFSQ8Hybrid) { + // return; + // } + // + // const std::string key = location_ + ".quantizer"; + // std::vector gpus; + // + // // cache hit + // { + // int64_t selected = -1; + // void* quantizer = nullptr; + // for (auto& gpu : gpus) { + // auto cache = cache::GpuCacheMgr::GetInstance(gpu); + // if (auto quan = cache->GetIndex(key)) { + // selected = gpu; + // quantizer = quan; + // } + // } + // + // if (selected != -1) { + // // set quantizer into index; + // return; + // } + // } + // + // // cache miss + // { + // std::vector all_free_mem; + // for (auto& gpu : gpus) { + // auto cache = cache::GpuCacheMgr::GetInstance(gpu); + // auto free_mem = cache->CacheCapacity() - cache->CacheUsage(); + // all_free_mem.push_back(free_mem); + // } + // + // auto max_e = std::max_element(all_free_mem.begin(), all_free_mem.end()); + // auto best = std::distance(all_free_mem.begin(), max_e); + // + // // load to best device; + // // cache quantizer + // } + // + // // if index_type == Hybrid + // + // // 1. quantizer in which gpu + // + // // 2.1 which gpu cache best + // + // // 2.2 load to that gpu cache + // + // // set quantizer into index } Status diff --git a/cpp/src/wrapper/VecImpl.h b/cpp/src/wrapper/VecImpl.h index cb0172ba11..2762287d73 100644 --- a/cpp/src/wrapper/VecImpl.h +++ b/cpp/src/wrapper/VecImpl.h @@ -113,10 +113,13 @@ class BFIndex : public VecIndexImpl { class ToIndexData : public cache::DataObj { public: - ToIndexData(int64_t size) : size_(size) {} + explicit ToIndexData(int64_t size) : size_(size) { + } int64_t - Size() override {return size_;} + Size() override { + return size_; + } private: int64_t size_;