From fd56f08e57e1894c3ee86b33a7c4ebd9a387a8df Mon Sep 17 00:00:00 2001 From: kangguangli Date: Mon, 5 Sep 2022 21:00:42 +0800 Subject: [PATCH] [Bug Fix] fix compile error in gcc540 (#45702) * fix compile error in gcc540 --- .../phi/kernels/funcs/data_layout_transform.h | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/paddle/phi/kernels/funcs/data_layout_transform.h b/paddle/phi/kernels/funcs/data_layout_transform.h index 62cfb45b8c0..a2a50937752 100644 --- a/paddle/phi/kernels/funcs/data_layout_transform.h +++ b/paddle/phi/kernels/funcs/data_layout_transform.h @@ -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 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; +#else + struct DataTypeHash { + std::size_t operator()(const DataType& f) const { + return std::hash{}(static_cast(f)); + } + }; + struct DataTypeEqual { + bool operator()(const DataType& lhs, const DataType& rhs) const { + return static_cast(lhs) == static_cast(rhs); + } + }; + using DataTypeMapping = + std::unordered_map; +#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; -- GitLab