1 #include "caffe2/core/types.h" 2 #include "caffe2/core/typeid.h" 11 CAFFE_KNOWN_TYPE(
float);
12 CAFFE_KNOWN_TYPE(
int);
13 CAFFE_KNOWN_TYPE(std::string);
14 CAFFE_KNOWN_TYPE(
bool);
15 CAFFE_KNOWN_TYPE(uint8_t);
16 CAFFE_KNOWN_TYPE(int8_t);
17 CAFFE_KNOWN_TYPE(uint16_t);
18 CAFFE_KNOWN_TYPE(int16_t);
19 CAFFE_KNOWN_TYPE(int64_t);
20 CAFFE_KNOWN_TYPE(float16);
21 CAFFE_KNOWN_TYPE(
double);
22 CAFFE_KNOWN_TYPE(
char);
23 CAFFE_KNOWN_TYPE(std::unique_ptr<std::mutex>);
24 CAFFE_KNOWN_TYPE(std::unique_ptr<std::atomic<bool>>);
25 CAFFE_KNOWN_TYPE(std::vector<int64_t>);
26 CAFFE_KNOWN_TYPE(std::vector<unsigned long>);
27 CAFFE_KNOWN_TYPE(
bool*);
28 CAFFE_KNOWN_TYPE(
char*);
29 CAFFE_KNOWN_TYPE(
int*);
31 #ifdef CAFFE2_UNIQUE_LONG_TYPEMETA 32 CAFFE_KNOWN_TYPE(
long);
33 CAFFE_KNOWN_TYPE(std::vector<long>);
34 #endif // CAFFE2_UNIQUE_LONG_TYPEMETA 36 TensorProto::DataType TypeMetaToDataType(
const TypeMeta& meta) {
37 static_assert(
sizeof(
int) == 4,
38 "int in this compiler does not equal to 4 bytes.");
39 static std::map<CaffeTypeId, TensorProto::DataType> data_type_map {
40 {TypeMeta::Id<float>(), TensorProto_DataType_FLOAT},
41 {TypeMeta::Id<int>(), TensorProto_DataType_INT32},
46 {TypeMeta::Id<string>(), TensorProto_DataType_STRING},
47 {TypeMeta::Id<bool>(), TensorProto_DataType_BOOL},
48 {TypeMeta::Id<uint8_t>(), TensorProto_DataType_UINT8},
49 {TypeMeta::Id<int8_t>(), TensorProto_DataType_INT8},
50 {TypeMeta::Id<uint16_t>(), TensorProto_DataType_UINT16},
51 {TypeMeta::Id<int16_t>(), TensorProto_DataType_INT16},
52 {TypeMeta::Id<int64_t>(), TensorProto_DataType_INT64},
53 {TypeMeta::Id<float16>(), TensorProto_DataType_FLOAT16},
54 {TypeMeta::Id<double>(), TensorProto_DataType_DOUBLE},
56 const auto it = data_type_map.find(meta.id());
57 return (it == data_type_map.end()
58 ? TensorProto_DataType_UNDEFINED : it->second);
61 const TypeMeta& DataTypeToTypeMeta(
const TensorProto::DataType& dt) {
62 static std::map<TensorProto::DataType, TypeMeta> type_meta_map{
63 {TensorProto_DataType_FLOAT, TypeMeta::Make<float>()},
64 {TensorProto_DataType_INT32, TypeMeta::Make<int>()},
65 {TensorProto_DataType_STRING, TypeMeta::Make<std::string>()},
66 {TensorProto_DataType_BOOL, TypeMeta::Make<bool>()},
67 {TensorProto_DataType_UINT8, TypeMeta::Make<uint8_t>()},
68 {TensorProto_DataType_INT8, TypeMeta::Make<int8_t>()},
69 {TensorProto_DataType_UINT16, TypeMeta::Make<uint16_t>()},
70 {TensorProto_DataType_INT16, TypeMeta::Make<int16_t>()},
71 {TensorProto_DataType_INT64, TypeMeta::Make<int64_t>()},
72 {TensorProto_DataType_FLOAT16, TypeMeta::Make<float16>()},
73 {TensorProto_DataType_DOUBLE, TypeMeta::Make<double>()},
75 const auto it = type_meta_map.find(dt);
76 if (it == type_meta_map.end()) {
77 throw std::runtime_error(
"Unknown data type.");
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...