Browse Source

Memory reuse switch

tags/v1.2.0
dingpeifei 5 years ago
parent
commit
db07f1c63d
6 changed files with 39 additions and 9 deletions
  1. +2
    -3
      mindspore/ccsrc/debug/debugger/debugger.cc
  2. +25
    -0
      mindspore/ccsrc/debug/env_config_parser.cc
  3. +5
    -0
      mindspore/ccsrc/debug/env_config_parser.h
  4. +2
    -3
      mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc
  5. +2
    -1
      mindspore/ccsrc/runtime/device/cpu/cpu_kernel_runtime.cc
  6. +3
    -2
      mindspore/ccsrc/runtime/device/kernel_runtime.cc

+ 2
- 3
mindspore/ccsrc/debug/debugger/debugger.cc View File

@@ -33,6 +33,7 @@
#include "runtime/device/kernel_runtime.h"
#include "debug/data_dump/e2e_dump.h"
#include "utils/config_manager.h"
#include "debug/env_config_parser.h"

using debugger::Chunk;
using debugger::EventReply;
@@ -81,10 +82,8 @@ Debugger::Debugger()
// configure partial memory reuse
partial_memory_ = CheckDebuggerPartialMemoryEnabled();

auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr);
// switch memory reuse on or off
context_ptr->set_param<bool>(MS_CTX_ENABLE_MEM_REUSE, partial_memory_);
EnvConfigParser::GetInstance().SetSysMemreuse(partial_memory_);
// print some message about memory reuse to user
if (partial_memory_) {
MS_LOG(WARNING)


+ 25
- 0
mindspore/ccsrc/debug/env_config_parser.cc View File

@@ -28,6 +28,8 @@ constexpr auto ENV_RDR_PATH = "MS_RDR_PATH";
constexpr auto KEY_RDR_SETTINGS = "rdr";
constexpr auto KEY_PATH = "path";
constexpr auto KEY_ENABLE = "enable";
constexpr auto kSysSettings = "sys";
constexpr auto kMemReuse = "mem_reuse";
} // namespace

namespace mindspore {
@@ -140,6 +142,7 @@ void EnvConfigParser::ParseFromFile() {

// Parse rdr seetings from file
ParseRdrSetting(j);
ParseMemReuseSetting(j);

ConfigToString();
}
@@ -154,6 +157,28 @@ void EnvConfigParser::Parse() {
ParseFromFile();
}

void EnvConfigParser::ParseMemReuseSetting(const nlohmann::json &content) {
auto sys_setting = content.find(kSysSettings);
if (sys_setting == content.end()) {
MS_LOG(INFO) << "The '" << kSysSettings << "' not exists. Please check the config file '" << config_file_
<< "' set by 'env_config_path' in context.";
return;
}
auto sys_memreuse = CheckJsonKeyExist(*sys_setting, kSysSettings, kMemReuse);
if (sys_memreuse.has_value()) {
ParseSysMemReuse(**sys_memreuse);
}
}

void EnvConfigParser::ParseSysMemReuse(const nlohmann::json &content) {
if (!content.is_boolean()) {
MS_LOG(WARNING) << "Json parse failed. 'enable' in " << kSysSettings << " should be boolean."
<< " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context.";
return;
}
sys_memreuse_ = content;
}

void EnvConfigParser::ParseRdrSetting(const nlohmann::json &content) {
auto rdr_setting = content.find(KEY_RDR_SETTINGS);
if (rdr_setting == content.end()) {


+ 5
- 0
mindspore/ccsrc/debug/env_config_parser.h View File

@@ -37,6 +37,8 @@ class EnvConfigParser {
bool HasRdrSetting() const { return has_rdr_setting_; }
bool RdrEnabled() const { return rdr_enabled_; }
std::string RdrPath() const { return rdr_path_; }
bool GetSysMemreuse() { return sys_memreuse_; }
void SetSysMemreuse(bool set_memreuse) { sys_memreuse_ = set_memreuse; }

private:
EnvConfigParser() {}
@@ -50,6 +52,7 @@ class EnvConfigParser {
bool has_rdr_setting_{false};
std::string rdr_path_{"./rdr/"};

bool sys_memreuse_{true};
void ParseFromFile();
void ParseFromEnv();
std::string GetIfstreamString(const std::ifstream &ifstream);
@@ -62,6 +65,8 @@ class EnvConfigParser {

void ParseRdrPath(const nlohmann::json &content);
void ParseRdrEnable(const nlohmann::json &content);
void ParseMemReuseSetting(const nlohmann::json &content);
void ParseSysMemReuse(const nlohmann::json &content);

void ConfigToString();
};


+ 2
- 3
mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc View File

@@ -43,6 +43,7 @@
#include "debug/anf_ir_dump.h"
#ifdef MEM_REUSE_DEBUG
#include "backend/optimizer/mem_reuse/mem_reuse_checker.h"
#include "debug/env_config_parser.h"
#endif
#include "runtime/device/ascend/executor/tiling/op_tiling_calculater.h"
#include "runtime/device/executor/executor_callback.h"
@@ -395,9 +396,7 @@ bool AscendKernelRuntime::GenTask(const session::KernelGraph *graph) {
MS_LOG(INFO) << "GenTask start. GraphId:" << graph->graph_id();
DumpJsonParser::GetInstance().UpdateNeedDumpKernels(NOT_NULL(graph));
#ifdef MEM_REUSE_DEBUG
auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr);
if (!context_ptr->get_param<bool>(MS_CTX_ENABLE_MEM_REUSE)) {
if (!EnvConfigParser::GetInstance().GetSysMemreuse()) {
// Get normal graph ir for memreuse
mindspore::memreuse::MemReuseChecker::GetInstance().CheckNormalIR(graph);
}


+ 2
- 1
mindspore/ccsrc/runtime/device/cpu/cpu_kernel_runtime.cc View File

@@ -35,6 +35,7 @@
#include "utils/profile.h"
#include "utils/trace_base.h"
#include "debug/data_dump/cpu_e2e_dump.h"
#include "debug/env_config_parser.h"
#ifdef MEM_REUSE_DEBUG
#include "backend/optimizer/mem_reuse/mem_reuse_checker.h"
#endif
@@ -59,7 +60,7 @@ void CPUKernelRuntime::AssignKernelAddress(session::KernelGraph *kernel_graph) {
AssignInputNodeAddress(kernel_graph);
auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr);
bool is_enable_mem_reuse = context_ptr->get_param<bool>(MS_CTX_ENABLE_MEM_REUSE);
bool is_enable_mem_reuse = EnvConfigParser::GetInstance().GetSysMemreuse();
if (context_ptr->get_param<int>(MS_CTX_EXECUTION_MODE) == kPynativeMode) {
// disable mem reuse for kPynativeMode
is_enable_mem_reuse = false;


+ 3
- 2
mindspore/ccsrc/runtime/device/kernel_runtime.cc View File

@@ -31,6 +31,7 @@
#include "utils/shape_utils.h"
#include "utils/utils.h"
#include "frontend/parallel/context.h"
#include "debug/env_config_parser.h"
#if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
#include "ps/ps_cache/ps_cache_manager.h"
#endif
@@ -717,11 +718,11 @@ void KernelRuntime::AssignDynamicMemory(session::KernelGraph *graph) {
MS_EXCEPTION_IF_NULL(mem_manager_);
auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr);
bool is_enable_mem_reuse = context_ptr->get_param<bool>(MS_CTX_ENABLE_MEM_REUSE);
bool is_enable_mem_reuse = EnvConfigParser::GetInstance().GetSysMemreuse();
auto mem_type = kDynamicMem;
auto &dump_json_parser = DumpJsonParser::GetInstance();
if (dump_json_parser.e2e_dump_enabled() && dump_json_parser.dump_mode() == 0) {
context_ptr->set_param<bool>(MS_CTX_ENABLE_MEM_REUSE, false);
EnvConfigParser::GetInstance().SetSysMemreuse(false);
is_enable_mem_reuse = false;
MS_LOG(INFO) << "Disable Memory Reuse when e2e dump is enable and dump mode is set to dump all kernels";
}


Loading…
Cancel
Save