提交 9f8d8685 编写于 作者: Y Yu Yang

Revert data_type

test=develop
上级 b22d638d
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "paddle/fluid/framework/data_type.h" #include "paddle/fluid/framework/data_type.h"
#include <stdint.h> #include <stdint.h>
#include <map>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
...@@ -24,10 +23,10 @@ namespace paddle { ...@@ -24,10 +23,10 @@ namespace paddle {
namespace framework { namespace framework {
struct DataTypeMap { struct DataTypeMap {
std::map<const char*, proto::VarType::Type> cpp_to_proto_; std::unordered_map<std::type_index, proto::VarType::Type> cpp_to_proto_;
std::unordered_map<int, std::type_index> proto_to_cpp_; std::unordered_map<int, std::type_index> proto_to_cpp_;
std::unordered_map<int, std::string> proto_to_str_; std::unordered_map<int, std::string> proto_to_str_;
std::map<const char* /*name pointer*/, size_t> cpp_to_size_; std::unordered_map<std::type_index, size_t> cpp_to_size_;
}; };
static DataTypeMap* InitDataTypeMap(); static DataTypeMap* InitDataTypeMap();
...@@ -44,9 +43,9 @@ static inline void RegisterType(DataTypeMap* map, ...@@ -44,9 +43,9 @@ static inline void RegisterType(DataTypeMap* map,
proto::VarType::Type proto_type, proto::VarType::Type proto_type,
const std::string& name) { const std::string& name) {
map->proto_to_cpp_.emplace(static_cast<int>(proto_type), typeid(T)); map->proto_to_cpp_.emplace(static_cast<int>(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<int>(proto_type), name); map->proto_to_str_.emplace(static_cast<int>(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() { static DataTypeMap* InitDataTypeMap() {
...@@ -72,7 +71,7 @@ static DataTypeMap* InitDataTypeMap() { ...@@ -72,7 +71,7 @@ static DataTypeMap* InitDataTypeMap() {
} }
proto::VarType::Type ToDataType(std::type_index type) { 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()) { if (it != gDataTypeMap().cpp_to_proto_.end()) {
return it->second; return it->second;
} }
...@@ -98,8 +97,8 @@ std::string DataTypeToString(const proto::VarType::Type type) { ...@@ -98,8 +97,8 @@ std::string DataTypeToString(const proto::VarType::Type type) {
} }
size_t SizeOfType(std::type_index type) { size_t SizeOfType(std::type_index type) {
auto it = gDataTypeMap().cpp_to_size_.find(type.name()); auto it = gDataTypeMap().cpp_to_size_.find(type);
if (LIKELY(it != gDataTypeMap().cpp_to_size_.end())) { if (it != gDataTypeMap().cpp_to_size_.end()) {
return it->second; return it->second;
} }
PADDLE_THROW("Not support %s as tensor type", type.name()); PADDLE_THROW("Not support %s as tensor type", type.name());
......
...@@ -39,8 +39,11 @@ DEFINE_string(pe_profile_fname, "", ...@@ -39,8 +39,11 @@ DEFINE_string(pe_profile_fname, "",
namespace paddle { namespace paddle {
namespace framework { namespace framework {
static std::once_flag gProfileOnce; static std::once_flag gProfileOnce;
#ifdef WITH_GPERFTOOLS
static bool gProfileStarted = false; static bool gProfileStarted = false;
#endif
class ParallelExecutorPrivate { class ParallelExecutorPrivate {
public: public:
explicit ParallelExecutorPrivate(const std::vector<platform::Place> &places) explicit ParallelExecutorPrivate(const std::vector<platform::Place> &places)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册