1 #ifndef CAFFE2_CORE_COMMON_H_ 2 #define CAFFE2_CORE_COMMON_H_ 11 #include <type_traits> 15 #include <TargetConditionals.h> 26 #include "caffe2/core/macros.h" 31 #define CAFFE2_VERSION_MAJOR 0 32 #define CAFFE2_VERSION_MINOR 6 33 #define CAFFE2_VERSION_PATCH 0 34 #define CAFFE2_VERSION \ 35 (CAFFE2_VERSION_MAJOR * 10000 + CAFFE2_VERSION_MINOR * 100 + \ 42 typedef int64_t TIndex;
49 template <
typename Key,
typename Value>
50 using CaffeMap = std::map<Key, Value>;
59 using std::unique_ptr;
63 #define CAFFE_NOT_IMPLEMENTED CAFFE_THROW("Not Implemented.") 66 #define UNUSED_VARIABLE __attribute__((unused)) 70 #ifndef DISABLE_COPY_AND_ASSIGN 71 #define DISABLE_COPY_AND_ASSIGN(classname) \ 73 classname(const classname&) = delete; \ 74 classname& operator=(const classname&) = delete 78 #if !defined(CAFFE2_MOBILE) 79 #if defined(__ANDROID__) 80 #define CAFFE2_ANDROID 1 81 #define CAFFE2_MOBILE 1 82 #elif (defined(__APPLE__) && \ 83 (TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE)) 85 #define CAFFE2_MOBILE 1 86 #elif (defined(__APPLE__) && TARGET_OS_MAC) 88 #define CAFFE2_MOBILE 0 90 #define CAFFE2_MOBILE 0 91 #endif // ANDROID / IOS / MACOS 92 #endif // CAFFE2_MOBILE 96 #define CAFFE2_ALIGNED(x) __declspec(align(x)) 98 #define CAFFE2_ALIGNED(x) __attribute__((aligned(x))) 105 #ifndef __GNUC_PREREQ 106 #if defined __GNUC__ && defined __GNUC_MINOR__ 107 #define __GNUC_PREREQ(maj, min) \ 108 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 110 #define __GNUC_PREREQ(maj, min) 0 114 #if defined(__GNUC__) 115 #if __GNUC_PREREQ(4, 9) 116 #define CAFFE2_EXPORT [[gnu::visibility("default")]] 118 #define CAFFE2_EXPORT __attribute__((__visibility__("default"))) 121 #define CAFFE2_EXPORT 126 #if __cplusplus >= 201402L || \ 127 (defined __cpp_lib_make_unique && __cpp_lib_make_unique >= 201304L) || \ 128 (defined(_MSC_VER) && _MSC_VER >= 1900) 129 using std::make_unique;
132 template<
typename T,
typename... Args>
133 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
134 make_unique(Args&&... args) {
135 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
140 typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type
141 make_unique(
const size_t n) {
142 return std::unique_ptr<T>(
new typename std::remove_extent<T>::type[n]());
146 template<
typename T,
typename... Args>
147 typename std::enable_if<
148 std::extent<T>::value != 0, std::unique_ptr<T>>::type
149 make_unique(Args&&...) =
delete;
155 using std::to_string;
157 template <
typename T>
158 std::string to_string(T value)
160 std::ostringstream os;
167 template <
typename Dst,
typename Src>
168 inline Dst dynamic_cast_if_rtti(Src ptr) {
170 return dynamic_cast<Dst
>(ptr);
172 return reinterpret_cast<Dst
>(ptr);
179 template <
int... values>
183 static inline bool ContainsInternal(
const int i) {
186 template <
int First,
int Second,
int... Rest>
187 static inline bool ContainsInternal(
const int i) {
188 return (i == First) && ContainsInternal<Second, Rest...>(i);
192 static inline bool Contains(
const int i) {
193 return ContainsInternal<values...>(i);
200 static inline bool Contains(
const int i) {
207 #endif // CAFFE2_CORE_COMMON_H_
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...