!11892 remove unnecessary profiling_output_path parameter for set_context
From: @yanghaitao1 Reviewed-by: @yelihua Signed-off-by:
This commit is contained in:
commit
d638a92946
|
@ -19,10 +19,14 @@
|
|||
#include <memory>
|
||||
#include "utils/log_adapter.h"
|
||||
#include "utils/ms_context.h"
|
||||
#include "utils/ms_utils.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace mindspore {
|
||||
namespace profiler {
|
||||
|
||||
constexpr char kOutputPath[] = "result_path";
|
||||
|
||||
std::shared_ptr<GraphMemory> MemoryProfiling::AddGraphMemoryNode(uint32_t graph_id) {
|
||||
std::shared_ptr<GraphMemory> node = std::make_shared<GraphMemory>(graph_id);
|
||||
graph_memory_[graph_id] = node;
|
||||
|
@ -76,10 +80,45 @@ void MemoryProfiling::MemoryToPB() {
|
|||
return;
|
||||
}
|
||||
|
||||
std::string MemoryProfiling::GetOutputPath() const {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
const std::string options_str = context->get_param<std::string>(MS_CTX_PROFILING_OPTIONS);
|
||||
nlohmann::json options_json;
|
||||
try {
|
||||
options_json = nlohmann::json::parse(options_str);
|
||||
} catch (nlohmann::json::parse_error &e) {
|
||||
MS_LOG(EXCEPTION) << "Parse profiling option json failed, error:" << e.what();
|
||||
}
|
||||
auto iter = options_json.find(kOutputPath);
|
||||
if (iter != options_json.end() && iter->is_string()) {
|
||||
char real_path[PATH_MAX] = {0};
|
||||
if ((*iter).size() >= PATH_MAX) {
|
||||
MS_LOG(ERROR) << "Path is invalid for memory profiling.";
|
||||
return "";
|
||||
}
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (_fullpath(real_path, common::SafeCStr(*iter), PATH_MAX) == nullptr) {
|
||||
MS_LOG(ERROR) << "Path is invalid for memory profiling.";
|
||||
return "";
|
||||
}
|
||||
#else
|
||||
if (realpath(common::SafeCStr(*iter), real_path) == nullptr) {
|
||||
MS_LOG(ERROR) << "Path is invalid for memory profiling.";
|
||||
return "";
|
||||
}
|
||||
#endif
|
||||
return real_path;
|
||||
}
|
||||
|
||||
MS_LOG(ERROR) << "Output path is not found when save memory profiling data";
|
||||
return "";
|
||||
}
|
||||
|
||||
void MemoryProfiling::SaveMemoryProfiling() {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
std::string dir_path = context->get_param<std::string>(MS_CTX_PROFILING_DIR_PATH);
|
||||
std::string dir_path = GetOutputPath();
|
||||
auto device_id = context->get_param<uint32_t>(MS_CTX_DEVICE_ID);
|
||||
std::string file = dir_path + std::string("/memory_usage_") + std::to_string(device_id) + std::string(".pb");
|
||||
|
||||
|
|
|
@ -115,6 +115,8 @@ class MemoryProfiling {
|
|||
void SaveMemoryProfiling();
|
||||
|
||||
private:
|
||||
std::string GetOutputPath() const;
|
||||
|
||||
MemoryProto memory_proto_;
|
||||
std::map<uint32_t, std::shared_ptr<GraphMemory>> graph_memory_;
|
||||
uint64_t device_mem_size_;
|
||||
|
|
|
@ -95,7 +95,6 @@ REGISTER_PYBIND_DEFINE(MsContextPy, ([](const py::module *m) {
|
|||
.value("variable_memory_max_size", MsCtxParam::MS_CTX_VARIABLE_MEMORY_MAX_SIZE)
|
||||
.value("device_id", MsCtxParam::MS_CTX_DEVICE_ID)
|
||||
.value("max_call_depth", MsCtxParam::MS_CTX_MAX_CALL_DEPTH)
|
||||
.value("profiling_dir_path", MsCtxParam::MS_CTX_PROFILING_DIR_PATH)
|
||||
.value("env_config_path", MsCtxParam::MS_CTX_ENV_CONFIG_PATH);
|
||||
(void)py::class_<mindspore::MsContext, std::shared_ptr<mindspore::MsContext>>(*m, "MSContext")
|
||||
.def_static("get_instance", &mindspore::MsContext::GetInstance, "Get ms context instance.")
|
||||
|
|
|
@ -74,7 +74,6 @@ MsContext::MsContext(const std::string &policy, const std::string &target) {
|
|||
set_param<bool>(MS_CTX_ENABLE_GRAPH_KERNEL, false);
|
||||
set_param<bool>(MS_CTX_ENABLE_SPARSE, false);
|
||||
set_param<bool>(MS_CTX_ENABLE_PARALLEL_SPLIT, false);
|
||||
set_param<std::string>(MS_CTX_PROFILING_DIR_PATH, "");
|
||||
|
||||
backend_policy_ = policy_map_[policy];
|
||||
}
|
||||
|
|
|
@ -106,7 +106,6 @@ enum MsCtxParam : unsigned {
|
|||
MS_CTX_SAVE_GRAPHS_PATH,
|
||||
MS_CTX_VARIABLE_MEMORY_MAX_SIZE,
|
||||
MS_CTX_PYTHON_EXE_PATH,
|
||||
MS_CTX_PROFILING_DIR_PATH,
|
||||
MS_CTX_ENV_CONFIG_PATH,
|
||||
MS_CTX_TYPE_STRING_END,
|
||||
|
||||
|
|
|
@ -132,8 +132,7 @@ class Profiler:
|
|||
logger.error(msg)
|
||||
raise ValueError(msg)
|
||||
# use context interface to open profiling, for the new mindspore version(after 2020.5.21)
|
||||
context.set_context(enable_profiling=True, profiling_options=profiling_options,
|
||||
profiling_dir_path=self._output_path)
|
||||
context.set_context(enable_profiling=True, profiling_options=profiling_options)
|
||||
base_profiling_container_path = os.path.join(self._output_path, "container")
|
||||
container_path = os.path.join(base_profiling_container_path, self._dev_id)
|
||||
data_path = os.path.join(container_path, "data")
|
||||
|
|
Loading…
Reference in New Issue