6 #ifndef XGBOOST_BASE_H_
7 #define XGBOOST_BASE_H_
22 #ifndef XGBOOST_STRICT_R_MODE
23 #define XGBOOST_STRICT_R_MODE 0
32 #ifndef XGBOOST_LOG_WITH_TIME
33 #define XGBOOST_LOG_WITH_TIME 1
39 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)
40 #define XGBOOST_ALIGNAS(X) alignas(X)
42 #define XGBOOST_ALIGNAS(X)
46 #define XGBOOST_EXPECT(cond, ret) __builtin_expect((cond), (ret))
48 #define XGBOOST_EXPECT(cond, ret) (cond)
54 #if defined(__CUDA__) || defined(__NVCC__)
55 #define XGBOOST_DEVICE __host__ __device__
57 #define XGBOOST_DEVICE
60 #if defined(__CUDA__) || defined(__CUDACC__)
61 #define XGBOOST_HOST_DEV_INLINE XGBOOST_DEVICE __forceinline__
62 #define XGBOOST_DEV_INLINE __device__ __forceinline__
64 #define XGBOOST_HOST_DEV_INLINE
65 #define XGBOOST_DEV_INLINE
70 #define XGBOOST_RESTRICT __restrict
72 #define XGBOOST_RESTRICT __restrict__
76 #if !defined(XGBOOST_MM_PREFETCH_PRESENT) && !defined(XGBOOST_BUILTIN_PREFETCH_PRESENT)
78 #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64))) || defined(__INTEL_COMPILER)
80 #define XGBOOST_MM_PREFETCH_PRESENT
81 #define XGBOOST_BUILTIN_PREFETCH_PRESENT
82 #elif defined(__GNUC__)
84 #define XGBOOST_BUILTIN_PREFETCH_PRESENT
137 template <
typename T>
170 template <
typename T2>
187 g.grad_ = grad_ + rhs.grad_;
188 g.hess_ = hess_ + rhs.hess_;
200 g.grad_ = grad_ - rhs.grad_;
201 g.hess_ = hess_ - rhs.hess_;
213 g.grad_ = grad_ * multiplier;
214 g.hess_ = hess_ * multiplier;
226 g.grad_ = grad_ / divisor;
227 g.hess_ = hess_ / divisor;
232 return grad_ == rhs.grad_ && hess_ == rhs.hess_;
279 g.grad_ = grad_ + rhs.grad_;
280 g.hess_ = hess_ + rhs.hess_;
292 g.grad_ = grad_ - rhs.grad_;
293 g.hess_ = hess_ - rhs.hess_;
298 return grad_ == rhs.grad_ && hess_ == rhs.hess_;
306 using Args = std::vector<std::pair<std::string, std::string> >;
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:57
Fixed point representation for high precision gradient pair. Has a different interface so we don't ac...
Definition: base.h:253
T ValueT
Definition: base.h:259
XGBOOST_DEVICE GradientPairInt64 operator+(const GradientPairInt64 &rhs) const
Definition: base.h:277
XGBOOST_DEVICE bool operator==(const GradientPairInt64 &rhs) const
Definition: base.h:297
GradientPairInt64()=default
XGBOOST_DEVICE T GetQuantisedHess() const
Definition: base.h:269
GradientPairInt64(GradientPairInt64 const &g)=default
GradientPairInt64 & operator=(GradientPairInt64 const &g)=default
XGBOOST_DEVICE GradientPairInt64 & operator-=(const GradientPairInt64 &rhs)
Definition: base.h:284
friend std::ostream & operator<<(std::ostream &os, const GradientPairInt64 &g)
Definition: base.h:300
XGBOOST_DEVICE GradientPairInt64 & operator+=(const GradientPairInt64 &rhs)
Definition: base.h:271
XGBOOST_DEVICE T GetQuantisedGrad() const
Definition: base.h:268
XGBOOST_DEVICE GradientPairInt64(T grad, T hess)
Definition: base.h:261
XGBOOST_DEVICE GradientPairInt64 operator-(const GradientPairInt64 &rhs) const
Definition: base.h:290
Implementation of gradient statistics pair. Template specialisation may be used to overload different...
Definition: base.h:138
GradientPairInternal(GradientPairInternal &&g)=default
XGBOOST_DEVICE GradientPairInternal< T > operator*(float multiplier) const
Definition: base.h:211
XGBOOST_DEVICE GradientPairInternal< T > & operator+=(const GradientPairInternal< T > &rhs)
Definition: base.h:179
void Add(const ValueT &grad, const ValueT &hess)
Definition: base.h:150
T ValueT
Definition: base.h:148
friend std::ostream & operator<<(std::ostream &os, const GradientPairInternal< T > &g)
Definition: base.h:239
XGBOOST_DEVICE GradientPairInternal(T grad, T hess)
Definition: base.h:157
XGBOOST_DEVICE GradientPairInternal< T > & operator*=(float multiplier)
Definition: base.h:205
XGBOOST_DEVICE GradientPairInternal(int value)
Definition: base.h:235
XGBOOST_DEVICE GradientPairInternal< T > operator+(const GradientPairInternal< T > &rhs) const
Definition: base.h:185
XGBOOST_DEVICE GradientPairInternal< T > & operator/=(float divisor)
Definition: base.h:218
XGBOOST_DEVICE GradientPairInternal< T > operator/(float divisor) const
Definition: base.h:224
XGBOOST_DEVICE T GetHess() const
Definition: base.h:177
XGBOOST_DEVICE GradientPairInternal< T > & operator-=(const GradientPairInternal< T > &rhs)
Definition: base.h:192
GradientPairInternal & operator=(GradientPairInternal &&that)=default
XGBOOST_DEVICE GradientPairInternal< T > operator-(const GradientPairInternal< T > &rhs) const
Definition: base.h:198
GradientPairInternal(GradientPairInternal const &g)=default
XGBOOST_DEVICE T GetGrad() const
Definition: base.h:176
GradientPairInternal & operator=(GradientPairInternal const &that)=default
XGBOOST_DEVICE GradientPairInternal(const GradientPairInternal< T2 > &g)
Definition: base.h:171
GradientPairInternal()=default
XGBOOST_DEVICE bool operator==(const GradientPairInternal< T > &rhs) const
Definition: base.h:231
Learner interface that integrates objective, gbm and evaluation together. This is the user facing XGB...
Definition: base.h:89
std::vector< std::pair< std::string, std::string > > Args
Definition: base.h:306
std::uint32_t bst_group_t
Type for ranking group index.
Definition: base.h:115
std::int32_t bst_node_t
Type for tree node index and tree depth.
Definition: base.h:111
dmlc::omp_ulong omp_ulong
define unsigned long for openmp loop
Definition: base.h:312
dmlc::omp_uint bst_omp_uint
define unsigned int for openmp loop
Definition: base.h:314
std::int32_t bst_bin_t
Type for histogram bin index. We sometimes use -1 to indicate invalid bin.
Definition: base.h:103
std::int32_t XGBoostVersionT
Type used for representing version number in binary form.
Definition: base.h:316
std::uint64_t bst_idx_t
Type for data row index (sample).
Definition: base.h:107
std::int32_t bst_tree_t
Type for indexing trees.
Definition: base.h:127
std::uint32_t bst_target_t
Type for indexing into output targets.
Definition: base.h:119
std::int16_t bst_d_ordinal_t
Ordinal of a CUDA device.
Definition: base.h:131
std::uint32_t bst_uint
unsigned integer type used for feature index.
Definition: base.h:91
std::int32_t bst_layer_t
Type for indexing boosted layers.
Definition: base.h:123
std::uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:99
constexpr float kRtEps
small eps gap for minimum split decision.
Definition: base.h:309
std::uint64_t bst_ulong
unsigned long integers
Definition: base.h:93
float bst_float
float type, used for storing statistics
Definition: base.h:95
std::int32_t bst_cat_t
Categorical value type.
Definition: base.h:97