add config value gpu.cache.enable (#2899)

* add config value gpu.cache.enable

Signed-off-by: wxyu <xy.wang@zilliz.com>

* clang-format

Signed-off-by: wxyu <xy.wang@zilliz.com>

* clang-format

Signed-off-by: wxyu <xy.wang@zilliz.com>

* fix ut

Signed-off-by: wxyu <xy.wang@zilliz.com>
This commit is contained in:
Wang XiangYu 2020-07-17 20:59:31 +08:00 committed by GitHub
parent 8135cee414
commit 283e087a78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 4 deletions

View File

@ -126,6 +126,8 @@ const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "true";
#else
const char* CONFIG_GPU_RESOURCE_ENABLE_DEFAULT = "false";
#endif
const char* CONFIG_GPU_RESOURCE_CACHE_ENABLE = "cache.enable";
const char* CONFIG_GPU_RESOURCE_CACHE_ENABLE_DEFAULT = "false";
const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY = "cache_size";
const char* CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT = "1073741824"; // 1024 * 1024 * 1024
const char* CONFIG_GPU_RESOURCE_CACHE_THRESHOLD = "cache_threshold";
@ -374,6 +376,9 @@ Config::ValidateConfig() {
std::cout << "GPU resources " << (gpu_resource_enable ? "ENABLED !" : "DISABLED !") << std::endl;
if (gpu_resource_enable) {
bool resource_cache_enable;
STATUS_CHECK(GetGpuResourceConfigCacheEnable(resource_cache_enable));
int64_t resource_cache_capacity;
STATUS_CHECK(GetGpuResourceConfigCacheCapacity(resource_cache_capacity));
@ -488,6 +493,7 @@ Config::ResetDefaultConfig() {
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
STATUS_CHECK(SetGpuResourceConfigEnable(CONFIG_GPU_RESOURCE_ENABLE_DEFAULT));
STATUS_CHECK(SetGpuResourceConfigCacheEnable(CONFIG_GPU_RESOURCE_CACHE_ENABLE_DEFAULT));
STATUS_CHECK(SetGpuResourceConfigCacheCapacity(CONFIG_GPU_RESOURCE_CACHE_CAPACITY_DEFAULT));
STATUS_CHECK(SetGpuResourceConfigCacheThreshold(CONFIG_GPU_RESOURCE_CACHE_THRESHOLD_DEFAULT));
STATUS_CHECK(SetGpuResourceConfigGpuSearchThreshold(CONFIG_GPU_RESOURCE_GPU_SEARCH_THRESHOLD_DEFAULT));
@ -629,6 +635,8 @@ Config::SetConfigCli(const std::string& parent_key, const std::string& child_key
} else if (parent_key == CONFIG_GPU_RESOURCE) {
if (child_key == CONFIG_GPU_RESOURCE_ENABLE) {
status = SetGpuResourceConfigEnable(value);
} else if (child_key == CONFIG_GPU_RESOURCE_CACHE_ENABLE) {
status = SetGpuResourceConfigCacheEnable(value);
} else if (child_key == CONFIG_GPU_RESOURCE_CACHE_CAPACITY) {
status = SetGpuResourceConfigCacheCapacity(value);
} else if (child_key == CONFIG_GPU_RESOURCE_CACHE_THRESHOLD) {
@ -1596,6 +1604,16 @@ Config::CheckGpuResourceConfigEnable(const std::string& value) {
return Status::OK();
}
Status
Config::CheckGpuResourceConfigCacheEnable(const std::string& value) {
if (!ValidationUtil::ValidateStringIsBool(value).ok()) {
std::string msg =
"Invalid gpu resource config: " + value + ". Possible reason: gpu.cache.enable is not a boolean.";
return Status(SERVER_INVALID_ARGUMENT, msg);
}
return Status::OK();
}
Status
Config::CheckGpuResourceConfigCacheCapacity(const std::string& value) {
fiu_return_on("check_gpu_cache_size_fail", Status(SERVER_INVALID_ARGUMENT, ""));
@ -2297,6 +2315,15 @@ Config::GetGpuResourceConfigEnable(bool& value) {
return Status::OK();
}
Status
Config::GetGpuResourceConfigCacheEnable(bool& value) {
std::string str =
GetConfigStr(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_ENABLE, CONFIG_GPU_RESOURCE_CACHE_ENABLE_DEFAULT);
STATUS_CHECK(CheckGpuResourceConfigCacheEnable(str));
STATUS_CHECK(StringHelpFunctions::ConvertToBoolean(str, value));
return Status::OK();
}
Status
Config::GetGpuResourceConfigCacheCapacity(int64_t& value) {
bool gpu_resource_enable = false;
@ -2734,7 +2761,6 @@ Config::SetEngineSearchCombineMaxNq(const std::string& value) {
/* gpu resource config */
#ifdef MILVUS_GPU_VERSION
Status
Config::SetGpuResourceConfigEnable(const std::string& value) {
STATUS_CHECK(CheckGpuResourceConfigEnable(value));
@ -2742,6 +2768,12 @@ Config::SetGpuResourceConfigEnable(const std::string& value) {
return ExecCallBacks(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_ENABLE, value);
}
Status
Config::SetGpuResourceConfigCacheEnable(const std::string& value) {
STATUS_CHECK(CheckGpuResourceConfigCacheEnable(value));
return SetConfigValueInMem(CONFIG_GPU_RESOURCE, CONFIG_GPU_RESOURCE_CACHE_ENABLE, value);
}
Status
Config::SetGpuResourceConfigCacheCapacity(const std::string& value) {
STATUS_CHECK(CheckGpuResourceConfigCacheCapacity(value));

View File

@ -278,6 +278,8 @@ class Config {
Status
CheckGpuResourceConfigEnable(const std::string& value);
Status
CheckGpuResourceConfigCacheEnable(const std::string& value);
Status
CheckGpuResourceConfigCacheCapacity(const std::string& value);
Status
CheckGpuResourceConfigCacheThreshold(const std::string& value);
@ -400,6 +402,8 @@ class Config {
Status
GetGpuResourceConfigEnable(bool& value);
Status
GetGpuResourceConfigCacheEnable(bool& value);
Status
GetGpuResourceConfigCacheCapacity(int64_t& value);
Status
GetGpuResourceConfigCacheThreshold(float& value);
@ -514,6 +518,8 @@ class Config {
Status
SetGpuResourceConfigEnable(const std::string& value);
Status
SetGpuResourceConfigCacheEnable(const std::string& value);
Status
SetGpuResourceConfigCacheCapacity(const std::string& value);
Status
SetGpuResourceConfigCacheThreshold(const std::string& value);

View File

@ -584,9 +584,17 @@ ExecutionEngineImpl::CopyToGpu(uint64_t device_id, bool hybrid) {
*/
LOG_ENGINE_DEBUG_ << "CPU to GPU" << device_id << " start";
auto gpu_cache_mgr = cache::GpuCacheMgr::GetInstance(device_id);
// gpu_cache_mgr->Reserve(index_->Size());
index_ = knowhere::cloner::CopyCpuToGpu(index_, device_id, knowhere::Config());
// gpu_cache_mgr->InsertItem(location_, std::static_pointer_cast<cache::DataObj>(index_));
bool gpu_cache_enable = false;
STATUS_CHECK(server::Config::GetInstance().GetGpuResourceConfigCacheEnable(gpu_cache_enable));
if (gpu_cache_enable) {
gpu_cache_mgr->Reserve(index_->Size());
index_ = knowhere::cloner::CopyCpuToGpu(index_, device_id, knowhere::Config());
gpu_cache_mgr->InsertItem(location_, std::static_pointer_cast<cache::DataObj>(index_));
} else {
index_ = knowhere::cloner::CopyCpuToGpu(index_, device_id, knowhere::Config());
}
LOG_ENGINE_DEBUG_ << "CPU to GPU" << device_id << " finished";
} catch (std::exception& e) {
LOG_ENGINE_ERROR_ << e.what();

View File

@ -136,6 +136,8 @@ class ExecutionEngineImpl : public ExecutionEngine {
milvus::json index_params_;
int64_t gpu_num_ = 0;
bool gpu_cache_enable_ = false;
};
} // namespace engine