Add basic unittests for gpu-hist method. (#3785)

* Split building histogram into separated class.
* Extract `InitCompressedRow` definition.
* Basic tests for gpu-hist.
* Document the code more verbosely.
* Removed `HistCutUnit`.
* Removed some duplicated copies in `GPUHistMaker`.
* Implement LCG and use it in tests.
This commit is contained in:
trivialfis
2018-10-15 15:47:00 +13:00
committed by Rory Mitchell
parent 184efff9f9
commit 516457fadc
9 changed files with 928 additions and 404 deletions

View File

@@ -204,7 +204,7 @@ inline void LaunchN(int device_idx, size_t n, L lambda) {
const int GRID_SIZE =
static_cast<int>(DivRoundUp(n, ITEMS_PER_THREAD * BLOCK_THREADS));
LaunchNKernel<<<GRID_SIZE, BLOCK_THREADS>>>(static_cast<size_t>(0), n,
lambda);
lambda);
}
/*
@@ -365,6 +365,7 @@ class DVec2 {
T *other() { return buff_.Alternate(); }
};
/*! \brief Helper for allocating large block of memory. */
template <MemoryType MemoryT>
class BulkAllocator {
std::vector<char *> d_ptr_;

View File

@@ -53,34 +53,15 @@ struct GHistEntry {
}
};
/*! \brief Cut configuration for one feature */
struct HistCutUnit {
/*! \brief the index pointer of each histunit */
const bst_float* cut;
/*! \brief number of cutting point, containing the maximum point */
uint32_t size;
// default constructor
HistCutUnit() = default;
// constructor
HistCutUnit(const bst_float* cut, uint32_t size)
: cut(cut), size(size) {}
};
/*! \brief cut configuration for all the features. */
/*! \brief Cut configuration for all the features. */
struct HistCutMatrix {
/*! \brief unit pointer to rows by element position */
/*! \brief Unit pointer to rows by element position */
std::vector<uint32_t> row_ptr;
/*! \brief minimum value of each feature */
std::vector<bst_float> min_val;
/*! \brief the cut field */
std::vector<bst_float> cut;
uint32_t GetBinIdx(const Entry &e);
/*! \brief Get histogram bound for fid */
inline HistCutUnit operator[](bst_uint fid) const {
return {dmlc::BeginPtr(cut) + row_ptr[fid],
row_ptr[fid + 1] - row_ptr[fid]};
}
using WXQSketch = common::WXQuantileSketch<bst_float, bst_float>;
@@ -189,7 +170,7 @@ class GHistIndexBlockMatrix {
/*!
* \brief histogram of graident statistics for a single node.
* Consists of multiple GHistEntry's, each entry showing total graident statistics
* Consists of multiple GHistEntry's, each entry showing total graident statistics
* for that particular bin
* Uses global bin id so as to represent all features simultaneously
*/

View File

@@ -75,7 +75,8 @@ inline void CheckGradientMax(const std::vector<GradientPair>& gpair) {
auto* ptr = reinterpret_cast<const float*>(gpair.data());
float abs_max =
std::accumulate(ptr, ptr + (gpair.size() * 2), 0.f,
[=](float a, float b) { return max(abs(a), abs(b)); });
[=](float a, float b) {
return std::max(abs(a), abs(b)); });
CHECK_LT(abs_max, std::pow(2.0f, 16.0f))
<< "Labels are too large for this algorithm. Rescale to less than 2^16.";
@@ -254,6 +255,7 @@ XGBOOST_DEVICE float inline LossChangeMissing(const GradientPairT& scan,
const float& parent_gain,
const GPUTrainingParam& param,
bool& missing_left_out) { // NOLINT
// Put gradients of missing values to left
float missing_left_loss =
DeviceCalcLossChange(param, scan + missing, parent_sum, parent_gain);
float missing_right_loss =

File diff suppressed because it is too large Load Diff