mxnet
base.h
Go to the documentation of this file.
1 
6 #ifndef DMLC_BASE_H_
7 #define DMLC_BASE_H_
8 
10 #ifndef DMLC_USE_GLOG
11 #define DMLC_USE_GLOG 0
12 #endif
13 
20 #ifndef DMLC_LOG_FATAL_THROW
21 #define DMLC_LOG_FATAL_THROW 1
22 #endif
23 
28 #ifndef DMLC_LOG_BEFORE_THROW
29 #define DMLC_LOG_BEFORE_THROW 0
30 #endif
31 
36 #ifndef DMLC_LOG_CUSTOMIZE
37 #define DMLC_LOG_CUSTOMIZE 0
38 #endif
39 
43 #ifndef DMLC_LOG_DEBUG
44 #ifdef NDEBUG
45 #define DMLC_LOG_DEBUG 0
46 #else
47 #define DMLC_LOG_DEBUG 1
48 #endif
49 #endif
50 
52 #ifndef DMLC_USE_HDFS
53 #define DMLC_USE_HDFS 0
54 #endif
55 
57 #ifndef DMLC_USE_S3
58 #define DMLC_USE_S3 0
59 #endif
60 
62 #ifndef DMLC_USE_PS
63 #define DMLC_USE_PS 0
64 #endif
65 
67 #ifndef DMLC_USE_CXX11
68 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER)
69 #define DMLC_USE_CXX11 1
70 #else
71 #define DMLC_USE_CXX11 (__cplusplus >= 201103L)
72 #endif
73 #endif
74 
76 #ifndef DMLC_STRICT_CXX11
77 #if defined(_MSC_VER)
78 #define DMLC_STRICT_CXX11 1
79 #else
80 #define DMLC_STRICT_CXX11 (__cplusplus >= 201103L)
81 #endif
82 #endif
83 
85 #ifndef DMLC_CXX11_THREAD_LOCAL
86 #if defined(_MSC_VER)
87 #define DMLC_CXX11_THREAD_LOCAL (_MSC_VER >= 1900)
88 #elif defined(__clang__)
89 #define DMLC_CXX11_THREAD_LOCAL (__has_feature(cxx_thread_local))
90 #else
91 #define DMLC_CXX11_THREAD_LOCAL (__cplusplus >= 201103L)
92 #endif
93 #endif
94 
96 #ifndef DMLC_MODERN_THREAD_LOCAL
97 #define DMLC_MODERN_THREAD_LOCAL 1
98 #endif
99 
100 
101 
103 #ifndef DMLC_ENABLE_RTTI
104 #define DMLC_ENABLE_RTTI 1
105 #endif
106 
108 #ifndef DMLC_USE_FOPEN64
109 #define DMLC_USE_FOPEN64 1
110 #endif
111 
113 #if DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
114 #if __GNUC__ == 4 && __GNUC_MINOR__ < 6
115 #pragma message("Will need g++-4.6 or higher to compile all" \
116  "the features in dmlc-core, " \
117  "compile without c++0x, some features may be disabled")
118 #undef DMLC_USE_CXX11
119 #define DMLC_USE_CXX11 0
120 #endif
121 #endif
122 
127 #ifndef DMLC_IO_USE_LITTLE_ENDIAN
128 #define DMLC_IO_USE_LITTLE_ENDIAN 1
129 #endif
130 
135 #ifndef DMLC_ENABLE_STD_THREAD
136 #define DMLC_ENABLE_STD_THREAD DMLC_USE_CXX11
137 #endif
138 
140 #ifndef DMLC_USE_REGEX
141 #define DMLC_USE_REGEX DMLC_STRICT_CXX11
142 #endif
143 
145 #if defined(__GNUC__)
146 #define DMLC_ATTRIBUTE_UNUSED __attribute__((unused))
147 #else
148 #define DMLC_ATTRIBUTE_UNUSED
149 #endif
150 
152 #define DMLC_STR_CONCAT_(__x, __y) __x##__y
153 #define DMLC_STR_CONCAT(__x, __y) DMLC_STR_CONCAT_(__x, __y)
154 
163 #ifndef DISALLOW_COPY_AND_ASSIGN
164 # if DMLC_USE_CXX11
165 # define DISALLOW_COPY_AND_ASSIGN(T) \
166  T(T const&) = delete; \
167  T(T&&) = delete; \
168  T& operator=(T const&) = delete; \
169  T& operator=(T&&) = delete
170 # else
171 # define DISALLOW_COPY_AND_ASSIGN(T) \
172  T(T const&); \
173  T& operator=(T const&)
174 # endif
175 #endif
176 
177 #ifdef __APPLE__
178 # define off64_t off_t
179 #endif
180 
181 #ifdef _MSC_VER
182 #if _MSC_VER < 1900
183 // NOTE: sprintf_s is not equivalent to snprintf,
184 // they are equivalent when success, which is sufficient for our case
185 #define snprintf sprintf_s
186 #define vsnprintf vsprintf_s
187 #endif
188 #else
189 #ifdef _FILE_OFFSET_BITS
190 #if _FILE_OFFSET_BITS == 32
191 #pragma message("Warning: FILE OFFSET BITS defined to be 32 bit")
192 #endif
193 #endif
194 
195 extern "C" {
196 #include <sys/types.h>
197 }
198 #endif
199 
200 #ifdef _MSC_VER
201 typedef signed char int8_t;
203 typedef __int16 int16_t;
204 typedef __int32 int32_t;
205 typedef __int64 int64_t;
206 typedef unsigned char uint8_t;
207 typedef unsigned __int16 uint16_t;
208 typedef unsigned __int32 uint32_t;
209 typedef unsigned __int64 uint64_t;
211 #else
212 #include <inttypes.h>
213 #endif
214 #include <string>
215 #include <vector>
216 
217 #if defined(_MSC_VER) && _MSC_VER < 1900
218 #define noexcept_true throw ()
219 #define noexcept_false
220 #define noexcept(a) noexcept_##a
221 #endif
222 
223 #if DMLC_USE_CXX11
224 #define DMLC_THROW_EXCEPTION noexcept(false)
225 #define DMLC_NO_EXCEPTION noexcept(true)
226 #else
227 #define DMLC_THROW_EXCEPTION
228 #define DMLC_NO_EXCEPTION
229 #endif
230 
232 namespace dmlc {
238 template<typename T>
239 inline T *BeginPtr(std::vector<T> &vec) { // NOLINT(*)
240  if (vec.size() == 0) {
241  return NULL;
242  } else {
243  return &vec[0];
244  }
245 }
251 template<typename T>
252 inline const T *BeginPtr(const std::vector<T> &vec) {
253  if (vec.size() == 0) {
254  return NULL;
255  } else {
256  return &vec[0];
257  }
258 }
264 inline char* BeginPtr(std::string &str) { // NOLINT(*)
265  if (str.length() == 0) return NULL;
266  return &str[0];
267 }
273 inline const char* BeginPtr(const std::string &str) {
274  if (str.length() == 0) return NULL;
275  return &str[0];
276 }
277 } // namespace dmlc
278 
279 #if defined(_MSC_VER) && _MSC_VER < 1900
280 #define constexpr const
281 #define alignof __alignof
282 #endif
283 
284 /* If fopen64 is not defined by current machine,
285  replace fopen64 with std::fopen. Also determine ability to print stack trace
286  for fatal error and define DMLC_LOG_STACK_TRACE if stack trace can be
287  produced. Always keep this include directive at the bottom of dmlc/base.h */
288 #ifdef DMLC_CORE_USE_CMAKE
289 #include <dmlc/build_config.h>
290 #else
292 #endif
293 
294 #endif // DMLC_BASE_H_
T * BeginPtr(std::vector< T > &vec)
safely get the beginning address of a vector
Definition: base.h:239
namespace for dmlc
Definition: array_view.h:12
Default detection logic for fopen64 and other symbols. May be overriden by CMake. ...