|
|
|
@@ -1282,11 +1282,11 @@ void PynativeExecutor::GradNetInner(const GradOperationPtr &grad, const py::obje |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void MapClear(T map, const std::string &flag) { |
|
|
|
for (auto it = map.begin(); it != map.end();) { |
|
|
|
void MapClear(T *map, const std::string &flag) { |
|
|
|
for (auto it = map->begin(); it != map->end();) { |
|
|
|
if (it->first.find(flag) != std::string::npos) { |
|
|
|
it->second = nullptr; |
|
|
|
it = map.erase(it); |
|
|
|
it = map->erase(it); |
|
|
|
} else { |
|
|
|
it++; |
|
|
|
} |
|
|
|
@@ -1296,9 +1296,9 @@ void MapClear(T map, const std::string &flag) { |
|
|
|
void PynativeExecutor::Clear(const std::string &flag) { |
|
|
|
if (!flag.empty()) { |
|
|
|
MS_LOG(DEBUG) << "Clear res"; |
|
|
|
MapClear<std::unordered_map<std::string, FuncGraphPtr>>(graph_map_, flag); |
|
|
|
MapClear<std::unordered_map<std::string, FuncGraphPtr>>(cell_graph_map_, flag); |
|
|
|
MapClear<std::unordered_map<std::string, ResourcePtr>>(cell_resource_map_, flag); |
|
|
|
MapClear<std::unordered_map<std::string, FuncGraphPtr>>(&graph_map_, flag); |
|
|
|
MapClear<std::unordered_map<std::string, FuncGraphPtr>>(&cell_graph_map_, flag); |
|
|
|
MapClear<std::unordered_map<std::string, ResourcePtr>>(&cell_resource_map_, flag); |
|
|
|
Clean(); |
|
|
|
// Maybe exit in the pynative runing op, so need reset pynative flag. |
|
|
|
auto ms_context = MsContext::GetInstance(); |
|
|
|
@@ -1331,17 +1331,17 @@ void PynativeExecutor::Clean() { |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void MapErase(T map) { |
|
|
|
for (auto it = map.begin(); it != map.end();) { |
|
|
|
it = map.erase(it++); |
|
|
|
void MapErase(T *map) { |
|
|
|
for (auto it = map->begin(); it != map->end();) { |
|
|
|
it = map->erase(it++); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void PynativeExecutor::ClearRes() { |
|
|
|
MapErase<std::unordered_map<std::string, FuncGraphPtr>>(graph_map_); |
|
|
|
MapErase<std::unordered_map<std::string, FuncGraphPtr>>(cell_graph_map_); |
|
|
|
MapErase<std::unordered_map<std::string, ResourcePtr>>(cell_resource_map_); |
|
|
|
MapErase<std::unordered_map<std::string, abstract::AbstractBasePtr>>(node_abs_map_); |
|
|
|
MapErase<std::unordered_map<std::string, FuncGraphPtr>>(&graph_map_); |
|
|
|
MapErase<std::unordered_map<std::string, FuncGraphPtr>>(&cell_graph_map_); |
|
|
|
MapErase<std::unordered_map<std::string, ResourcePtr>>(&cell_resource_map_); |
|
|
|
MapErase<std::unordered_map<std::string, abstract::AbstractBasePtr>>(&node_abs_map_); |
|
|
|
Clean(); |
|
|
|
resource_.reset(); |
|
|
|
} |
|
|
|
|