diff --git a/paddle/fluid/framework/data_type.cc b/paddle/fluid/framework/data_type.cc index 1c29a89bffa8b2813e3e3be12edf750910a9033a..28f3da88fa18021f6b71e458fdb467be86d4dbf0 100644 --- a/paddle/fluid/framework/data_type.cc +++ b/paddle/fluid/framework/data_type.cc @@ -14,7 +14,6 @@ #include "paddle/fluid/framework/data_type.h" #include -#include #include #include @@ -24,10 +23,10 @@ namespace paddle { namespace framework { struct DataTypeMap { - std::map cpp_to_proto_; + std::unordered_map cpp_to_proto_; std::unordered_map proto_to_cpp_; std::unordered_map proto_to_str_; - std::map cpp_to_size_; + std::unordered_map cpp_to_size_; }; static DataTypeMap* InitDataTypeMap(); @@ -44,9 +43,9 @@ static inline void RegisterType(DataTypeMap* map, proto::VarType::Type proto_type, const std::string& name) { map->proto_to_cpp_.emplace(static_cast(proto_type), typeid(T)); - map->cpp_to_proto_.emplace(typeid(T).name(), proto_type); + map->cpp_to_proto_.emplace(typeid(T), proto_type); map->proto_to_str_.emplace(static_cast(proto_type), name); - map->cpp_to_size_.emplace(typeid(T).name(), sizeof(T)); + map->cpp_to_size_.emplace(typeid(T), sizeof(T)); } static DataTypeMap* InitDataTypeMap() { @@ -72,7 +71,7 @@ static DataTypeMap* InitDataTypeMap() { } proto::VarType::Type ToDataType(std::type_index type) { - auto it = gDataTypeMap().cpp_to_proto_.find(type.name()); + auto it = gDataTypeMap().cpp_to_proto_.find(type); if (it != gDataTypeMap().cpp_to_proto_.end()) { return it->second; } @@ -98,8 +97,8 @@ std::string DataTypeToString(const proto::VarType::Type type) { } size_t SizeOfType(std::type_index type) { - auto it = gDataTypeMap().cpp_to_size_.find(type.name()); - if (LIKELY(it != gDataTypeMap().cpp_to_size_.end())) { + auto it = gDataTypeMap().cpp_to_size_.find(type); + if (it != gDataTypeMap().cpp_to_size_.end()) { return it->second; } PADDLE_THROW("Not support %s as tensor type", type.name()); diff --git a/paddle/fluid/framework/parallel_executor.cc b/paddle/fluid/framework/parallel_executor.cc index 0636b89048f2eac6d6bef149b249c392a1658094..28a4b14b27bda65c0ff8e3e73df1fab62439af2f 100644 --- a/paddle/fluid/framework/parallel_executor.cc +++ b/paddle/fluid/framework/parallel_executor.cc @@ -39,8 +39,11 @@ DEFINE_string(pe_profile_fname, "", namespace paddle { namespace framework { + static std::once_flag gProfileOnce; +#ifdef WITH_GPERFTOOLS static bool gProfileStarted = false; +#endif class ParallelExecutorPrivate { public: explicit ParallelExecutorPrivate(const std::vector &places)