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