|
|
@ -49,7 +49,7 @@ std::string GetMsIrPath(void) {
|
|
|
|
path = path_ptr;
|
|
|
|
path = path_ptr;
|
|
|
|
char real_path[PATH_MAX] = {0};
|
|
|
|
char real_path[PATH_MAX] = {0};
|
|
|
|
if (path.size() > PATH_MAX || nullptr == realpath(path.c_str(), real_path)) {
|
|
|
|
if (path.size() > PATH_MAX || nullptr == realpath(path.c_str(), real_path)) {
|
|
|
|
MS_LOG(EXCEPTION) << "MS IR Path error, " << path_ptr;
|
|
|
|
MS_LOG(EXCEPTION) << "MS IR path error, " << path_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
path = real_path;
|
|
|
|
path = real_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -144,8 +144,8 @@ std::string AnfExporter::GetValueNodeText(const FuncGraphPtr& fg, const ValueNod
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string AnfExporter::GetMultitypeFuncGraphText(const prim::MultitypeFuncGraphPtr& mt_func_graph) {
|
|
|
|
std::string AnfExporter::GetMultitypeFuncGraphText(const prim::MultitypeFuncGraphPtr& mt_func_graph) {
|
|
|
|
auto py_funs = mt_func_graph->GetPyFunctions();
|
|
|
|
auto py_funcs = mt_func_graph->GetPyFunctions();
|
|
|
|
if (py_funs.empty()) {
|
|
|
|
if (py_funcs.empty()) {
|
|
|
|
return "";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -153,7 +153,7 @@ std::string AnfExporter::GetMultitypeFuncGraphText(const prim::MultitypeFuncGrap
|
|
|
|
|
|
|
|
|
|
|
|
oss << "{";
|
|
|
|
oss << "{";
|
|
|
|
bool is_first = true;
|
|
|
|
bool is_first = true;
|
|
|
|
for (const auto& py_func : py_funs) {
|
|
|
|
for (const auto& py_func : py_funcs) {
|
|
|
|
if (is_first) {
|
|
|
|
if (is_first) {
|
|
|
|
is_first = false;
|
|
|
|
is_first = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -626,7 +626,7 @@ void AnfExporter::ExportFuncGraph(const std::string& filename, const FuncGraphPt
|
|
|
|
ofs << "\n\n";
|
|
|
|
ofs << "\n\n";
|
|
|
|
(void)func_graph_set.erase(fg);
|
|
|
|
(void)func_graph_set.erase(fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ofs << "# num of total funcgraphs: " << exported.size();
|
|
|
|
ofs << "# num of total function graphs: " << exported.size();
|
|
|
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
ofs.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -651,7 +651,7 @@ void AnfExporter::ExportFuncGraph(const std::string& filename, const std::vector
|
|
|
|
ofs << "\n\n";
|
|
|
|
ofs << "\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ofs << "# num of total funcgraphs: " << graphs.size();
|
|
|
|
ofs << "# num of total function graphs: " << graphs.size();
|
|
|
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
ofs.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -763,7 +763,7 @@ class Lexer {
|
|
|
|
fin.close();
|
|
|
|
fin.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
MS_LOG(ERROR) << "exception when closing file";
|
|
|
|
MS_LOG(ERROR) << "Exception when closing file";
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
|
std::string exName(abi::__cxa_current_exception_type()->name());
|
|
|
|
std::string exName(abi::__cxa_current_exception_type()->name());
|
|
|
|
MS_LOG(ERROR) << "Error occurred when closing file. Exception name: " << exName;
|
|
|
|
MS_LOG(ERROR) << "Error occurred when closing file. Exception name: " << exName;
|
|
|
@ -802,7 +802,7 @@ class Lexer {
|
|
|
|
Token token = GetNextTokenInner();
|
|
|
|
Token token = GetNextTokenInner();
|
|
|
|
const char* str = token_text[token];
|
|
|
|
const char* str = token_text[token];
|
|
|
|
std::string text = (str == nullptr ? GetTokenText() : str);
|
|
|
|
std::string text = (str == nullptr ? GetTokenText() : str);
|
|
|
|
MS_LOG(DEBUG) << "------parse token] " << text;
|
|
|
|
MS_LOG(DEBUG) << "------Parse token] " << text;
|
|
|
|
return token;
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1642,7 +1642,7 @@ class IrParser {
|
|
|
|
MS_LOG(EXCEPTION) << "Expect @file at line " << lexer_.GetLineNo();
|
|
|
|
MS_LOG(EXCEPTION) << "Expect @file at line " << lexer_.GetLineNo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// load prameter default value from serialized file
|
|
|
|
// load parameter default value from serialized file
|
|
|
|
py::object default_obj = LoadObject(lexer_.GetTokenText());
|
|
|
|
py::object default_obj = LoadObject(lexer_.GetTokenText());
|
|
|
|
param->set_default_param(default_obj);
|
|
|
|
param->set_default_param(default_obj);
|
|
|
|
|
|
|
|
|
|
|
@ -1950,7 +1950,7 @@ class IrParser {
|
|
|
|
return TOK_ERROR;
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// restore python funciton of PrimitivePy from serialized file
|
|
|
|
// restore python function of PrimitivePy from serialized file
|
|
|
|
py::object py_obj = LoadObject(lexer_.GetTokenText());
|
|
|
|
py::object py_obj = LoadObject(lexer_.GetTokenText());
|
|
|
|
PrimitivePyPtr ptr = nullptr;
|
|
|
|
PrimitivePyPtr ptr = nullptr;
|
|
|
|
if (py::hasattr(py_obj, "__setattr_flag__") && py::hasattr(py_obj, "_clone")) {
|
|
|
|
if (py::hasattr(py_obj, "__setattr_flag__") && py::hasattr(py_obj, "_clone")) {
|
|
|
@ -1958,7 +1958,7 @@ class IrParser {
|
|
|
|
py::object new_obj = clone_fn();
|
|
|
|
py::object new_obj = clone_fn();
|
|
|
|
ptr = new_obj.cast<PrimitivePyPtr>();
|
|
|
|
ptr = new_obj.cast<PrimitivePyPtr>();
|
|
|
|
if (ptr == nullptr) {
|
|
|
|
if (ptr == nullptr) {
|
|
|
|
MS_LOG(EXCEPTION) << "cast to type 'PrimitivePyPtr' error";
|
|
|
|
MS_LOG(EXCEPTION) << "Cast to type 'PrimitivePyPtr' error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ptr = std::make_shared<PrimitivePy>(id.substr(strlen("PrimitivePy::")), py_obj);
|
|
|
|
ptr = std::make_shared<PrimitivePy>(id.substr(strlen("PrimitivePy::")), py_obj);
|
|
|
@ -2221,15 +2221,15 @@ class IrParser {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<FuncGraphPtr> ImportIR(const std::string& filename) {
|
|
|
|
std::vector<FuncGraphPtr> ImportIR(const std::string& filename) {
|
|
|
|
IrParser paser(filename.c_str());
|
|
|
|
IrParser parser(filename.c_str());
|
|
|
|
paser.ParseFile();
|
|
|
|
parser.ParseFile();
|
|
|
|
return paser.GetFuncGraphs();
|
|
|
|
return parser.GetFuncGraphs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_DUMP_IR
|
|
|
|
#ifdef ENABLE_DUMP_IR
|
|
|
|
void DumpIRProto(const FuncGraphPtr& func_graph, const std::string& suffix) {
|
|
|
|
void DumpIRProto(const FuncGraphPtr& func_graph, const std::string& suffix) {
|
|
|
|
if (func_graph == nullptr) {
|
|
|
|
if (func_graph == nullptr) {
|
|
|
|
MS_LOG(ERROR) << "func graph is nullptr";
|
|
|
|
MS_LOG(ERROR) << "Func graph is nullptr";
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto ms_context = MsContext::GetInstance();
|
|
|
|
auto ms_context = MsContext::GetInstance();
|
|
|
@ -2243,16 +2243,16 @@ void DumpIRProto(const FuncGraphPtr& func_graph, const std::string& suffix) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string file_path = save_graphs_path + "/" + "ms_output_" + suffix + ".pb";
|
|
|
|
std::string file_path = save_graphs_path + "/" + "ms_output_" + suffix + ".pb";
|
|
|
|
if (file_path.size() > PATH_MAX) {
|
|
|
|
if (file_path.size() > PATH_MAX) {
|
|
|
|
MS_LOG(ERROR) << "file path " << file_path << " is too long.";
|
|
|
|
MS_LOG(ERROR) << "File path " << file_path << " is too long.";
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char real_path[PATH_MAX] = {0};
|
|
|
|
char real_path[PATH_MAX] = {0};
|
|
|
|
if (nullptr == realpath(file_path.c_str(), real_path)) {
|
|
|
|
if (nullptr == realpath(file_path.c_str(), real_path)) {
|
|
|
|
MS_LOG(DEBUG) << "dir " << file_path << " does not exit.";
|
|
|
|
MS_LOG(DEBUG) << "Dir " << file_path << " does not exit.";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
std::string path_string = real_path;
|
|
|
|
std::string path_string = real_path;
|
|
|
|
if (chmod(common::SafeCStr(path_string), S_IRUSR | S_IWUSR) == -1) {
|
|
|
|
if (chmod(common::SafeCStr(path_string), S_IRUSR | S_IWUSR) == -1) {
|
|
|
|
MS_LOG(ERROR) << "modify file:" << real_path << " to rw fail.";
|
|
|
|
MS_LOG(ERROR) << "Modify file:" << real_path << " to rw fail.";
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|