Browse Source

assign graph memory max size and variable memory max size adaptively

tags/v1.5.1
lichun 3 years ago
parent
commit
5bf4d4c424
3 changed files with 49 additions and 7 deletions
  1. +40
    -7
      ge/graph/manager/graph_var_manager.cc
  2. +3
    -0
      ge/graph/manager/graph_var_manager.h
  3. +6
    -0
      tests/depends/runtime/src/runtime_stub.cc

+ 40
- 7
ge/graph/manager/graph_var_manager.cc View File

@@ -20,6 +20,7 @@
#include "graph/manager/graph_mem_manager.h"
#include "graph/manager/trans_var_data_utils.h"
#include "graph/utils/type_utils.h"
#include "graph/ge_context.h"

using std::map;
using std::string;
@@ -767,24 +768,54 @@ Status VarManager::GetChangedGraphId(const std::string &var_name, uint32_t &grap
return var_resource_->GetChangedGraphId(var_name, graph_id);
}

Status VarManager::GetTotalMemorySize(size_t &total_mem_size) {
rtError_t rt_ret = rtSetDevice(GetContext().DeviceId());
if (rt_ret != RT_ERROR_NONE) {
REPORT_CALL_ERROR("E19999", "Call rtSetDevice failed, device_id:%u, ret:0x%X",
GetContext().DeviceId(), rt_ret);
GELOGE(RT_FAILED, "[Call][RtSetDevice] failed, device_id:%u, ret:0x%X", GetContext().DeviceId(), rt_ret);
return RT_FAILED;
}
size_t free_mem = 0;
rt_ret = rtMemGetInfoEx(RT_MEMORYINFO_HBM, &free_mem, &total_mem_size);
if (rt_ret != RT_ERROR_NONE) {
REPORT_CALL_ERROR("E19999", "Call rtMemGetInfo failed, ret:0x%X", rt_ret);
GELOGE(RT_FAILED, "[Call][RtMemGetInfo] failed, ret:0x%X", rt_ret);
return RT_FAILED;
}
rt_ret = rtDeviceReset(GetContext().DeviceId());
if (rt_ret != RT_ERROR_NONE) {
REPORT_CALL_ERROR("E19999", "Call rtDeviceReset failed, device_id:%u, ret:0x%X",
GetContext().DeviceId(), rt_ret);
GELOGE(RT_FAILED, "[Call][RtDeviceReset] failed, device_id:%u, ret:0x%X", GetContext().DeviceId(), rt_ret);
return RT_FAILED;
}
return SUCCESS;
}

Status VarManager::SetMemoryMallocSize(const map<string, string> &options) {
size_t total_mem_size = 0;
Status ret = VarManager::GetTotalMemorySize(total_mem_size);
if (ret != SUCCESS) {
return ret;
}
GEEVENT("Total memory size is %zu", total_mem_size);

graph_mem_max_size_ = floor(total_mem_size * kGraphMemoryManagerMallocRatio);
var_mem_max_size_ = floor(total_mem_size * kVarMemoryManagerMallocRatio);

auto it = options.find(GRAPH_MEMORY_MAX_SIZE);
if (it == options.end()) {
graph_mem_max_size_ = kGraphMemoryManagerMallocMaxSize;
} else {
if (it != options.end()) {
string graph_memory_manager_malloc_max_size = it->second;
ge::Status ret = ParseMemoryMallocSize(graph_memory_manager_malloc_max_size, graph_mem_max_size_);
if (ret != SUCCESS) {
GELOGE(ge::GE_GRAPH_OPTIONS_INVALID, "[Call][ParseMemoryMallocSize] failed, session id:%lu.", session_id_);
return ge::GE_GRAPH_OPTIONS_INVALID;
}
GELOGI("The max size for graph mem is set to %zu", graph_mem_max_size_);
}

it = options.find(VARIABLE_MEMORY_MAX_SIZE);
if (it == options.end()) {
var_mem_max_size_ = kMemoryVarManagerMallocSize;
} else {
if (it != options.end()) {
string memory_var_manager_malloc_size = it->second;
ge::Status ret = ParseMemoryMallocSize(memory_var_manager_malloc_size, var_mem_max_size_);
if (ret != SUCCESS) {
@@ -793,6 +824,8 @@ Status VarManager::SetMemoryMallocSize(const map<string, string> &options) {
}
}

GEEVENT("The graph_mem_max_size is %zu and the var_mem_max_size is %zu", graph_mem_max_size_, var_mem_max_size_);

var_mem_logic_base_ = graph_mem_max_size_ + kGraphMemoryBuffer;
if (var_mem_logic_base_ > kMaxMemorySize) {
REPORT_INNER_ERROR("E19999", "var_login_base:%zu can not exeed limit:%zu, session_id:%lu, check invalid",


+ 3
- 0
ge/graph/manager/graph_var_manager.h View File

@@ -43,6 +43,8 @@ const size_t kMaxMemorySize = 256UL * 1024UL * 1024UL * 1024UL;
const char kEnvGeuseStaticMemory[] = "GE_USE_STATIC_MEMORY";
const uint64_t kSessionMemAlignSize = 512;
const size_t kSessionMemAlignUnit = 2;
const double kGraphMemoryManagerMallocRatio = 26.0 / 32.0;
const double kVarMemoryManagerMallocRatio = 5.0 / 32.0;

enum MemStatus {
NORMAL = 0,
@@ -301,6 +303,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY VarManager {
mutable std::recursive_mutex mutex_;

Status ParseMemoryMallocSize(std::string &memory_size, size_t &my_size);
Status GetTotalMemorySize(size_t &total_mem_size);
};

class VarManagerPool {


+ 6
- 0
tests/depends/runtime/src/runtime_stub.cc View File

@@ -193,6 +193,12 @@ rtError_t rtMemGetInfo(size_t *free, size_t *total) {
return RT_ERROR_NONE;
}

rtError_t rtMemGetInfoEx(rtMemInfoType_t memInfoType, size_t *free, size_t *total) {
*free = 512UL * 1024UL * 1024UL;
*total = 1024UL * 1024UL * 1024UL;
return RT_ERROR_NONE;
}

rtError_t rtMemAllocManaged(void **ptr, uint64_t size, uint32_t flag) { return RT_ERROR_NONE; }

rtError_t rtMemFreeManaged(void *ptr) { return RT_ERROR_NONE; }


Loading…
Cancel
Save