提交 0d1923c6 编写于 作者: Y yudong.cai

#346 update gpu resource config APIs

上级 00a21da4
...@@ -27,9 +27,7 @@ metric_config: ...@@ -27,9 +27,7 @@ metric_config:
port: 8080 # port prometheus uses to fetch metrics, must in range [1025, 65534] port: 8080 # port prometheus uses to fetch metrics, must in range [1025, 65534]
cache_config: cache_config:
cpu_cache_capacity: 16 # GB, size of CPU memory used for cache, must be a positive integer
cpu_cache_capacity: 16 # GB, CPU memory used for cache, must be a positive integer
cpu_cache_threshold: 0.85 # percentage of data that will be kept when cache cleanup is triggered, must be in range (0.0, 1.0]
cache_insert_data: false # whether to load inserted data into cache, must be a boolean cache_insert_data: false # whether to load inserted data into cache, must be a boolean
engine_config: engine_config:
...@@ -37,7 +35,10 @@ engine_config: ...@@ -37,7 +35,10 @@ engine_config:
# if nq >= use_blas_threshold, use OpenBlas, slower with stable response times # if nq >= use_blas_threshold, use OpenBlas, slower with stable response times
gpu_search_threshold: 1000 # threshold beyond which the search computation is executed on GPUs only gpu_search_threshold: 1000 # threshold beyond which the search computation is executed on GPUs only
resource_config: gpu_resource_config:
search_resources: # define the device used for search computation enable_gpu: true # whether to enable GPU resources
- cpu cache_capacity: 4 # GB, size of GPU memory per card used for cache, must be a positive integer
index_build_device: cpu # CPU used for building index search_resources: # define the GPU devices used for search computation, must be in format gpux
- gpu0
build_index_resources: # define the GPU devices used for index building, must be in format gpux
- gpu0
\ No newline at end of file
...@@ -27,10 +27,7 @@ metric_config: ...@@ -27,10 +27,7 @@ metric_config:
port: 8080 # port prometheus uses to fetch metrics, must in range [1025, 65534] port: 8080 # port prometheus uses to fetch metrics, must in range [1025, 65534]
cache_config: cache_config:
cpu_cache_capacity: 16 # GB, CPU memory used for cache, must be a positive integer cpu_cache_capacity: 16 # GB, size of CPU memory used for cache, must be a positive integer
cpu_cache_threshold: 0.85 # percentage of data that will be kept when cache cleanup is triggered, must be in range (0.0, 1.0]
gpu_cache_capacity: 4 # GB, GPU memory used for cache, must be a positive integer
gpu_cache_threshold: 0.85 # percentage of data that will be kept when cache cleanup is triggered, must be in range (0.0, 1.0]
cache_insert_data: false # whether to load inserted data into cache, must be a boolean cache_insert_data: false # whether to load inserted data into cache, must be a boolean
engine_config: engine_config:
...@@ -38,8 +35,10 @@ engine_config: ...@@ -38,8 +35,10 @@ engine_config:
# if nq >= use_blas_threshold, use OpenBlas, slower with stable response times # if nq >= use_blas_threshold, use OpenBlas, slower with stable response times
gpu_search_threshold: 1000 # threshold beyond which the search computation is executed on GPUs only gpu_search_threshold: 1000 # threshold beyond which the search computation is executed on GPUs only
resource_config: gpu_resource_config:
search_resources: # define the devices used for search computation, must be in format: cpu or gpux enable_gpu: false # whether to enable GPU resources
- cpu cache_capacity: 4 # GB, size of GPU memory per card used for cache, must be a positive integer
search_resources: # define the GPU devices used for search computation, must be in format gpux
- gpu0 - gpu0
index_build_device: gpu0 # CPU / GPU used for building index, must be in format: cpu or gpux build_index_resources: # define the GPU devices used for index building, must be in format gpux
- gpu0
\ No newline at end of file
...@@ -37,7 +37,7 @@ GpuCacheMgr::GpuCacheMgr() { ...@@ -37,7 +37,7 @@ GpuCacheMgr::GpuCacheMgr() {
Status s; Status s;
int64_t gpu_cache_cap; int64_t gpu_cache_cap;
s = config.GetCacheConfigGpuCacheCapacity(gpu_cache_cap); s = config.GetGpuResourceConfigCacheCapacity(gpu_cache_cap);
if (!s.ok()) { if (!s.ok()) {
SERVER_LOG_ERROR << s.message(); SERVER_LOG_ERROR << s.message();
} }
...@@ -45,7 +45,7 @@ GpuCacheMgr::GpuCacheMgr() { ...@@ -45,7 +45,7 @@ GpuCacheMgr::GpuCacheMgr() {
cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL << 32); cache_ = std::make_shared<Cache<DataObjPtr>>(cap, 1UL << 32);
float gpu_mem_threshold; float gpu_mem_threshold;
s = config.GetCacheConfigGpuCacheThreshold(gpu_mem_threshold); s = config.GetGpuResourceConfigCacheThreshold(gpu_mem_threshold);
if (!s.ok()) { if (!s.ok()) {
SERVER_LOG_ERROR << s.message(); SERVER_LOG_ERROR << s.message();
} }
......
...@@ -163,20 +163,6 @@ Config::ValidateConfig() { ...@@ -163,20 +163,6 @@ Config::ValidateConfig() {
return s; return s;
} }
#ifdef MILVUS_GPU_VERSION
int64_t cache_gpu_cache_capacity;
s = GetCacheConfigGpuCacheCapacity(cache_gpu_cache_capacity);
if (!s.ok()) {
return s;
}
float cache_gpu_cache_threshold;
s = GetCacheConfigGpuCacheThreshold(cache_gpu_cache_threshold);
if (!s.ok()) {
return s;
}
#endif
bool cache_insert_data; bool cache_insert_data;
s = GetCacheConfigCacheInsertData(cache_insert_data); s = GetCacheConfigCacheInsertData(cache_insert_data);
if (!s.ok()) { if (!s.ok()) {
...@@ -202,25 +188,39 @@ Config::ValidateConfig() { ...@@ -202,25 +188,39 @@ Config::ValidateConfig() {
return s; return s;
} }
/* resource config */ /* gpu resource config */
std::string resource_mode; #ifdef MILVUS_GPU_VERSION
s = GetResourceConfigMode(resource_mode); bool resource_enable_gpu;
s = GetGpuResourceConfigEnableGpu(resource_enable_gpu);
if (!s.ok()) {
return s;
}
int64_t resource_cache_capacity;
s = GetGpuResourceConfigCacheCapacity(resource_cache_capacity);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
std::vector<std::string> search_resources; float resource_cache_threshold;
s = GetResourceConfigSearchResources(search_resources); s = GetGpuResourceConfigCacheThreshold(resource_cache_threshold);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
int32_t resource_index_build_device; std::vector<int32_t> search_resources;
s = GetResourceConfigIndexBuildDevice(resource_index_build_device); s = GetGpuResourceConfigSearchResources(search_resources);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
std::vector<int32_t> index_build_resources;
s = GetGpuResourceConfigBuildIndexResources(index_build_resources);
if (!s.ok()) {
return s;
}
#endif
return Status::OK(); return Status::OK();
} }
...@@ -307,54 +307,54 @@ Config::ResetDefaultConfig() { ...@@ -307,54 +307,54 @@ Config::ResetDefaultConfig() {
return s; return s;
} }
#ifdef MILVUS_GPU_VERSION s = SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT);
s = SetCacheConfigGpuCacheCapacity(CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
s = SetCacheConfigGpuCacheThreshold(CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT); /* engine config */
s = SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
#endif
s = SetCacheConfigCacheInsertData(CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT); s = SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
/* engine config */ s = SetEngineConfigGpuSearchThreshold(CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT);
s = SetEngineConfigUseBlasThreshold(CONFIG_ENGINE_USE_BLAS_THRESHOLD_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
s = SetEngineConfigOmpThreadNum(CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT); /* gpu resource config */
#ifdef MILVUS_GPU_VERSION
s = SetGpuResourceConfigEnableGpu(CONFIG_GPU_RESOURCE_ENABLE_GPU_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
s = SetEngineConfigGpuSearchThreshold(CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT); s = SetGpuResourceConfigCacheCapacity(CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
/* resource config */ s = SetGpuResourceConfigCacheThreshold(CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT);
s = SetResourceConfigMode(CONFIG_RESOURCE_MODE_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
s = SetResourceConfigSearchResources(CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT); s = SetGpuResourceConfigSearchResources(CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
s = SetResourceConfigIndexBuildDevice(CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT); s = SetGpuResourceConfigBuildIndexResources(CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
#endif
return Status::OK(); return Status::OK();
} }
...@@ -377,7 +377,7 @@ Config::PrintAll() { ...@@ -377,7 +377,7 @@ Config::PrintAll() {
PrintConfigSection(CONFIG_CACHE); PrintConfigSection(CONFIG_CACHE);
PrintConfigSection(CONFIG_METRIC); PrintConfigSection(CONFIG_METRIC);
PrintConfigSection(CONFIG_ENGINE); PrintConfigSection(CONFIG_ENGINE);
PrintConfigSection(CONFIG_RESOURCE); PrintConfigSection(CONFIG_GPU_RESOURCE);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -591,52 +591,6 @@ Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) { ...@@ -591,52 +591,6 @@ Config::CheckCacheConfigCpuCacheThreshold(const std::string& value) {
return Status::OK(); return Status::OK();
} }
Status
Config::CheckCacheConfigGpuCacheCapacity(const std::string& value) {
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
std::string msg = "Invalid gpu cache capacity: " + value +
". Possible reason: cache_config.gpu_cache_capacity is not a positive integer.";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else {
uint64_t gpu_cache_capacity = std::stoi(value) * GB;
int device_id;
Status s = GetResourceConfigIndexBuildDevice(device_id);
if (!s.ok()) {
return s;
}
size_t gpu_memory;
if (!ValidationUtil::GetGpuMemory(device_id, gpu_memory).ok()) {
std::string msg = "Fail to get GPU memory for GPU device: " + std::to_string(device_id);
return Status(SERVER_UNEXPECTED_ERROR, msg);
} else if (gpu_cache_capacity >= gpu_memory) {
std::string msg = "Invalid gpu cache capacity: " + value +
". Possible reason: cache_config.gpu_cache_capacity exceeds GPU memory.";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
std::cerr << "Warning: gpu cache capacity value is too big" << std::endl;
}
}
return Status::OK();
}
Status
Config::CheckCacheConfigGpuCacheThreshold(const std::string& value) {
if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
std::string msg = "Invalid gpu cache threshold: " + value +
". Possible reason: cache_config.gpu_cache_threshold is not in range (0.0, 1.0].";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else {
float gpu_cache_threshold = std::stof(value);
if (gpu_cache_threshold <= 0.0 || gpu_cache_threshold >= 1.0) {
std::string msg = "Invalid gpu cache threshold: " + value +
". Possible reason: cache_config.gpu_cache_threshold is not in range (0.0, 1.0].";
return Status(SERVER_INVALID_ARGUMENT, msg);
}
}
return Status::OK();
}
Status Status
Config::CheckCacheConfigCacheInsertData(const std::string& value) { Config::CheckCacheConfigCacheInsertData(const std::string& value) {
if (!ValidationUtil::ValidateStringIsBool(value).ok()) { if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
...@@ -687,56 +641,99 @@ Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) { ...@@ -687,56 +641,99 @@ Config::CheckEngineConfigGpuSearchThreshold(const std::string& value) {
} }
Status Status
Config::CheckResourceConfigMode(const std::string& value) { Config::CheckGpuResourceConfigEnableGpu(const std::string& value) {
if (value != "simple") { if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
std::string msg = "Invalid resource mode: " + value + ". Possible reason: resource_config.mode is invalid."; std::string msg = "Invalid gpu resource config: " + value +
". Possible reason: gpu_resource_config.enable_gpu is not a boolean.";
return Status(SERVER_INVALID_ARGUMENT, msg); return Status(SERVER_INVALID_ARGUMENT, msg);
} }
return Status::OK(); return Status::OK();
} }
Status Status
CheckResource(const std::string& value) { Config::CheckGpuResourceConfigCacheCapacity(const std::string& value) {
if (!ValidationUtil::ValidateStringIsNumber(value).ok()) {
std::string msg = "Invalid gpu cache capacity: " + value +
". Possible reason: gpu_resource_config.cache_capacity is not a positive integer.";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else {
uint64_t gpu_cache_capacity = std::stoi(value) * GB;
std::vector<int32_t> gpu_ids;
Status s = GetGpuResourceConfigBuildIndexResources(gpu_ids);
if (!s.ok()) {
return s;
}
for (int32_t gpu_id : gpu_ids) {
size_t gpu_memory;
if (!ValidationUtil::GetGpuMemory(gpu_id, gpu_memory).ok()) {
std::string msg = "Fail to get GPU memory for GPU device: " + std::to_string(gpu_id);
return Status(SERVER_UNEXPECTED_ERROR, msg);
} else if (gpu_cache_capacity >= gpu_memory) {
std::string msg = "Invalid gpu cache capacity: " + value +
". Possible reason: gpu_resource_config.cache_capacity exceeds GPU memory.";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else if (gpu_cache_capacity > (double)gpu_memory * 0.9) {
std::cerr << "Warning: gpu cache capacity value is too big" << std::endl;
}
}
}
return Status::OK();
}
Status
Config::CheckGpuResourceConfigCacheThreshold(const std::string& value) {
if (!ValidationUtil::ValidateStringIsFloat(value).ok()) {
std::string msg = "Invalid gpu cache threshold: " + value +
". Possible reason: gpu_resource_config.cache_threshold is not in range (0.0, 1.0].";
return Status(SERVER_INVALID_ARGUMENT, msg);
} else {
float gpu_cache_threshold = std::stof(value);
if (gpu_cache_threshold <= 0.0 || gpu_cache_threshold >= 1.0) {
std::string msg = "Invalid gpu cache threshold: " + value +
". Possible reason: gpu_resource_config.cache_threshold is not in range (0.0, 1.0].";
return Status(SERVER_INVALID_ARGUMENT, msg);
}
}
return Status::OK();
}
Status
CheckGpuResource(const std::string& value) {
std::string s = value; std::string s = value;
std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::transform(s.begin(), s.end(), s.begin(), ::tolower);
#ifdef MILVUS_CPU_VERSION const std::regex pat("gpu(\\d+)");
if (s != "cpu") {
return Status(SERVER_INVALID_ARGUMENT, "Invalid CPU resource: " + s);
}
#else
const std::regex pat("cpu|gpu(\\d+)");
std::smatch m; std::smatch m;
if (!std::regex_match(s, m, pat)) { if (!std::regex_match(s, m, pat)) {
std::string msg = "Invalid search resource: " + value + std::string msg = "Invalid gpu resource: " + value +
". Possible reason: resource_config.search_resources is not in the format of cpux or gpux"; ". Possible reason: gpu_resource_config is not in the format of cpux or gpux";
return Status(SERVER_INVALID_ARGUMENT, msg); return Status(SERVER_INVALID_ARGUMENT, msg);
} }
if (s.compare(0, 3, "gpu") == 0) { if (s.compare(0, 3, "gpu") == 0) {
int32_t gpu_index = std::stoi(s.substr(3)); int32_t gpu_index = std::stoi(s.substr(3));
if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) { if (!ValidationUtil::ValidateGpuIndex(gpu_index).ok()) {
std::string msg = "Invalid search resource: " + value + std::string msg = "Invalid gpu resource: " + value +
". Possible reason: resource_config.search_resources does not match your hardware."; ". Possible reason: gpu_resource_config does not match with the hardware.";
return Status(SERVER_INVALID_ARGUMENT, msg); return Status(SERVER_INVALID_ARGUMENT, msg);
} }
} }
#endif
return Status::OK(); return Status::OK();
} }
Status Status
Config::CheckResourceConfigSearchResources(const std::vector<std::string>& value) { Config::CheckGpuResourceConfigSearchResources(const std::vector<std::string>& value) {
if (value.empty()) { if (value.empty()) {
std::string msg = std::string msg =
"Invalid search resource. " "Invalid gpu search resource. "
"Possible reason: resource_config.search_resources is empty."; "Possible reason: gpu_resource_config.search_resources is empty.";
return Status(SERVER_INVALID_ARGUMENT, msg); return Status(SERVER_INVALID_ARGUMENT, msg);
} }
for (auto& resource : value) { for (auto& resource : value) {
auto status = CheckResource(resource); auto status = CheckGpuResource(resource);
if (!status.ok()) { if (!status.ok()) {
return Status(SERVER_INVALID_ARGUMENT, status.message()); return Status(SERVER_INVALID_ARGUMENT, status.message());
} }
...@@ -745,10 +742,19 @@ Config::CheckResourceConfigSearchResources(const std::vector<std::string>& value ...@@ -745,10 +742,19 @@ Config::CheckResourceConfigSearchResources(const std::vector<std::string>& value
} }
Status Status
Config::CheckResourceConfigIndexBuildDevice(const std::string& value) { Config::CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>& value) {
auto status = CheckResource(value); if (value.empty()) {
if (!status.ok()) { std::string msg =
return Status(SERVER_INVALID_ARGUMENT, status.message()); "Invalid gpu build index resource. "
"Possible reason: gpu_resource_config.build_index_resources is empty.";
return Status(SERVER_INVALID_ARGUMENT, msg);
}
for (auto& resource : value) {
auto status = CheckGpuResource(resource);
if (!status.ok()) {
return Status(SERVER_INVALID_ARGUMENT, status.message());
}
} }
return Status::OK(); return Status::OK();
} }
...@@ -855,7 +861,6 @@ Config::GetDBConfigArchiveDiskThreshold(int32_t& value) { ...@@ -855,7 +861,6 @@ Config::GetDBConfigArchiveDiskThreshold(int32_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
...@@ -868,7 +873,6 @@ Config::GetDBConfigArchiveDaysThreshold(int32_t& value) { ...@@ -868,7 +873,6 @@ Config::GetDBConfigArchiveDaysThreshold(int32_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
...@@ -880,7 +884,6 @@ Config::GetDBConfigInsertBufferSize(int32_t& value) { ...@@ -880,7 +884,6 @@ Config::GetDBConfigInsertBufferSize(int32_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
...@@ -898,7 +901,6 @@ Config::GetMetricConfigEnableMonitor(bool& value) { ...@@ -898,7 +901,6 @@ Config::GetMetricConfigEnableMonitor(bool& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
std::transform(str.begin(), str.end(), str.begin(), ::tolower); std::transform(str.begin(), str.end(), str.begin(), ::tolower);
value = (str == "true" || str == "on" || str == "yes" || str == "1"); value = (str == "true" || str == "on" || str == "yes" || str == "1");
return Status::OK(); return Status::OK();
...@@ -924,7 +926,6 @@ Config::GetCacheConfigCpuCacheCapacity(int64_t& value) { ...@@ -924,7 +926,6 @@ Config::GetCacheConfigCpuCacheCapacity(int64_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
...@@ -937,33 +938,6 @@ Config::GetCacheConfigCpuCacheThreshold(float& value) { ...@@ -937,33 +938,6 @@ Config::GetCacheConfigCpuCacheThreshold(float& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stof(str);
return Status::OK();
}
Status
Config::GetCacheConfigGpuCacheCapacity(int64_t& value) {
std::string str =
GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_CAPACITY, CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT);
Status s = CheckCacheConfigGpuCacheCapacity(str);
if (!s.ok()) {
return s;
}
value = std::stoi(str);
return Status::OK();
}
Status
Config::GetCacheConfigGpuCacheThreshold(float& value) {
std::string str =
GetConfigStr(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_THRESHOLD, CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT);
Status s = CheckCacheConfigGpuCacheThreshold(str);
if (!s.ok()) {
return s;
}
value = std::stof(str); value = std::stof(str);
return Status::OK(); return Status::OK();
} }
...@@ -976,7 +950,6 @@ Config::GetCacheConfigCacheInsertData(bool& value) { ...@@ -976,7 +950,6 @@ Config::GetCacheConfigCacheInsertData(bool& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
std::transform(str.begin(), str.end(), str.begin(), ::tolower); std::transform(str.begin(), str.end(), str.begin(), ::tolower);
value = (str == "true" || str == "on" || str == "yes" || str == "1"); value = (str == "true" || str == "on" || str == "yes" || str == "1");
return Status::OK(); return Status::OK();
...@@ -990,7 +963,6 @@ Config::GetEngineConfigUseBlasThreshold(int32_t& value) { ...@@ -990,7 +963,6 @@ Config::GetEngineConfigUseBlasThreshold(int32_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
...@@ -1002,7 +974,6 @@ Config::GetEngineConfigOmpThreadNum(int32_t& value) { ...@@ -1002,7 +974,6 @@ Config::GetEngineConfigOmpThreadNum(int32_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
...@@ -1015,41 +986,113 @@ Config::GetEngineConfigGpuSearchThreshold(int32_t& value) { ...@@ -1015,41 +986,113 @@ Config::GetEngineConfigGpuSearchThreshold(int32_t& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
value = std::stoi(str); value = std::stoi(str);
return Status::OK(); return Status::OK();
} }
Status Status
Config::GetResourceConfigMode(std::string& value) { Config::GetGpuResourceConfigEnableGpu(bool& value) {
value = GetConfigStr(CONFIG_RESOURCE, CONFIG_RESOURCE_MODE, CONFIG_RESOURCE_MODE_DEFAULT); std::string str =
return CheckResourceConfigMode(value); GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE_GPU, CONFIG_GPU_RESOURCE_ENABLE_GPU_DEFAULT);
Status s = CheckGpuResourceConfigEnableGpu(str);
if (!s.ok()) {
return s;
}
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
value = (str == "true" || str == "on" || str == "yes" || str == "1");
return Status::OK();
} }
Status Status
Config::GetResourceConfigSearchResources(std::vector<std::string>& value) { Config::GetGpuResourceConfigCacheCapacity(int64_t& value) {
std::string str = bool enable_gpu = false;
GetConfigSequenceStr(CONFIG_RESOURCE, CONFIG_RESOURCE_SEARCH_RESOURCES, Status s = GetGpuResourceConfigEnableGpu(enable_gpu);
CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT); if (!s.ok()) {
server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, value); return s;
return CheckResourceConfigSearchResources(value); }
if (!enable_gpu) {
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable_gpu is set to false.";
return Status(SERVER_UNSUPPORTED_ERROR, msg);
}
std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY,
CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT);
s = CheckGpuResourceConfigCacheCapacity(str);
if (!s.ok()) {
return s;
}
value = std::stoi(str);
return Status::OK();
} }
Status Status
Config::GetResourceConfigIndexBuildDevice(int32_t& value) { Config::GetGpuResourceConfigCacheThreshold(float& value) {
std::string str = bool enable_gpu = false;
GetConfigStr(CONFIG_RESOURCE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT); Status s = GetGpuResourceConfigEnableGpu(enable_gpu);
Status s = CheckResourceConfigIndexBuildDevice(str);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
if (!enable_gpu) {
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable_gpu is set to false.";
return Status(SERVER_UNSUPPORTED_ERROR, msg);
}
std::string str = GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD,
CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT);
s = CheckGpuResourceConfigCacheThreshold(str);
if (!s.ok()) {
return s;
}
value = std::stof(str);
return Status::OK();
}
if (str == "cpu") { Status
value = CPU_DEVICE_ID; Config::GetGpuResourceConfigSearchResources(std::vector<int32_t>& value) {
} else { bool enable_gpu = false;
value = std::stoi(str.substr(3)); Status s = GetGpuResourceConfigEnableGpu(enable_gpu);
if (!s.ok()) {
return s;
}
if (!enable_gpu) {
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable_gpu is set to false.";
return Status(SERVER_UNSUPPORTED_ERROR, msg);
}
std::string str = GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES,
CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT);
std::vector<std::string> res_vec;
server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
s = CheckGpuResourceConfigSearchResources(res_vec);
if (!s.ok()) {
return s;
} }
for (std::string& res : res_vec) {
value.push_back(std::stoi(res.substr(3)));
}
return Status::OK();
}
Status
Config::GetGpuResourceConfigBuildIndexResources(std::vector<int32_t>& value) {
bool enable_gpu = false;
Status s = GetGpuResourceConfigEnableGpu(enable_gpu);
if (!s.ok()) {
return s;
}
if (!enable_gpu) {
std::string msg = "GPU not supported. Possible reason: gpu_resource_config.enable_gpu is set to false.";
return Status(SERVER_UNSUPPORTED_ERROR, msg);
}
std::string str =
GetConfigSequenceStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES,
CONFIG_GPU_RESOURCE_DELIMITER, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT);
std::vector<std::string> res_vec;
server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
s = CheckGpuResourceConfigBuildIndexResources(res_vec);
if (!s.ok()) {
return s;
}
for (std::string& res : res_vec) {
value.push_back(std::stoi(res.substr(3)));
}
return Status::OK(); return Status::OK();
} }
...@@ -1061,7 +1104,6 @@ Config::SetServerConfigAddress(const std::string& value) { ...@@ -1061,7 +1104,6 @@ Config::SetServerConfigAddress(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value); SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_ADDRESS, value);
return Status::OK(); return Status::OK();
} }
...@@ -1072,7 +1114,6 @@ Config::SetServerConfigPort(const std::string& value) { ...@@ -1072,7 +1114,6 @@ Config::SetServerConfigPort(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value); SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_PORT, value);
return Status::OK(); return Status::OK();
} }
...@@ -1083,7 +1124,6 @@ Config::SetServerConfigDeployMode(const std::string& value) { ...@@ -1083,7 +1124,6 @@ Config::SetServerConfigDeployMode(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value); SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_DEPLOY_MODE, value);
return Status::OK(); return Status::OK();
} }
...@@ -1094,7 +1134,6 @@ Config::SetServerConfigTimeZone(const std::string& value) { ...@@ -1094,7 +1134,6 @@ Config::SetServerConfigTimeZone(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value); SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value);
return Status::OK(); return Status::OK();
} }
...@@ -1106,7 +1145,6 @@ Config::SetDBConfigPrimaryPath(const std::string& value) { ...@@ -1106,7 +1145,6 @@ Config::SetDBConfigPrimaryPath(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRIMARY_PATH, value); SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRIMARY_PATH, value);
return Status::OK(); return Status::OK();
} }
...@@ -1117,7 +1155,6 @@ Config::SetDBConfigSecondaryPath(const std::string& value) { ...@@ -1117,7 +1155,6 @@ Config::SetDBConfigSecondaryPath(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_SECONDARY_PATH, value); SetConfigValueInMem(CONFIG_DB, CONFIG_DB_SECONDARY_PATH, value);
return Status::OK(); return Status::OK();
} }
...@@ -1128,7 +1165,6 @@ Config::SetDBConfigBackendUrl(const std::string& value) { ...@@ -1128,7 +1165,6 @@ Config::SetDBConfigBackendUrl(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value); SetConfigValueInMem(CONFIG_DB, CONFIG_DB_BACKEND_URL, value);
return Status::OK(); return Status::OK();
} }
...@@ -1139,7 +1175,6 @@ Config::SetDBConfigArchiveDiskThreshold(const std::string& value) { ...@@ -1139,7 +1175,6 @@ Config::SetDBConfigArchiveDiskThreshold(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value); SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DISK_THRESHOLD, value);
return Status::OK(); return Status::OK();
} }
...@@ -1150,7 +1185,6 @@ Config::SetDBConfigArchiveDaysThreshold(const std::string& value) { ...@@ -1150,7 +1185,6 @@ Config::SetDBConfigArchiveDaysThreshold(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value); SetConfigValueInMem(CONFIG_DB, CONFIG_DB_ARCHIVE_DAYS_THRESHOLD, value);
return Status::OK(); return Status::OK();
} }
...@@ -1161,7 +1195,6 @@ Config::SetDBConfigInsertBufferSize(const std::string& value) { ...@@ -1161,7 +1195,6 @@ Config::SetDBConfigInsertBufferSize(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, value); SetConfigValueInMem(CONFIG_DB, CONFIG_DB_INSERT_BUFFER_SIZE, value);
return Status::OK(); return Status::OK();
} }
...@@ -1173,7 +1206,6 @@ Config::SetMetricConfigEnableMonitor(const std::string& value) { ...@@ -1173,7 +1206,6 @@ Config::SetMetricConfigEnableMonitor(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, value); SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_ENABLE_MONITOR, value);
return Status::OK(); return Status::OK();
} }
...@@ -1184,7 +1216,6 @@ Config::SetMetricConfigCollector(const std::string& value) { ...@@ -1184,7 +1216,6 @@ Config::SetMetricConfigCollector(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_COLLECTOR, value); SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_COLLECTOR, value);
return Status::OK(); return Status::OK();
} }
...@@ -1195,7 +1226,6 @@ Config::SetMetricConfigPrometheusPort(const std::string& value) { ...@@ -1195,7 +1226,6 @@ Config::SetMetricConfigPrometheusPort(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_PROMETHEUS_PORT, value); SetConfigValueInMem(CONFIG_METRIC, CONFIG_METRIC_PROMETHEUS_PORT, value);
return Status::OK(); return Status::OK();
} }
...@@ -1207,7 +1237,6 @@ Config::SetCacheConfigCpuCacheCapacity(const std::string& value) { ...@@ -1207,7 +1237,6 @@ Config::SetCacheConfigCpuCacheCapacity(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value); SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_CAPACITY, value);
return Status::OK(); return Status::OK();
} }
...@@ -1218,40 +1247,16 @@ Config::SetCacheConfigCpuCacheThreshold(const std::string& value) { ...@@ -1218,40 +1247,16 @@ Config::SetCacheConfigCpuCacheThreshold(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value); SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CPU_CACHE_THRESHOLD, value);
return Status::OK(); return Status::OK();
} }
Status
Config::SetCacheConfigGpuCacheCapacity(const std::string& value) {
Status s = CheckCacheConfigGpuCacheCapacity(value);
if (!s.ok()) {
return s;
}
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_CAPACITY, value);
return Status::OK();
}
Status
Config::SetCacheConfigGpuCacheThreshold(const std::string& value) {
Status s = CheckCacheConfigGpuCacheThreshold(value);
if (!s.ok()) {
return s;
}
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_GPU_CACHE_THRESHOLD, value);
return Status::OK();
}
Status Status
Config::SetCacheConfigCacheInsertData(const std::string& value) { Config::SetCacheConfigCacheInsertData(const std::string& value) {
Status s = CheckCacheConfigCacheInsertData(value); Status s = CheckCacheConfigCacheInsertData(value);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value); SetConfigValueInMem(CONFIG_CACHE, CONFIG_CACHE_CACHE_INSERT_DATA, value);
return Status::OK(); return Status::OK();
} }
...@@ -1263,7 +1268,6 @@ Config::SetEngineConfigUseBlasThreshold(const std::string& value) { ...@@ -1263,7 +1268,6 @@ Config::SetEngineConfigUseBlasThreshold(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value); SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_USE_BLAS_THRESHOLD, value);
return Status::OK(); return Status::OK();
} }
...@@ -1274,7 +1278,6 @@ Config::SetEngineConfigOmpThreadNum(const std::string& value) { ...@@ -1274,7 +1278,6 @@ Config::SetEngineConfigOmpThreadNum(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, value); SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_OMP_THREAD_NUM, value);
return Status::OK(); return Status::OK();
} }
...@@ -1285,45 +1288,62 @@ Config::SetEngineConfigGpuSearchThreshold(const std::string& value) { ...@@ -1285,45 +1288,62 @@ Config::SetEngineConfigGpuSearchThreshold(const std::string& value) {
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value); SetConfigValueInMem(CONFIG_ENGINE, CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, value);
return Status::OK(); return Status::OK();
} }
/* resource config */ /* gpu resource config */
Status Status
Config::SetResourceConfigMode(const std::string& value) { Config::SetGpuResourceConfigEnableGpu(const std::string& value) {
Status s = CheckResourceConfigMode(value); Status s = CheckGpuResourceConfigEnableGpu(value);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE_GPU, value);
SetConfigValueInMem(CONFIG_RESOURCE, CONFIG_RESOURCE_MODE, value);
return Status::OK(); return Status::OK();
} }
Status Status
Config::SetResourceConfigSearchResources(const std::string& value) { Config::SetGpuResourceConfigCacheCapacity(const std::string& value) {
std::vector<std::string> res_vec; Status s = CheckGpuResourceConfigCacheCapacity(value);
server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, res_vec);
Status s = CheckResourceConfigSearchResources(res_vec);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_CAPACITY, value);
return Status::OK();
}
SetConfigValueInMem(CONFIG_RESOURCE, CONFIG_RESOURCE_SEARCH_RESOURCES, value); Status
Config::SetGpuResourceConfigCacheThreshold(const std::string& value) {
Status s = CheckGpuResourceConfigCacheThreshold(value);
if (!s.ok()) {
return s;
}
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, value);
return Status::OK(); return Status::OK();
} }
Status Status
Config::SetResourceConfigIndexBuildDevice(const std::string& value) { Config::SetGpuResourceConfigSearchResources(const std::string& value) {
Status s = CheckResourceConfigIndexBuildDevice(value); std::vector<std::string> res_vec;
server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
Status s = CheckGpuResourceConfigSearchResources(res_vec);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, value);
return Status::OK();
}
SetConfigValueInMem(CONFIG_RESOURCE, CONFIG_RESOURCE_INDEX_BUILD_DEVICE, value); Status
Config::SetGpuResourceConfigBuildIndexResources(const std::string& value) {
std::vector<std::string> res_vec;
server::StringHelpFunctions::SplitStringByDelimeter(value, CONFIG_GPU_RESOURCE_DELIMITER, res_vec);
Status s = CheckGpuResourceConfigBuildIndexResources(res_vec);
if (!s.ok()) {
return s;
}
SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, value);
return Status::OK(); return Status::OK();
} }
......
...@@ -59,12 +59,8 @@ static const char* CONFIG_DB_PRELOAD_TABLE = "preload_table"; ...@@ -59,12 +59,8 @@ static const char* CONFIG_DB_PRELOAD_TABLE = "preload_table";
static const char* CONFIG_CACHE = "cache_config"; static const char* CONFIG_CACHE = "cache_config";
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY = "cpu_cache_capacity"; static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY = "cpu_cache_capacity";
static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT = "16"; static const char* CONFIG_CACHE_CPU_CACHE_CAPACITY_DEFAULT = "16";
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY = "gpu_cache_capacity"; static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_cache_threshold";
static const char* CONFIG_CACHE_GPU_CACHE_CAPACITY_DEFAULT = "4";
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD = "cpu_mem_threshold";
static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT = "0.85"; static const char* CONFIG_CACHE_CPU_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_CACHE_GPU_CACHE_THRESHOLD = "gpu_mem_threshold";
static const char* CONFIG_CACHE_GPU_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data"; static const char* CONFIG_CACHE_CACHE_INSERT_DATA = "cache_insert_data";
static const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "false"; static const char* CONFIG_CACHE_CACHE_INSERT_DATA_DEFAULT = "false";
...@@ -87,26 +83,23 @@ static const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0"; ...@@ -87,26 +83,23 @@ static const char* CONFIG_ENGINE_OMP_THREAD_NUM_DEFAULT = "0";
static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD = "gpu_search_threshold"; static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD = "gpu_search_threshold";
static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT = "1000"; static const char* CONFIG_ENGINE_GPU_SEARCH_THRESHOLD_DEFAULT = "1000";
/* resource config */ /* gpu resource config */
static const char* CONFIG_RESOURCE = "resource_config"; static const char* CONFIG_GPU_RESOURCE = "gpu_resource_config";
static const char* CONFIG_RESOURCE_MODE = "mode"; static const char* CONFIG_GPU_RESOURCE_ENABLE_GPU = "enable_gpu";
static const char* CONFIG_RESOURCE_MODE_DEFAULT = "simple"; #ifdef MILVUS_GPU_VERSION
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES = "search_resources"; static const char* CONFIG_GPU_RESOURCE_ENABLE_GPU_DEFAULT = "true";
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER = ",";
#ifdef MILVUS_CPU_VERSION
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT = "cpu";
#else
static const char* CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT = "cpu,gpu0";
#endif
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE = "index_build_device";
#ifdef MILVUS_CPU_VERSION
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT = "cpu";
#else #else
static const char* CONFIG_RESOURCE_INDEX_BUILD_DEVICE_DEFAULT = "gpu0"; static const char* CONFIG_GPU_RESOURCE_ENABLE_GPU_DEFAULT = "false";
#endif #endif
const int32_t CPU_DEVICE_ID = -1; static const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY = "cache_capacity";
static const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT = "4";
static const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD = "cache_threshold";
static const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT = "0.85";
static const char* CONFIG_GPU_RESOURCE_DELIMITER = ",";
static const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES = "search_resources";
static const char* CONFIG_GPU_RESOURCE_SEARCH_RESOURCES_DEFAULT = "gpu0";
static const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES = "build_index_resources";
static const char* CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT = "gpu0";
class Config { class Config {
public: public:
...@@ -170,10 +163,6 @@ class Config { ...@@ -170,10 +163,6 @@ class Config {
Status Status
CheckCacheConfigCpuCacheThreshold(const std::string& value); CheckCacheConfigCpuCacheThreshold(const std::string& value);
Status Status
CheckCacheConfigGpuCacheCapacity(const std::string& value);
Status
CheckCacheConfigGpuCacheThreshold(const std::string& value);
Status
CheckCacheConfigCacheInsertData(const std::string& value); CheckCacheConfigCacheInsertData(const std::string& value);
/* engine config */ /* engine config */
...@@ -184,13 +173,17 @@ class Config { ...@@ -184,13 +173,17 @@ class Config {
Status Status
CheckEngineConfigGpuSearchThreshold(const std::string& value); CheckEngineConfigGpuSearchThreshold(const std::string& value);
/* resource config */ /* gpu resource config */
Status
CheckGpuResourceConfigEnableGpu(const std::string& value);
Status
CheckGpuResourceConfigCacheCapacity(const std::string& value);
Status Status
CheckResourceConfigMode(const std::string& value); CheckGpuResourceConfigCacheThreshold(const std::string& value);
Status Status
CheckResourceConfigSearchResources(const std::vector<std::string>& value); CheckGpuResourceConfigSearchResources(const std::vector<std::string>& value);
Status Status
CheckResourceConfigIndexBuildDevice(const std::string& value); CheckGpuResourceConfigBuildIndexResources(const std::vector<std::string>& value);
std::string std::string
GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = ""); GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = "");
...@@ -239,10 +232,6 @@ class Config { ...@@ -239,10 +232,6 @@ class Config {
Status Status
GetCacheConfigCpuCacheThreshold(float& value); GetCacheConfigCpuCacheThreshold(float& value);
Status Status
GetCacheConfigGpuCacheCapacity(int64_t& value);
Status
GetCacheConfigGpuCacheThreshold(float& value);
Status
GetCacheConfigCacheInsertData(bool& value); GetCacheConfigCacheInsertData(bool& value);
/* engine config */ /* engine config */
...@@ -253,13 +242,17 @@ class Config { ...@@ -253,13 +242,17 @@ class Config {
Status Status
GetEngineConfigGpuSearchThreshold(int32_t& value); GetEngineConfigGpuSearchThreshold(int32_t& value);
/* resource config */ /* gpu resource config */
Status
GetGpuResourceConfigEnableGpu(bool& value);
Status
GetGpuResourceConfigCacheCapacity(int64_t& value);
Status Status
GetResourceConfigMode(std::string& value); GetGpuResourceConfigCacheThreshold(float& value);
Status Status
GetResourceConfigSearchResources(std::vector<std::string>& value); GetGpuResourceConfigSearchResources(std::vector<int32_t>& value);
Status Status
GetResourceConfigIndexBuildDevice(int32_t& value); GetGpuResourceConfigBuildIndexResources(std::vector<int32_t>& value);
public: public:
/* server config */ /* server config */
...@@ -300,10 +293,6 @@ class Config { ...@@ -300,10 +293,6 @@ class Config {
Status Status
SetCacheConfigCpuCacheThreshold(const std::string& value); SetCacheConfigCpuCacheThreshold(const std::string& value);
Status Status
SetCacheConfigGpuCacheCapacity(const std::string& value);
Status
SetCacheConfigGpuCacheThreshold(const std::string& value);
Status
SetCacheConfigCacheInsertData(const std::string& value); SetCacheConfigCacheInsertData(const std::string& value);
/* engine config */ /* engine config */
...@@ -314,13 +303,17 @@ class Config { ...@@ -314,13 +303,17 @@ class Config {
Status Status
SetEngineConfigGpuSearchThreshold(const std::string& value); SetEngineConfigGpuSearchThreshold(const std::string& value);
/* resource config */ /* gpu resource config */
Status
SetGpuResourceConfigEnableGpu(const std::string& value);
Status
SetGpuResourceConfigCacheCapacity(const std::string& value);
Status Status
SetResourceConfigMode(const std::string& value); SetGpuResourceConfigCacheThreshold(const std::string& value);
Status Status
SetResourceConfigSearchResources(const std::string& value); SetGpuResourceConfigSearchResources(const std::string& value);
Status Status
SetResourceConfigIndexBuildDevice(const std::string& value); SetGpuResourceConfigBuildIndexResources(const std::string& value);
private: private:
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_; std::unordered_map<std::string, std::unordered_map<std::string, std::string>> config_map_;
......
...@@ -182,7 +182,7 @@ ValidationUtil::ValidatePartitionTags(const std::vector<std::string>& partition_ ...@@ -182,7 +182,7 @@ ValidationUtil::ValidatePartitionTags(const std::vector<std::string>& partition_
} }
Status Status
ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) { ValidationUtil::ValidateGpuIndex(int32_t gpu_index) {
#ifdef MILVUS_GPU_VERSION #ifdef MILVUS_GPU_VERSION
int num_devices = 0; int num_devices = 0;
auto cuda_err = cudaGetDeviceCount(&num_devices); auto cuda_err = cudaGetDeviceCount(&num_devices);
...@@ -203,7 +203,7 @@ ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) { ...@@ -203,7 +203,7 @@ ValidationUtil::ValidateGpuIndex(uint32_t gpu_index) {
} }
Status Status
ValidationUtil::GetGpuMemory(uint32_t gpu_index, size_t& memory) { ValidationUtil::GetGpuMemory(int32_t gpu_index, size_t& memory) {
#ifdef MILVUS_GPU_VERSION #ifdef MILVUS_GPU_VERSION
cudaDeviceProp deviceProp; cudaDeviceProp deviceProp;
......
...@@ -59,10 +59,10 @@ class ValidationUtil { ...@@ -59,10 +59,10 @@ class ValidationUtil {
ValidatePartitionTags(const std::vector<std::string>& partition_tags); ValidatePartitionTags(const std::vector<std::string>& partition_tags);
static Status static Status
ValidateGpuIndex(uint32_t gpu_index); ValidateGpuIndex(int32_t gpu_index);
static Status static Status
GetGpuMemory(uint32_t gpu_index, size_t& memory); GetGpuMemory(int32_t gpu_index, size_t& memory);
static Status static Status
ValidateIpAddress(const std::string& ip_address); ValidateIpAddress(const std::string& ip_address);
......
...@@ -216,21 +216,6 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) { ...@@ -216,21 +216,6 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
s = config.GetCacheConfigCpuCacheThreshold(float_val); s = config.GetCacheConfigCpuCacheThreshold(float_val);
ASSERT_TRUE(float_val == cache_cpu_cache_threshold); ASSERT_TRUE(float_val == cache_cpu_cache_threshold);
#ifdef MILVUS_GPU_VERSION
int64_t cache_gpu_cache_capacity = 1;
s = config.SetCacheConfigGpuCacheCapacity(std::to_string(cache_gpu_cache_capacity));
ASSERT_TRUE(s.ok());
s = config.GetCacheConfigGpuCacheCapacity(int64_val);
ASSERT_TRUE(s.ok());
ASSERT_TRUE(int64_val == cache_gpu_cache_capacity);
float cache_gpu_cache_threshold = 0.2;
s = config.SetCacheConfigGpuCacheThreshold(std::to_string(cache_gpu_cache_threshold));
ASSERT_TRUE(s.ok());
s = config.GetCacheConfigGpuCacheThreshold(float_val);
ASSERT_TRUE(float_val == cache_gpu_cache_threshold);
#endif
bool cache_insert_data = true; bool cache_insert_data = true;
s = config.SetCacheConfigCacheInsertData(std::to_string(cache_insert_data)); s = config.SetCacheConfigCacheInsertData(std::to_string(cache_insert_data));
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
...@@ -259,42 +244,54 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) { ...@@ -259,42 +244,54 @@ TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
ASSERT_TRUE(int32_val == engine_gpu_search_threshold); ASSERT_TRUE(int32_val == engine_gpu_search_threshold);
/* resource config */ /* gpu resource config */
std::string resource_mode = "simple"; bool resource_enable_gpu = true;
s = config.SetResourceConfigMode(resource_mode); s = config.SetGpuResourceConfigEnableGpu(std::to_string(resource_enable_gpu));
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
s = config.GetResourceConfigMode(str_val); s = config.GetGpuResourceConfigEnableGpu(bool_val);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
ASSERT_TRUE(str_val == resource_mode); ASSERT_TRUE(bool_val == resource_enable_gpu);
#ifdef MILVUS_CPU_VERSION #ifdef MILVUS_GPU_VERSION
std::vector<std::string> search_resources = {"cpu"}; int64_t gpu_cache_capacity = 1;
#else s = config.SetGpuResourceConfigCacheCapacity(std::to_string(gpu_cache_capacity));
std::vector<std::string> search_resources = {"cpu", "gpu0"}; ASSERT_TRUE(s.ok());
#endif s = config.GetGpuResourceConfigCacheCapacity(int64_val);
std::vector<std::string> res_vec; ASSERT_TRUE(s.ok());
std::string res_str; ASSERT_TRUE(int64_val == gpu_cache_capacity);
float gpu_cache_threshold = 0.2;
s = config.SetGpuResourceConfigCacheThreshold(std::to_string(gpu_cache_threshold));
ASSERT_TRUE(s.ok());
s = config.GetGpuResourceConfigCacheThreshold(float_val);
ASSERT_TRUE(float_val == gpu_cache_threshold);
std::vector<std::string> search_resources = {"gpu0"};
std::vector<int32_t> search_res_vec;
std::string search_res_str;
milvus::server::StringHelpFunctions::MergeStringWithDelimeter( milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
search_resources, milvus::server::CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, res_str); search_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, search_res_str);
s = config.SetResourceConfigSearchResources(res_str); s = config.SetGpuResourceConfigSearchResources(search_res_str);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
s = config.GetResourceConfigSearchResources(res_vec); s = config.GetGpuResourceConfigSearchResources(search_res_vec);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
for (size_t i = 0; i < search_resources.size(); i++) { for (size_t i = 0; i < search_resources.size(); i++) {
ASSERT_TRUE(search_resources[i] == res_vec[i]); ASSERT_TRUE(std::stoi(search_resources[i].substr(3)) == search_res_vec[i]);
} }
#ifdef MILVUS_CPU_VERSION std::vector<std::string> build_index_resources = {"gpu0"};
int32_t resource_index_build_device = milvus::server::CPU_DEVICE_ID; std::vector<int32_t> build_index_res_vec;
s = config.SetResourceConfigIndexBuildDevice("cpu"); std::string build_index_res_str;
#else milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
int32_t resource_index_build_device = 0; build_index_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, build_index_res_str);
s = config.SetResourceConfigIndexBuildDevice("gpu" + std::to_string(resource_index_build_device)); s = config.SetGpuResourceConfigBuildIndexResources(build_index_res_str);
#endif
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
s = config.GetResourceConfigIndexBuildDevice(int32_val); s = config.GetGpuResourceConfigBuildIndexResources(build_index_res_vec);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
ASSERT_TRUE(int32_val == resource_index_build_device); for (size_t i = 0; i < build_index_resources.size(); i++) {
ASSERT_TRUE(std::stoi(build_index_resources[i].substr(3)) == build_index_res_vec[i]);
}
#endif
} }
TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) { TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
...@@ -381,18 +378,6 @@ TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) { ...@@ -381,18 +378,6 @@ TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
s = config.SetCacheConfigCpuCacheThreshold("1.0"); s = config.SetCacheConfigCpuCacheThreshold("1.0");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
#ifdef MILVUS_GPU_VERSION
s = config.SetCacheConfigGpuCacheCapacity("a");
ASSERT_FALSE(s.ok());
s = config.SetCacheConfigGpuCacheCapacity("128");
ASSERT_FALSE(s.ok());
s = config.SetCacheConfigGpuCacheThreshold("a");
ASSERT_FALSE(s.ok());
s = config.SetCacheConfigGpuCacheThreshold("1.0");
ASSERT_FALSE(s.ok());
#endif
s = config.SetCacheConfigCacheInsertData("N"); s = config.SetCacheConfigCacheInsertData("N");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
...@@ -408,20 +393,29 @@ TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) { ...@@ -408,20 +393,29 @@ TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
s = config.SetEngineConfigGpuSearchThreshold("-1"); s = config.SetEngineConfigGpuSearchThreshold("-1");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
/* resource config */ /* gpu resource config */
s = config.SetResourceConfigMode("default"); s = config.SetGpuResourceConfigEnableGpu("ok");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
s = config.SetResourceConfigSearchResources("gpu10"); #ifdef MILVUS_GPU_VERSION
s = config.SetGpuResourceConfigCacheCapacity("a");
ASSERT_FALSE(s.ok());
s = config.SetGpuResourceConfigCacheCapacity("128");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
s = config.SetResourceConfigSearchResources("cpu"); s = config.SetGpuResourceConfigCacheThreshold("a");
ASSERT_TRUE(s.ok()); ASSERT_FALSE(s.ok());
s = config.SetGpuResourceConfigCacheThreshold("1.0");
ASSERT_FALSE(s.ok());
s = config.SetGpuResourceConfigSearchResources("gpu10");
ASSERT_FALSE(s.ok());
s = config.SetResourceConfigIndexBuildDevice("gup2"); s = config.SetGpuResourceConfigBuildIndexResources("gup2");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
s = config.SetResourceConfigIndexBuildDevice("gpu16"); s = config.SetGpuResourceConfigBuildIndexResources("gpu16");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
#endif
} }
TEST_F(ConfigTest, SERVER_CONFIG_TEST) { TEST_F(ConfigTest, SERVER_CONFIG_TEST) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册