Go to the documentation of this file.
6 #ifndef XGBOOST_BASE_H_
7 #define XGBOOST_BASE_H_
20 #ifndef XGBOOST_STRICT_R_MODE
21 #define XGBOOST_STRICT_R_MODE 0
22 #endif // XGBOOST_STRICT_R_MODE
30 #ifndef XGBOOST_LOG_WITH_TIME
31 #define XGBOOST_LOG_WITH_TIME 1
32 #endif // XGBOOST_LOG_WITH_TIME
37 #ifndef XGBOOST_CUSTOMIZE_LOGGER
38 #define XGBOOST_CUSTOMIZE_LOGGER XGBOOST_STRICT_R_MODE
39 #endif // XGBOOST_CUSTOMIZE_LOGGER
44 #ifndef XGBOOST_CUSTOMIZE_GLOBAL_PRNG
45 #define XGBOOST_CUSTOMIZE_GLOBAL_PRNG XGBOOST_STRICT_R_MODE
46 #endif // XGBOOST_CUSTOMIZE_GLOBAL_PRNG
51 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)
52 #define XGBOOST_ALIGNAS(X) alignas(X)
54 #define XGBOOST_ALIGNAS(X)
55 #endif // defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)
57 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4) && \
58 !defined(__CUDACC__) && !defined(__sun) && !defined(sun)
59 #include <parallel/algorithm>
60 #define XGBOOST_PARALLEL_SORT(X, Y, Z) __gnu_parallel::sort((X), (Y), (Z))
61 #define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) \
62 __gnu_parallel::stable_sort((X), (Y), (Z))
63 #elif defined(_MSC_VER) && (!__INTEL_COMPILER)
65 #define XGBOOST_PARALLEL_SORT(X, Y, Z) concurrency::parallel_sort((X), (Y), (Z))
66 #define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) std::stable_sort((X), (Y), (Z))
68 #define XGBOOST_PARALLEL_SORT(X, Y, Z) std::sort((X), (Y), (Z))
69 #define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) std::stable_sort((X), (Y), (Z))
70 #endif // GLIBC VERSION
73 #define XGBOOST_EXPECT(cond, ret) __builtin_expect((cond), (ret))
75 #define XGBOOST_EXPECT(cond, ret) (cond)
76 #endif // defined(__GNUC__)
81 #if defined (__CUDA__) || defined(__NVCC__)
82 #define XGBOOST_DEVICE __host__ __device__
84 #define XGBOOST_DEVICE
85 #endif // defined (__CUDA__) || defined(__NVCC__)
87 #if defined(__CUDA__) || defined(__CUDACC__)
88 #define XGBOOST_HOST_DEV_INLINE XGBOOST_DEVICE __forceinline__
89 #define XGBOOST_DEV_INLINE __device__ __forceinline__
91 #define XGBOOST_HOST_DEV_INLINE
92 #define XGBOOST_DEV_INLINE
93 #endif // defined(__CUDA__) || defined(__CUDACC__)
96 #if !defined(XGBOOST_MM_PREFETCH_PRESENT) && !defined(XGBOOST_BUILTIN_PREFETCH_PRESENT)
98 #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64))) || defined(__INTEL_COMPILER)
100 #define XGBOOST_MM_PREFETCH_PRESENT
101 #define XGBOOST_BUILTIN_PREFETCH_PRESENT
102 #elif defined(__GNUC__)
104 #define XGBOOST_BUILTIN_PREFETCH_PRESENT
107 #endif // !defined(XGBOOST_MM_PREFETCH_PRESENT) && !defined()
140 template <
typename T>
174 template <
typename T2>
193 g.grad_ = grad_ + rhs.grad_;
194 g.hess_ = hess_ + rhs.hess_;
208 g.grad_ = grad_ - rhs.grad_;
209 g.hess_ = hess_ - rhs.hess_;
221 g.grad_ = grad_ * multiplier;
222 g.hess_ = hess_ * multiplier;
234 g.grad_ = grad_ / divisor;
235 g.hess_ = hess_ / divisor;
240 return grad_ == rhs.grad_ && hess_ == rhs.hess_;
245 static_cast<float>(value));
262 using Args = std::vector<std::pair<std::string, std::string> >;
278 #if DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
279 #if __GNUC__ == 4 && __GNUC_MINOR__ < 8
282 #endif // __GNUC__ == 4 && __GNUC_MINOR__ < 8
283 #endif // DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
286 #endif // XGBOOST_BASE_H_
XGBOOST_DEVICE GradientPairInternal(int value)
Definition: base.h:243
XGBOOST_DEVICE GradientPairInternal< T > & operator/=(float divisor)
Definition: base.h:226
std::vector< std::pair< std::string, std::string > > Args
Definition: base.h:262
int32_t bst_int
integer type.
Definition: base.h:115
Implementation of gradient statistics pair. Template specialisation may be used to overload different...
Definition: base.h:141
XGBOOST_DEVICE GradientPairInternal< T > operator*(float multiplier) const
Definition: base.h:219
XGBOOST_DEVICE GradientPairInternal< T > & operator-=(const GradientPairInternal< T > &rhs)
Definition: base.h:198
XGBOOST_DEVICE GradientPairInternal(const GradientPairInternal< T2 > &g)
Definition: base.h:175
XGBOOST_DEVICE bool operator==(const GradientPairInternal< T > &rhs) const
Definition: base.h:239
int32_t XGBoostVersionT
Type used for representing version number in binary form.
Definition: base.h:272
XGBOOST_DEVICE GradientPairInternal()
Definition: base.h:162
dmlc::omp_ulong omp_ulong
define unsigned long for openmp loop
Definition: base.h:268
uint64_t bst_ulong
unsigned long integers
Definition: base.h:117
XGBOOST_DEVICE GradientPairInternal< T > operator/(float divisor) const
Definition: base.h:232
uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:123
dmlc::omp_uint bst_omp_uint
define unsigned int for openmp loop
Definition: base.h:270
uint32_t bst_group_t
Type for ranking group index.
Definition: base.h:134
void Add(const ValueT &grad, const ValueT &hess)
Definition: base.h:153
XGBOOST_DEVICE GradientPairInternal< T > & operator+=(const GradientPairInternal< T > &rhs)
Definition: base.h:183
XGBOOST_DEVICE T GetGrad() const
Definition: base.h:180
int32_t bst_cat_t
Categorical value type.
Definition: base.h:121
int32_t bst_node_t
Type for tree node index.
Definition: base.h:132
std::size_t bst_row_t
Type for data row index.
Definition: base.h:130
XGBOOST_DEVICE GradientPairInternal< T > operator-(const GradientPairInternal< T > &rhs) const
Definition: base.h:205
XGBOOST_DEVICE GradientPairInternal< T > operator+(const GradientPairInternal< T > &rhs) const
Definition: base.h:190
friend std::ostream & operator<<(std::ostream &os, const GradientPairInternal< T > &g)
Definition: base.h:248
constexpr bst_float kRtEps
small eps gap for minimum split decision.
Definition: base.h:265
XGBOOST_DEVICE GradientPairInternal(T grad, T hess)
Definition: base.h:164
T ValueT
Definition: base.h:151
uint32_t bst_uint
unsigned integer type used for feature index.
Definition: base.h:113
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
XGBOOST_DEVICE T GetHess() const
Definition: base.h:181
static void Reduce(GradientPairInternal< T > &a, const GradientPairInternal< T > &b)
Definition: base.h:158
XGBOOST_DEVICE GradientPairInternal< T > & operator*=(float multiplier)
Definition: base.h:213
namespace of xgboost
Definition: base.h:110
float bst_float
float type, used for storing statistics
Definition: base.h:119