[GPU-Plugin] Unify gpu_gpair/bst_gpair. Refactor. (#2477)
This commit is contained in:
@@ -19,7 +19,8 @@
|
||||
/*!
|
||||
* \brief Whether always log console message with time.
|
||||
* It will display like, with timestamp appended to head of the message.
|
||||
* "[21:47:50] 6513x126 matrix with 143286 entries loaded from ../data/agaricus.txt.train"
|
||||
* "[21:47:50] 6513x126 matrix with 143286 entries loaded from
|
||||
* ../data/agaricus.txt.train"
|
||||
*/
|
||||
#ifndef XGBOOST_LOG_WITH_TIME
|
||||
#define XGBOOST_LOG_WITH_TIME 1
|
||||
@@ -36,7 +37,7 @@
|
||||
* \brief Whether to customize global PRNG.
|
||||
*/
|
||||
#ifndef XGBOOST_CUSTOMIZE_GLOBAL_PRNG
|
||||
#define XGBOOST_CUSTOMIZE_GLOBAL_PRNG XGBOOST_STRICT_R_MODE
|
||||
#define XGBOOST_CUSTOMIZE_GLOBAL_PRNG XGBOOST_STRICT_R_MODE
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@@ -48,16 +49,27 @@
|
||||
#define XGBOOST_ALIGNAS(X)
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ >= 8 && !defined(__CUDACC__)
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ >= 8 && \
|
||||
!defined(__CUDACC__)
|
||||
#include <parallel/algorithm>
|
||||
#define XGBOOST_PARALLEL_SORT(X, Y, Z) __gnu_parallel::sort((X), (Y), (Z))
|
||||
#define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) __gnu_parallel::stable_sort((X), (Y), (Z))
|
||||
#define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) \
|
||||
__gnu_parallel::stable_sort((X), (Y), (Z))
|
||||
#else
|
||||
#define XGBOOST_PARALLEL_SORT(X, Y, Z) std::sort((X), (Y), (Z))
|
||||
#define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z) std::stable_sort((X), (Y), (Z))
|
||||
#endif
|
||||
|
||||
/*! \brief namespace of xgboo st*/
|
||||
/*!
|
||||
* \brief Tag function as usable by device
|
||||
*/
|
||||
#ifdef __NVCC__
|
||||
#define XGBOOST_DEVICE __host__ __device__
|
||||
#else
|
||||
#define XGBOOST_DEVICE
|
||||
#endif
|
||||
|
||||
/*! \brief namespace of xgboost*/
|
||||
namespace xgboost {
|
||||
/*!
|
||||
* \brief unsigned integer type used in boost,
|
||||
@@ -76,8 +88,41 @@ struct bst_gpair {
|
||||
bst_float grad;
|
||||
/*! \brief second order gradient statistics */
|
||||
bst_float hess;
|
||||
bst_gpair() {}
|
||||
bst_gpair(bst_float grad, bst_float hess) : grad(grad), hess(hess) {}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair() : grad(0), hess(0) {}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair(bst_float grad, bst_float hess)
|
||||
: grad(grad), hess(hess) {}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair &operator+=(const bst_gpair &rhs) {
|
||||
grad += rhs.grad;
|
||||
hess += rhs.hess;
|
||||
return *this;
|
||||
}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair operator+(const bst_gpair &rhs) const {
|
||||
bst_gpair g;
|
||||
g.grad = grad + rhs.grad;
|
||||
g.hess = hess + rhs.hess;
|
||||
return g;
|
||||
}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair &operator-=(const bst_gpair &rhs) {
|
||||
grad -= rhs.grad;
|
||||
hess -= rhs.hess;
|
||||
return *this;
|
||||
}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair operator-(const bst_gpair &rhs) const {
|
||||
bst_gpair g;
|
||||
g.grad = grad - rhs.grad;
|
||||
g.hess = hess - rhs.hess;
|
||||
return g;
|
||||
}
|
||||
|
||||
XGBOOST_DEVICE bst_gpair(int value) {
|
||||
*this = bst_gpair(static_cast<float>(value), static_cast<float>(value));
|
||||
}
|
||||
};
|
||||
|
||||
/*! \brief small eps gap for minimum split decision. */
|
||||
|
||||
Reference in New Issue
Block a user