6 #ifndef XGBOOST_BASE_H_
7 #define XGBOOST_BASE_H_
20 #ifndef XGBOOST_STRICT_R_MODE
21 #define XGBOOST_STRICT_R_MODE 0
30 #ifndef XGBOOST_LOG_WITH_TIME
31 #define XGBOOST_LOG_WITH_TIME 1
37 #ifndef XGBOOST_CUSTOMIZE_GLOBAL_PRNG
38 #define XGBOOST_CUSTOMIZE_GLOBAL_PRNG 0
44 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)
45 #define XGBOOST_ALIGNAS(X) alignas(X)
47 #define XGBOOST_ALIGNAS(X)
51 #define XGBOOST_EXPECT(cond, ret) __builtin_expect((cond), (ret))
53 #define XGBOOST_EXPECT(cond, ret) (cond)
59 #if defined (__CUDA__) || defined(__NVCC__)
60 #define XGBOOST_DEVICE __host__ __device__
62 #define XGBOOST_DEVICE
65 #if defined(__CUDA__) || defined(__CUDACC__)
66 #define XGBOOST_HOST_DEV_INLINE XGBOOST_DEVICE __forceinline__
67 #define XGBOOST_DEV_INLINE __device__ __forceinline__
69 #define XGBOOST_HOST_DEV_INLINE
70 #define XGBOOST_DEV_INLINE
74 #if !defined(XGBOOST_MM_PREFETCH_PRESENT) && !defined(XGBOOST_BUILTIN_PREFETCH_PRESENT)
76 #if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64))) || defined(__INTEL_COMPILER)
78 #define XGBOOST_MM_PREFETCH_PRESENT
79 #define XGBOOST_BUILTIN_PREFETCH_PRESENT
80 #elif defined(__GNUC__)
82 #define XGBOOST_BUILTIN_PREFETCH_PRESENT
131 template <
typename T>
168 template <
typename T2>
187 g.grad_ = grad_ + rhs.grad_;
188 g.hess_ = hess_ + rhs.hess_;
202 g.grad_ = grad_ - rhs.grad_;
203 g.hess_ = hess_ - rhs.hess_;
215 g.grad_ = grad_ * multiplier;
216 g.hess_ = hess_ * multiplier;
228 g.grad_ = grad_ / divisor;
229 g.hess_ = hess_ / divisor;
234 return grad_ == rhs.grad_ && hess_ == rhs.hess_;
239 static_cast<float>(value));
283 g.grad_ = grad_ + rhs.grad_;
284 g.hess_ = hess_ + rhs.hess_;
296 g.grad_ = grad_ - rhs.grad_;
297 g.hess_ = hess_ - rhs.hess_;
302 return grad_ == rhs.grad_ && hess_ == rhs.hess_;
310 using Args = std::vector<std::pair<std::string, std::string> >;
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:62
Fixed point representation for high precision gradient pair. Has a different interface so we don't ac...
Definition: base.h:257
T ValueT
Definition: base.h:263
XGBOOST_DEVICE GradientPairInt64 operator+(const GradientPairInt64 &rhs) const
Definition: base.h:281
XGBOOST_DEVICE bool operator==(const GradientPairInt64 &rhs) const
Definition: base.h:301
GradientPairInt64()=default
XGBOOST_DEVICE T GetQuantisedHess() const
Definition: base.h:273
GradientPairInt64(GradientPairInt64 const &g)=default
GradientPairInt64 & operator=(GradientPairInt64 const &g)=default
XGBOOST_DEVICE GradientPairInt64 & operator-=(const GradientPairInt64 &rhs)
Definition: base.h:288
friend std::ostream & operator<<(std::ostream &os, const GradientPairInt64 &g)
Definition: base.h:304
XGBOOST_DEVICE GradientPairInt64 & operator+=(const GradientPairInt64 &rhs)
Definition: base.h:275
XGBOOST_DEVICE T GetQuantisedGrad() const
Definition: base.h:272
XGBOOST_DEVICE GradientPairInt64(T grad, T hess)
Definition: base.h:265
XGBOOST_DEVICE GradientPairInt64 operator-(const GradientPairInt64 &rhs) const
Definition: base.h:294
Implementation of gradient statistics pair. Template specialisation may be used to overload different...
Definition: base.h:132
GradientPairInternal(GradientPairInternal &&g)=default
XGBOOST_DEVICE GradientPairInternal< T > operator*(float multiplier) const
Definition: base.h:213
XGBOOST_DEVICE GradientPairInternal< T > & operator+=(const GradientPairInternal< T > &rhs)
Definition: base.h:177
void Add(const ValueT &grad, const ValueT &hess)
Definition: base.h:144
T ValueT
Definition: base.h:142
friend std::ostream & operator<<(std::ostream &os, const GradientPairInternal< T > &g)
Definition: base.h:242
XGBOOST_DEVICE GradientPairInternal(T grad, T hess)
Definition: base.h:155
XGBOOST_DEVICE GradientPairInternal< T > & operator*=(float multiplier)
Definition: base.h:207
XGBOOST_DEVICE GradientPairInternal(int value)
Definition: base.h:237
XGBOOST_DEVICE GradientPairInternal< T > operator+(const GradientPairInternal< T > &rhs) const
Definition: base.h:184
XGBOOST_DEVICE GradientPairInternal< T > & operator/=(float divisor)
Definition: base.h:220
XGBOOST_DEVICE GradientPairInternal< T > operator/(float divisor) const
Definition: base.h:226
XGBOOST_DEVICE T GetHess() const
Definition: base.h:175
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:199
static void Reduce(GradientPairInternal< T > &a, const GradientPairInternal< T > &b)
Definition: base.h:149
GradientPairInternal(GradientPairInternal const &g)=default
XGBOOST_DEVICE T GetGrad() const
Definition: base.h:174
GradientPairInternal & operator=(GradientPairInternal const &that)=default
XGBOOST_DEVICE GradientPairInternal(const GradientPairInternal< T2 > &g)
Definition: base.h:169
GradientPairInternal()=default
XGBOOST_DEVICE bool operator==(const GradientPairInternal< T > &rhs) const
Definition: base.h:233
Core data structure for multi-target trees.
Definition: base.h:87
std::vector< std::pair< std::string, std::string > > Args
Definition: base.h:310
std::uint32_t bst_group_t
Type for ranking group index.
Definition: base.h:109
std::int32_t bst_node_t
Type for tree node index.
Definition: base.h:107
dmlc::omp_ulong omp_ulong
define unsigned long for openmp loop
Definition: base.h:316
dmlc::omp_uint bst_omp_uint
define unsigned int for openmp loop
Definition: base.h:318
std::int32_t bst_bin_t
Type for histogram bin index. We sometimes use -1 to indicate invalid bin.
Definition: base.h:101
std::int32_t XGBoostVersionT
Type used for representing version number in binary form.
Definition: base.h:320
std::uint64_t bst_idx_t
Type for data row index (sample).
Definition: base.h:105
std::int32_t bst_tree_t
Type for indexing trees.
Definition: base.h:121
std::uint32_t bst_target_t
Type for indexing into output targets.
Definition: base.h:113
std::int16_t bst_d_ordinal_t
Ordinal of a CUDA device.
Definition: base.h:125
std::uint32_t bst_uint
unsigned integer type used for feature index.
Definition: base.h:89
std::int32_t bst_layer_t
Type for indexing boosted layers.
Definition: base.h:117
std::uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:97
std::uint64_t bst_ulong
unsigned long integers
Definition: base.h:91
float bst_float
float type, used for storing statistics
Definition: base.h:93
std::int32_t bst_cat_t
Categorical value type.
Definition: base.h:95
constexpr bst_float kRtEps
small eps gap for minimum split decision.
Definition: base.h:313