mirror of https://github.com/milvus-io/milvus.git
modify GpuCacheMgr GetInsatnce
Former-commit-id: 7323d4a63e58a6e70f8d47f6b2fbe9566197013cpull/191/head
parent
4b4071f288
commit
b576bd6f1f
|
@ -46,9 +46,6 @@ public:
|
|||
|
||||
double freemem_percent() const { return freemem_percent_; };
|
||||
void set_freemem_percent(double percent) { freemem_percent_ = percent; }
|
||||
void set_gpu_ids(std::vector<uint64_t>& gpu_ids) { gpu_ids_ = gpu_ids; }
|
||||
|
||||
std::vector<uint64_t> gpu_ids() const { return gpu_ids_; }
|
||||
|
||||
size_t size() const;
|
||||
bool exists(const std::string& key);
|
||||
|
@ -63,7 +60,6 @@ private:
|
|||
int64_t usage_;
|
||||
int64_t capacity_;
|
||||
double freemem_percent_;
|
||||
std::vector<uint64_t> gpu_ids_;
|
||||
|
||||
LRU<std::string, CacheObjPtr> lru_;
|
||||
mutable std::mutex mutex_;
|
||||
|
|
|
@ -56,7 +56,6 @@ engine::VecIndexPtr CacheMgr::GetIndex(const std::string& key) {
|
|||
}
|
||||
|
||||
void CacheMgr::InsertItem(const std::string& key, const DataObjPtr& data) {
|
||||
std::cout << "dashalk\n";
|
||||
if(cache_ == nullptr) {
|
||||
SERVER_LOG_ERROR << "Cache doesn't exist";
|
||||
return;
|
||||
|
@ -131,24 +130,6 @@ void CacheMgr::SetCapacity(int64_t capacity) {
|
|||
cache_->set_capacity(capacity);
|
||||
}
|
||||
|
||||
std::vector<uint64_t> CacheMgr::GpuIds() const {
|
||||
if(cache_ == nullptr) {
|
||||
SERVER_LOG_ERROR << "Cache doesn't exist";
|
||||
std::vector<uint64_t> gpu_ids;
|
||||
return gpu_ids;
|
||||
}
|
||||
|
||||
return cache_->gpu_ids();
|
||||
}
|
||||
|
||||
void CacheMgr::SetGpuIds(std::vector<uint64_t> gpu_ids){
|
||||
if(cache_ == nullptr) {
|
||||
SERVER_LOG_ERROR << "Cache doesn't exist";
|
||||
return;
|
||||
}
|
||||
cache_->set_gpu_ids(gpu_ids);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ public:
|
|||
int64_t CacheUsage() const;
|
||||
int64_t CacheCapacity() const;
|
||||
void SetCapacity(int64_t capacity);
|
||||
std::vector<uint64_t > GpuIds() const;
|
||||
void SetGpuIds(std::vector<uint64_t> gpu_ids);
|
||||
|
||||
protected:
|
||||
CacheMgr();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <sstream>
|
||||
#include "utils/Log.h"
|
||||
#include "GpuCacheMgr.h"
|
||||
#include "server/ServerConfig.h"
|
||||
|
@ -18,34 +19,39 @@ std::unordered_map<uint64_t, GpuCacheMgrPtr> GpuCacheMgr::instance_;
|
|||
namespace {
|
||||
constexpr int64_t unit = 1024 * 1024 * 1024;
|
||||
|
||||
void parse_gpu_ids(std::string gpu_ids_str, std::vector<uint64_t>& gpu_ids) {
|
||||
for (auto i = 0; i < gpu_ids_str.length(); ) {
|
||||
if (gpu_ids_str[i] != ',') {
|
||||
int id = 0;
|
||||
while (gpu_ids_str[i] <= '9' && gpu_ids_str[i] >= '0') {
|
||||
id = id * 10 + gpu_ids_str[i] - '0';
|
||||
++i;
|
||||
}
|
||||
gpu_ids.push_back(id);
|
||||
} else {
|
||||
++i;
|
||||
std::vector<uint64_t> load() {
|
||||
server::ConfigNode& config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_CACHE);
|
||||
std::string gpu_ids_str = config.GetValue(server::CONFIG_GPU_IDS, "0,1");
|
||||
|
||||
std::vector<uint64_t > gpu_ids;
|
||||
|
||||
std::stringstream ss(gpu_ids_str);
|
||||
for (int i; ss >> i;) {
|
||||
gpu_ids.push_back(i);
|
||||
if (ss.peek() == ',') {
|
||||
ss.ignore();
|
||||
}
|
||||
}
|
||||
return gpu_ids;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool GpuCacheMgr::GpuIdInConfig(uint64_t gpu_id) {
|
||||
static std::vector<uint64_t > ids = load();
|
||||
for (auto id : ids) {
|
||||
if (gpu_id == id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GpuCacheMgr::GpuCacheMgr() {
|
||||
server::ConfigNode& config = server::ServerConfig::GetInstance().GetConfig(server::CONFIG_CACHE);
|
||||
std::string gpu_ids_str = config.GetValue(server::CONFIG_GPU_IDS, "0,1");
|
||||
|
||||
int64_t cap = config.GetInt64Value(server::CONFIG_GPU_CACHE_CAPACITY, 2);
|
||||
cap *= unit;
|
||||
cache_ = std::make_shared<Cache>(cap, 1UL<<32);
|
||||
|
||||
std::vector<uint64_t> gpu_ids;
|
||||
parse_gpu_ids(gpu_ids_str, gpu_ids);
|
||||
cache_->set_gpu_ids(gpu_ids);
|
||||
|
||||
double free_percent = config.GetDoubleValue(server::GPU_CACHE_FREE_PERCENT, 0.85);
|
||||
if (free_percent > 0.0 && free_percent <= 1.0) {
|
||||
cache_->set_freemem_percent(free_percent);
|
||||
|
|
|
@ -19,12 +19,18 @@ class GpuCacheMgr : public CacheMgr {
|
|||
public:
|
||||
GpuCacheMgr();
|
||||
|
||||
public:
|
||||
static bool GpuIdInConfig(uint64_t gpu_id);
|
||||
|
||||
static CacheMgr* GetInstance(uint64_t gpu_id) {
|
||||
if (instance_.find(gpu_id) == instance_.end()) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
instance_.insert(std::pair<uint64_t, GpuCacheMgrPtr>(gpu_id, std::make_shared<GpuCacheMgr>()));
|
||||
// instance_[gpu_id] = std::make_shared<GpuCacheMgr>();
|
||||
if (instance_.find(gpu_id) == instance_.end()) {
|
||||
if (GpuIdInConfig(gpu_id)) {
|
||||
instance_.insert(std::pair<uint64_t, GpuCacheMgrPtr>(gpu_id, std::make_shared<GpuCacheMgr>()));
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance_[gpu_id].get();
|
||||
}
|
||||
|
|
|
@ -263,9 +263,6 @@ ClientTest::Test(const std::string& address, const std::string& port) {
|
|||
search_record_array.push_back(
|
||||
std::make_pair(record_ids[SEARCH_TARGET], record_array[SEARCH_TARGET]));
|
||||
}
|
||||
int64_t row_count;
|
||||
conn->CountTable(TABLE_NAME, row_count);
|
||||
std::cout << "\t" << TABLE_NAME << "(" << row_count << " rows)" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -448,18 +448,19 @@ InsertTask::OnExecute() {
|
|||
|
||||
// TODO: change to one dimension array in protobuf or use multiple-thread to copy the data
|
||||
for (size_t i = 0; i < insert_param_.row_record_array_size(); i++) {
|
||||
if (insert_param_.row_record_array(i).vector_data().empty()) {
|
||||
return SetError(SERVER_INVALID_ROWRECORD_ARRAY, "Row record float array is empty");
|
||||
}
|
||||
uint64_t vec_dim = insert_param_.row_record_array(i).vector_data().size();
|
||||
if (vec_dim != table_info.dimension_) {
|
||||
ServerError error_code = SERVER_INVALID_VECTOR_DIMENSION;
|
||||
std::string error_msg = "Invalid rowrecord dimension: " + std::to_string(vec_dim)
|
||||
+ " vs. table dimension:" +
|
||||
std::to_string(table_info.dimension_);
|
||||
return SetError(error_code, error_msg);
|
||||
}
|
||||
//TODO: use memcpy
|
||||
for (size_t j = 0; j < table_info.dimension_; j++) {
|
||||
if (insert_param_.row_record_array(i).vector_data().empty()) {
|
||||
return SetError(SERVER_INVALID_ROWRECORD_ARRAY, "Row record float array is empty");
|
||||
}
|
||||
uint64_t vec_dim = insert_param_.row_record_array(i).vector_data().size();
|
||||
if (vec_dim != table_info.dimension_) {
|
||||
ServerError error_code = SERVER_INVALID_VECTOR_DIMENSION;
|
||||
std::string error_msg = "Invalid rowrecord dimension: " + std::to_string(vec_dim)
|
||||
+ " vs. table dimension:" +
|
||||
std::to_string(table_info.dimension_);
|
||||
return SetError(error_code, error_msg);
|
||||
}
|
||||
vec_f[i * table_info.dimension_ + j] = insert_param_.row_record_array(i).vector_data(j);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,8 +165,8 @@ TEST(CacheTest, GPU_CACHE_TEST) {
|
|||
gpu_mgr->ClearCache();
|
||||
ASSERT_EQ(gpu_mgr->ItemCount(), 0);
|
||||
|
||||
gpu_mgr->SetCapacity(4096000000);
|
||||
for (auto i = 0; i < 3; i++) {
|
||||
// TODO: use gpu index to mock
|
||||
MockVecIndex *mock_index = new MockVecIndex();
|
||||
mock_index->ntotal_ = 1000000; //2G
|
||||
engine::VecIndexPtr index(mock_index);
|
||||
|
|
Loading…
Reference in New Issue