mxnet
3rdparty
dmlc-core
include
dmlc
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
#if defined(__clang__)
153
#define DMLC_SUPPRESS_UBSAN __attribute__((no_sanitize("undefined")))
154
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
155
#define DMLC_SUPPRESS_UBSAN __attribute__((no_sanitize_undefined))
156
#else
157
#define DMLC_SUPPRESS_UBSAN
158
#endif
159
161
#define DMLC_STR_CONCAT_(__x, __y) __x##__y
162
#define DMLC_STR_CONCAT(__x, __y) DMLC_STR_CONCAT_(__x, __y)
163
172
#ifndef DISALLOW_COPY_AND_ASSIGN
173
# if DMLC_USE_CXX11
174
# define DISALLOW_COPY_AND_ASSIGN(T) \
175
T(T const&) = delete; \
176
T(T&&) = delete; \
177
T& operator=(T const&) = delete; \
178
T& operator=(T&&) = delete
179
# else
180
# define DISALLOW_COPY_AND_ASSIGN(T) \
181
T(T const&); \
182
T& operator=(T const&)
183
# endif
184
#endif
185
186
#ifdef __APPLE__
187
# define off64_t off_t
188
#endif
189
190
#ifdef _MSC_VER
191
#if _MSC_VER < 1900
192
// NOTE: sprintf_s is not equivalent to snprintf,
193
// they are equivalent when success, which is sufficient for our case
194
#define snprintf sprintf_s
195
#define vsnprintf vsprintf_s
196
#endif
197
#else
198
#ifdef _FILE_OFFSET_BITS
199
#if _FILE_OFFSET_BITS == 32
200
#pragma message("Warning: FILE OFFSET BITS defined to be 32 bit")
201
#endif
202
#endif
203
204
extern
"C"
{
205
#include <sys/types.h>
206
}
207
#endif
208
209
#ifdef _MSC_VER
210
typedef
signed
char
int8_t;
212
typedef
__int16 int16_t;
213
typedef
__int32 int32_t;
214
typedef
__int64 int64_t;
215
typedef
unsigned
char
uint8_t;
216
typedef
unsigned
__int16 uint16_t;
217
typedef
unsigned
__int32 uint32_t;
218
typedef
unsigned
__int64 uint64_t;
220
#else
221
#include <inttypes.h>
222
#endif
223
#include <string>
224
#include <vector>
225
226
#if defined(_MSC_VER) && _MSC_VER < 1900
227
#define noexcept_true throw ()
228
#define noexcept_false
229
#define noexcept(a) noexcept_##a
230
#endif
231
232
#if DMLC_USE_CXX11
233
#define DMLC_THROW_EXCEPTION noexcept(false)
234
#define DMLC_NO_EXCEPTION noexcept(true)
235
#else
236
#define DMLC_THROW_EXCEPTION
237
#define DMLC_NO_EXCEPTION
238
#endif
239
241
namespace
dmlc
{
247
template
<
typename
T>
248
inline
T *
BeginPtr
(std::vector<T> &vec) {
// NOLINT(*)
249
if
(vec.size() == 0) {
250
return
NULL;
251
}
else
{
252
return
&vec[0];
253
}
254
}
260
template
<
typename
T>
261
inline
const
T *
BeginPtr
(
const
std::vector<T> &vec) {
262
if
(vec.size() == 0) {
263
return
NULL;
264
}
else
{
265
return
&vec[0];
266
}
267
}
273
inline
char
*
BeginPtr
(std::string &str) {
// NOLINT(*)
274
if
(str.length() == 0)
return
NULL;
275
return
&str[0];
276
}
282
inline
const
char
*
BeginPtr
(
const
std::string &str) {
283
if
(str.length() == 0)
return
NULL;
284
return
&str[0];
285
}
286
}
// namespace dmlc
287
288
#if defined(_MSC_VER) && _MSC_VER < 1900
289
#define constexpr const
290
#define alignof __alignof
291
#endif
292
293
/* If fopen64 is not defined by current machine,
294
replace fopen64 with std::fopen. Also determine ability to print stack trace
295
for fatal error and define DMLC_LOG_STACK_TRACE if stack trace can be
296
produced. Always keep this include directive at the bottom of dmlc/base.h */
297
#ifdef DMLC_CORE_USE_CMAKE
298
#include <dmlc/build_config.h>
299
#else
300
#include <
dmlc/build_config_default.h
>
301
#endif
302
303
#endif // DMLC_BASE_H_
build_config_default.h
Default detection logic for fopen64 and other symbols. May be overriden by CMake.
dmlc
namespace for dmlc
Definition:
array_view.h:12
dmlc::BeginPtr
T * BeginPtr(std::vector< T > &vec)
safely get the beginning address of a vector
Definition:
base.h:248
Generated on Thu Jan 5 2023 03:47:39 for mxnet by
1.8.17