1 #ifndef CAFFE2_CORE_COMMON_H_ 2 #define CAFFE2_CORE_COMMON_H_ 12 #include <type_traits> 16 #include <TargetConditionals.h> 27 #include "caffe2/core/macros.h" 29 #include <c10/macros/Macros.h> 31 #include "c10/util/string_utils.h" 40 template <
typename Key,
typename Value>
41 using CaffeMap = std::map<Key, Value>;
50 using std::unique_ptr;
54 #define CAFFE_NOT_IMPLEMENTED CAFFE_THROW("Not Implemented.") 61 #define CAFFE2_UNUSED __attribute__((__unused__)) 62 #define CAFFE2_USED __attribute__((__used__)) 67 #define CAFFE2_ALIGNED(x) __declspec(align(x)) 69 #define CAFFE2_ALIGNED(x) __attribute__((aligned(x))) 73 #define CAFFE2_NORETURN __declspec(noreturn) 75 #define CAFFE2_NORETURN __attribute__((noreturn)) 78 #if (defined _MSC_VER && !defined NOMINMAX) 84 #if __cplusplus >= 201402L || \ 85 (defined __cpp_lib_make_unique && __cpp_lib_make_unique >= 201304L) || \ 86 (defined(_MSC_VER) && _MSC_VER >= 1900) 88 using std::make_unique;
91 template<
typename T,
typename... Args>
92 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
93 make_unique(Args&&... args) {
94 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
99 typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type
100 make_unique(
const size_t n) {
101 return std::unique_ptr<T>(
new typename std::remove_extent<T>::type[n]());
105 template<
typename T,
typename... Args>
106 typename std::enable_if<
107 std::extent<T>::value != 0, std::unique_ptr<T>>::type
108 make_unique(Args&&...) =
delete;
112 #if defined(__ANDROID__) && !defined(__NDK_MAJOR__) 116 #endif // defined(__ANDROID__) && !defined(__NDK_MAJOR__) 119 template <
typename Dst,
typename Src>
120 inline Dst dynamic_cast_if_rtti(Src ptr) {
122 return dynamic_cast<Dst
>(ptr);
124 return static_cast<Dst
>(ptr);
131 template <
int... values>
135 static inline bool ContainsInternal(
const int i) {
138 template <
int First,
int Second,
int... Rest>
139 static inline bool ContainsInternal(
const int i) {
140 return (i == First) || ContainsInternal<Second, Rest...>(i);
144 static inline bool Contains(
const int i) {
145 return ContainsInternal<values...>(i);
152 static inline bool Contains(
const int ) {
161 CAFFE2_API
bool HasCudaRuntime();
162 CAFFE2_API
bool HasHipRuntime();
167 CAFFE2_API
void SetCudaRuntimeFlag();
168 CAFFE2_API
void SetHipRuntimeFlag();
172 CAFFE2_API
const std::map<string, string>& GetBuildOptions();
176 #endif // CAFFE2_CORE_COMMON_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...