Caffe2 - C++ API
A deep learning, cross platform ML framework
types.h
1 #ifndef CAFFE2_CORE_TYPES_H_
2 #define CAFFE2_CORE_TYPES_H_
3 
4 #include <cstdint>
5 #include <string>
6 #include <type_traits>
7 
8 #include "caffe2/core/common.h"
9 #include "caffe2/core/logging.h"
10 #include "caffe2/core/typeid.h"
11 #include "caffe2/proto/caffe2.pb.h"
12 
13 namespace caffe2 {
14 
15 // Storage orders that are often used in the image applications.
16 enum StorageOrder {
17  UNKNOWN = 0,
18  NHWC = 1,
19  NCHW = 2,
20 };
21 
22 inline StorageOrder StringToStorageOrder(const string& str) {
23  if (str == "NHWC" || str == "nhwc") {
24  return StorageOrder::NHWC;
25  } else if (str == "NCHW" || str == "nchw") {
26  return StorageOrder::NCHW;
27  } else {
28  LOG(ERROR) << "Unknown storage order string: " << str;
29  return StorageOrder::UNKNOWN;
30  }
31 }
32 
33 inline constexpr char NameScopeSeparator() { return '/'; }
34 
35 // From TypeMeta to caffe2::DataType protobuffer enum.
36 TensorProto::DataType TypeMetaToDataType(const TypeMeta& meta);
37 
38 // From caffe2::DataType protobuffer enum to TypeMeta
39 const TypeMeta& DataTypeToTypeMeta(const TensorProto::DataType& dt);
40 
41 } // namespace caffe2
42 
44 // Half float definition. Currently half float operators are mainly on CUDA
45 // gpus.
46 // The reason we do not directly use the cuda __half data type is because that
47 // requires compilation with nvcc. The float16 data type should be compatible
48 // with the cuda __half data type, but will allow us to refer to the data type
49 // without the need of cuda.
50 static_assert(sizeof(unsigned short) == 2,
51  "Short on this platform is not 16 bit.");
52 namespace caffe2 {
53 typedef struct CAFFE2_ALIGNED(2) __f16 { uint16_t x; } float16;
54 
55 // Helpers to avoid using typeinfo with -rtti
56 template <typename T>
57 inline bool fp16_type();
58 // explicit instantation for float16 defined in types.cc.
59 template <>
60 inline bool fp16_type<float16>() {
61  return true;
62 }
63 // The rest.
64 template <typename T>
65 inline bool fp16_type() {
66  return false;
67 }
68 
69 } // namespace caffe2
70 
71 // Make __f16 a fundamental type.
72 namespace std {
73 template<>
74 struct is_fundamental<caffe2::__f16> : std::integral_constant<bool, true> {
75 };
76 } // namespace std
77 
78 #endif // CAFFE2_CORE_TYPES_H_
Definition: types.h:72
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...