forked from huawei/mindspore2022
Memory reuse switch
This commit is contained in:
parent
d2514950ec
commit
8d830f1e5c
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 KEY_MEM_REUSE_SETTINGS = "sys";
|
||||
constexpr auto KEY_MEM_REUSE = "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(KEY_MEM_REUSE_SETTINGS);
|
||||
if (sys_setting == content.end()) {
|
||||
MS_LOG(INFO) << "The '" << KEY_MEM_REUSE_SETTINGS << "' isn't existed. Please check the config file '"
|
||||
<< config_file_ << "' set by 'env_config_path' in context.";
|
||||
return;
|
||||
}
|
||||
auto sys_memreuse = CheckJsonKeyExist(*sys_setting, KEY_MEM_REUSE_SETTINGS, KEY_MEM_REUSE);
|
||||
if (sys_memreuse.has_value()) {
|
||||
ParseSysMemReuse(**sys_memreuse);
|
||||
}
|
||||
}
|
||||
|
||||
void EnvConfigParser::ParseSysMemReuse(const nlohmann::json &content) {
|
||||
if (!content.is_boolean()) {
|
||||
MS_LOG(INFO) << "the json object parses failed. 'enable' in " << KEY_MEM_REUSE_SETTINGS << " 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()) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,6 +44,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/ascend/executor/hccl_dynamic_kernel.h"
|
||||
|
|
@ -450,9 +451,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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,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
|
||||
|
|
@ -756,11 +756,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);
|
||||
mindspore::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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ MsContext::MsContext(const std::string &policy, const std::string &target) {
|
|||
set_param<bool>(MS_CTX_ENABLE_TASK_SINK, true);
|
||||
set_param<bool>(MS_CTX_IR_FUSION_FLAG, true);
|
||||
set_param<bool>(MS_CTX_ENABLE_HCCL, false);
|
||||
set_param<bool>(MS_CTX_ENABLE_MEM_REUSE, true);
|
||||
set_param<bool>(MS_CTX_ENABLE_GPU_SUMMARY, true);
|
||||
set_param<bool>(MS_CTX_PRECOMPILE_ONLY, false);
|
||||
set_param<bool>(MS_CTX_ENABLE_AUTO_MIXED_PRECISION, false);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ enum MsCtxParam : unsigned {
|
|||
MS_CTX_ENABLE_GRAPH_KERNEL,
|
||||
MS_CTX_ENABLE_HCCL,
|
||||
MS_CTX_ENABLE_LOOP_SINK,
|
||||
MS_CTX_ENABLE_MEM_REUSE,
|
||||
MS_CTX_ENABLE_PYNATIVE_HOOK,
|
||||
MS_CTX_ENABLE_PYNATIVE_INFER,
|
||||
MS_CTX_ENABLE_REDUCE_PRECISION,
|
||||
|
|
|
|||
Loading…
Reference in New Issue