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 <c10/util/typeid.h>
11 #include "caffe2/proto/caffe2_pb.h"
12 #include <c10/util/Half.h>
13 
14 namespace caffe2 {
15 
16 // Storage orders that are often used in the image applications.
17 enum StorageOrder {
18  UNKNOWN = 0,
19  NHWC = 1,
20  NCHW = 2,
21 };
22 
23 inline StorageOrder StringToStorageOrder(const string& str) {
24  if (str == "NHWC" || str == "nhwc") {
25  return StorageOrder::NHWC;
26  } else if (str == "NCHW" || str == "nchw") {
27  return StorageOrder::NCHW;
28  } else {
29  LOG(ERROR) << "Unknown storage order string: " << str;
30  return StorageOrder::UNKNOWN;
31  }
32 }
33 
34 inline constexpr char NameScopeSeparator() { return '/'; }
35 
36 // From TypeMeta to caffe2::DataType protobuffer enum.
37 CAFFE2_API TensorProto::DataType TypeMetaToDataType(const TypeMeta& meta);
38 
39 // From caffe2::DataType protobuffer enum to TypeMeta
40 CAFFE2_API const TypeMeta& DataTypeToTypeMeta(const TensorProto::DataType& dt);
41 
42 } // namespace caffe2
43 
45 // at::Half is defined in c10/util/Half.h. Currently half float operators are
46 // mainly on CUDA gpus.
47 // The reason we do not directly use the cuda __half data type is because that
48 // requires compilation with nvcc. The float16 data type should be compatible
49 // with the cuda __half data type, but will allow us to refer to the data type
50 // without the need of cuda.
51 static_assert(sizeof(unsigned short) == 2,
52  "Short on this platform is not 16 bit.");
53 namespace caffe2 {
54 // Helpers to avoid using typeinfo with -rtti
55 template <typename T>
56 inline bool fp16_type();
57 
58 template <>
59 inline bool fp16_type<at::Half>() {
60  return true;
61 }
62 
63 template <typename T>
64 inline bool fp16_type() {
65  return false;
66 }
67 
68 } // namespace caffe2
69 
70 #endif // CAFFE2_CORE_TYPES_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13