@@ -98,62 +98,17 @@ enum class DataType : int8_t {
9898 kFLOAT64 ,
9999};
100100
101- size_t DTypeSize (DataType data_type);
102-
103- extern const std::unordered_map<DataType, std::string> kDataTypeToDesc ;
104-
105- // -----------------------------------------------------------------------------
106- // Compile-time type mapping infrastructure
107- // -----------------------------------------------------------------------------
108- // Baseline framework scalar/storage mapping.
109- // This is the single source of truth for:
110- // - framework DataType -> C++ type mapping
111- // - CPU default type mapping
112- // - backend type-map fallback for dtypes without backend-native overrides
113- template <DataType DType> struct TypeMap ;
114-
115- template <DataType DType> using TypeMap_t = typename TypeMap<DType>::type;
116-
117- // -----------------------------------------------------------------------------
118- // Compile-time reverse mapping: framework C++ type -> DataType
119- // -----------------------------------------------------------------------------
120- template <typename T> struct DataTypeMap ;
121-
122- template <typename T> inline constexpr DataType DataTypeMap_v = DataTypeMap<T>::value;
123-
124- // Macro to define baseline mapping + reverse mapping
125- #define DEFINE_DEFAULT_DATA_TYPE_MAPPING (ENUM_VALUE, CPP_TYPE ) \
126- template <> struct TypeMap <DataType::ENUM_VALUE> { \
127- using type = CPP_TYPE; \
128- }; \
129- template <> struct DataTypeMap <CPP_TYPE> { \
130- static constexpr DataType value = DataType::ENUM_VALUE; \
131- };
132-
133- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kUINT8 , uint8_t )
134- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kINT8 , int8_t )
135- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kUINT16 , uint16_t )
136- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kINT16 , int16_t )
137- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kUINT32 , uint32_t )
138- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kINT32 , int32_t )
139- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kUINT64 , uint64_t )
140- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kINT64 , int64_t )
141- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kFLOAT32 , float )
142- DEFINE_DEFAULT_DATA_TYPE_MAPPING (kFLOAT64 , double )
143-
144- #undef DEFINE_DEFAULT_DATA_TYPE_MAPPING
145-
146- // ---------------------------------------------------------------------------
147- // Low-precision types: reverse mapping ONLY (DataTypeMap).
148- // TypeMap<kFLOAT16> / TypeMap<kBFLOAT16> are intentionally NOT defined here.
149- // Backend TypeMaps must explicitly provide these mappings; the default TypeMap
150- // will static_assert at compile time if dispatch reaches an unmapped dtype.
151- // ---------------------------------------------------------------------------
152- template <> struct DataTypeMap <FP16> {
153- static constexpr DataType value = DataType::kFLOAT16 ;
101+ inline const std::unordered_map<DataType, size_t > kDataTypeToSize = {
102+ {DataType::kUINT8 , 1 }, {DataType::kINT8 , 1 }, {DataType::kUINT16 , 2 }, {DataType::kINT16 , 2 },
103+ {DataType::kUINT32 , 4 }, {DataType::kINT32 , 4 }, {DataType::kUINT64 , 8 }, {DataType::kINT64 , 8 },
104+ {DataType::kBFLOAT16 , 2 }, {DataType::kFLOAT16 , 2 }, {DataType::kFLOAT32 , 4 }, {DataType::kFLOAT64 , 8 },
154105};
155- template <> struct DataTypeMap <BF16> {
156- static constexpr DataType value = DataType::kBFLOAT16 ;
106+
107+ inline const std::unordered_map<DataType, std::string> kDataTypeToDesc = {
108+ {DataType::kUINT8 , " uint8" }, {DataType::kINT8 , " int8" }, {DataType::kUINT16 , " uint16" },
109+ {DataType::kINT16 , " int16" }, {DataType::kUINT32 , " uint32" }, {DataType::kINT32 , " int32" },
110+ {DataType::kUINT64 , " uint64" }, {DataType::kINT64 , " int64" }, {DataType::kBFLOAT16 , " bf16" },
111+ {DataType::kFLOAT16 , " fp16" }, {DataType::kFLOAT32 , " fp32" }, {DataType::kFLOAT64 , " fp64" },
157112};
158113
159114// =============================================================================
0 commit comments