Skip to content

Commit

Permalink
[Bug Fix] fix compile error in gcc540 (#45702)
Browse files Browse the repository at this point in the history
* fix compile error in gcc540
  • Loading branch information
kangguangli authored Sep 5, 2022
1 parent 4b41edd commit fd56f08
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions paddle/phi/kernels/funcs/data_layout_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,30 @@ inline OneDNNMemoryFormat ToOneDNNFormat(const DataLayout& layout) {
}
}

// Caution: proto::VarType::Type -> phi::DataType after transfer
inline OneDNNDataType ToOneDNNDataType(DataType type) {
static std::unordered_map<DataType, OneDNNDataType> dict{
{DataType::FLOAT32, OneDNNDataType::f32},
{DataType::INT8, OneDNNDataType::s8},
{DataType::UINT8, OneDNNDataType::u8},
{DataType::INT32, OneDNNDataType::s32},
{DataType::BFLOAT16, OneDNNDataType::bf16}};
#if __GNUC__ > 5
using DataTypeMapping = std::unordered_map<DataType, OneDNNDataType>;
#else
struct DataTypeHash {
std::size_t operator()(const DataType& f) const {
return std::hash<int>{}(static_cast<int>(f));
}
};
struct DataTypeEqual {
bool operator()(const DataType& lhs, const DataType& rhs) const {
return static_cast<int>(lhs) == static_cast<int>(rhs);
}
};
using DataTypeMapping =
std::unordered_map<DataType, OneDNNDataType, DataTypeHash, DataTypeEqual>;
#endif

static DataTypeMapping dict{{DataType::FLOAT32, OneDNNDataType::f32},
{DataType::INT8, OneDNNDataType::s8},
{DataType::UINT8, OneDNNDataType::u8},
{DataType::INT32, OneDNNDataType::s32},
{DataType::BFLOAT16, OneDNNDataType::bf16}};

auto iter = dict.find(type);
if (iter != dict.end()) return iter->second;
return OneDNNDataType::undef;
Expand Down

0 comments on commit fd56f08

Please sign in to comment.