forked from mindspore-Ecosystem/mindspore
!26817 Fix map::overflow when save_graphs enabled
Merge pull request !26817 from hewei/use_robin_hood
This commit is contained in:
commit
526750bceb
|
@ -412,7 +412,7 @@ std::string AnfExporter::GetAnfNodeText(const FuncGraphPtr &func_graph, const An
|
|||
}
|
||||
|
||||
void AnfExporter::OutputParameters(std::ofstream &ofs, const std::vector<AnfNodePtr> ¶meters,
|
||||
OrderedMap<AnfNodePtr, int, ParamPtrHasher, ParamPtrEqual> *param_map) {
|
||||
ParamIndexMap *param_map) {
|
||||
bool first_flag = true;
|
||||
for (const AnfNodePtr ¶m : parameters) {
|
||||
if (first_flag) {
|
||||
|
@ -569,7 +569,7 @@ void AnfExporter::ExportOneFuncGraph(std::ofstream &ofs, const FuncGraphPtr &fun
|
|||
|
||||
std::vector<AnfNodePtr> nodes = TopoSort(func_graph->get_return(), SuccIncoming, AlwaysInclude);
|
||||
std::vector<AnfNodePtr> parameters = func_graph->parameters();
|
||||
OrderedMap<AnfNodePtr, int, ParamPtrHasher, ParamPtrEqual> param_map;
|
||||
ParamIndexMap param_map;
|
||||
|
||||
if (*(func_graph->switch_input())) {
|
||||
ofs << "switch_input: " << *(func_graph->switch_input()) << "\n";
|
||||
|
|
|
@ -62,6 +62,8 @@ struct ParamPtrHasher {
|
|||
}
|
||||
};
|
||||
|
||||
using ParamIndexMap = OrderedMap<AnfNodePtr, int, ParamPtrHasher, ParamPtrEqual, true>;
|
||||
|
||||
class AnfExporter {
|
||||
public:
|
||||
explicit AnfExporter(bool export_used = true, bool check_integrity = false)
|
||||
|
@ -89,8 +91,7 @@ class AnfExporter {
|
|||
std::string GetMetaFuncGraphText(const MetaFuncGraphPtr &meta_func_graph);
|
||||
std::string GetAnfNodeText(const FuncGraphPtr &func_graph, const AnfNodePtr &node,
|
||||
const std::map<AnfNodePtr, int> &apply_map);
|
||||
void OutputParameters(std::ofstream &ofs, const std::vector<AnfNodePtr> ¶meters,
|
||||
OrderedMap<AnfNodePtr, int, ParamPtrHasher, ParamPtrEqual> *param_map);
|
||||
void OutputParameters(std::ofstream &ofs, const std::vector<AnfNodePtr> ¶meters, ParamIndexMap *param_map);
|
||||
|
||||
void OutputStatementComment(std::ofstream &ofs, const CNodePtr &node);
|
||||
void OutputOrderList(std::ofstream &ofs, const FuncGraphPtr &func_graph);
|
||||
|
@ -101,7 +102,7 @@ class AnfExporter {
|
|||
std::map<AnfNodePtr, int> *const apply_map);
|
||||
void ExportOneFuncGraph(std::ofstream &ofs, const FuncGraphPtr &func_graph, const TaggedNodeMap &tagged_cnodes_map);
|
||||
|
||||
OrderedMap<FuncGraphPtr, OrderedMap<AnfNodePtr, int, ParamPtrHasher, ParamPtrEqual>> exported;
|
||||
OrderedMap<FuncGraphPtr, ParamIndexMap> exported;
|
||||
|
||||
private:
|
||||
void OutputCNodes(std::ofstream &ofs, const std::vector<AnfNodePtr> &nodes, const FuncGraphPtr &func_graph,
|
||||
|
|
|
@ -22,13 +22,16 @@
|
|||
#include <functional>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include "utils/hashing.h"
|
||||
#include "utils/hash_map.h"
|
||||
|
||||
namespace mindspore {
|
||||
// Implementation of OrderedMap that keeps insertion order
|
||||
// using hash map to improve the performance of find/erase, and use list to keep insertion order
|
||||
template <typename KeyT, typename ValueT, class Hash = std::hash<KeyT>, class Equal = std::equal_to<KeyT>>
|
||||
template <typename KeyT, typename ValueT, class Hash = std::hash<KeyT>, class Equal = std::equal_to<KeyT>,
|
||||
bool UseStd = false>
|
||||
class OrderedMap {
|
||||
using key_ptr_t = const KeyT *;
|
||||
struct KeyPtrHash {
|
||||
|
@ -47,7 +50,8 @@ class OrderedMap {
|
|||
using const_iterator = typename sequential_type::const_iterator;
|
||||
using reverse_iterator = typename sequential_type::reverse_iterator;
|
||||
using const_reverse_iterator = typename sequential_type::const_reverse_iterator;
|
||||
using map_type = mindspore::HashMap<key_ptr_t, iterator, KeyPtrHash, KeyPtrEqual>;
|
||||
using map_type = typename std::conditional<UseStd, std::unordered_map<key_ptr_t, iterator, KeyPtrHash, KeyPtrEqual>,
|
||||
mindspore::HashMap<key_ptr_t, iterator, KeyPtrHash, KeyPtrEqual>>::type;
|
||||
using value_type = typename sequential_type::value_type;
|
||||
using size_type = typename sequential_type::size_type;
|
||||
|
||||
|
|
Loading…
Reference in New Issue