1 #include "caffe2/core/types.h" 2 #include <c10/util/typeid.h> 11 TensorProto::DataType TypeMetaToDataType(
const TypeMeta& meta) {
12 static_assert(
sizeof(
int) == 4,
13 "int in this compiler does not equal to 4 bytes.");
14 static std::map<TypeIdentifier, TensorProto::DataType> data_type_map {
15 {TypeMeta::Id<float>(), TensorProto_DataType_FLOAT},
16 {TypeMeta::Id<int>(), TensorProto_DataType_INT32},
21 {TypeMeta::Id<string>(), TensorProto_DataType_STRING},
22 {TypeMeta::Id<bool>(), TensorProto_DataType_BOOL},
23 {TypeMeta::Id<uint8_t>(), TensorProto_DataType_UINT8},
24 {TypeMeta::Id<int8_t>(), TensorProto_DataType_INT8},
25 {TypeMeta::Id<uint16_t>(), TensorProto_DataType_UINT16},
26 {TypeMeta::Id<int16_t>(), TensorProto_DataType_INT16},
27 {TypeMeta::Id<int64_t>(), TensorProto_DataType_INT64},
28 {TypeMeta::Id<at::Half>(), TensorProto_DataType_FLOAT16},
29 {TypeMeta::Id<double>(), TensorProto_DataType_DOUBLE},
31 const auto it = data_type_map.find(meta.id());
32 return (it == data_type_map.end()
33 ? TensorProto_DataType_UNDEFINED : it->second);
36 const TypeMeta& DataTypeToTypeMeta(
const TensorProto::DataType& dt) {
37 static std::map<TensorProto::DataType, TypeMeta> type_meta_map{
38 {TensorProto_DataType_FLOAT, TypeMeta::Make<float>()},
39 {TensorProto_DataType_INT32, TypeMeta::Make<int>()},
40 {TensorProto_DataType_BYTE, TypeMeta::Make<uint8_t>()},
41 {TensorProto_DataType_STRING, TypeMeta::Make<std::string>()},
42 {TensorProto_DataType_BOOL, TypeMeta::Make<bool>()},
43 {TensorProto_DataType_UINT8, TypeMeta::Make<uint8_t>()},
44 {TensorProto_DataType_INT8, TypeMeta::Make<int8_t>()},
45 {TensorProto_DataType_UINT16, TypeMeta::Make<uint16_t>()},
46 {TensorProto_DataType_INT16, TypeMeta::Make<int16_t>()},
47 {TensorProto_DataType_INT64, TypeMeta::Make<int64_t>()},
48 {TensorProto_DataType_FLOAT16, TypeMeta::Make<at::Half>()},
49 {TensorProto_DataType_DOUBLE, TypeMeta::Make<double>()},
51 const auto it = type_meta_map.find(dt);
52 if (it == type_meta_map.end()) {
53 throw std::runtime_error(
"Unknown data type.");
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...