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 } // namespace caffe2
55 
56 // Make __f16 a fundamental type.
57 namespace std {
58 template<>
59 struct is_fundamental<caffe2::__f16> : std::integral_constant<bool, true> {
60 };
61 } // namespace std
62 
63 #endif // CAFFE2_CORE_TYPES_H_
Definition: types.h:57
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...