/*! * Copyright 2017 XGBoost contributors */ #pragma once #include #include #include // Need key value pair definition #include #include "../../src/common/hist_util.h" #include "../../src/tree/param.h" #include "device_helpers.cuh" #include "types.cuh" #ifndef NCCL #define NCCL 1 #endif #if (NCCL) #include "nccl.h" #endif namespace xgboost { namespace tree { struct DeviceGMat { dh::dvec gidx; dh::dvec ridx; void Init(int device_idx, const common::GHistIndexMatrix &gmat, bst_uint begin, bst_uint end); }; struct HistBuilder { gpu_gpair *d_hist; int n_bins; __host__ __device__ HistBuilder(gpu_gpair *ptr, int n_bins); __device__ void Add(gpu_gpair gpair, int gidx, int nidx) const; __device__ gpu_gpair Get(int gidx, int nidx) const; }; struct DeviceHist { int n_bins; dh::dvec data; void Init(int max_depth); void Reset(int device_idx); HistBuilder GetBuilder(); gpu_gpair *GetLevelPtr(int depth); int LevelSize(int depth); }; class GPUHistBuilder { public: GPUHistBuilder(); ~GPUHistBuilder(); void Init(const TrainParam ¶m); void UpdateParam(const TrainParam ¶m) { this->param = param; this->gpu_param = GPUTrainingParam(param.min_child_weight, param.reg_lambda, param.reg_alpha, param.max_delta_step); } void InitData(const std::vector &gpair, DMatrix &fmat, // NOLINT const RegTree &tree); void Update(const std::vector &gpair, DMatrix *p_fmat, RegTree *p_tree); void BuildHist(int depth); void FindSplit(int depth); template void FindSplitSpecialize(int depth); template void LaunchFindSplit(int depth); void InitFirstNode(const std::vector &gpair); void UpdatePosition(int depth); void UpdatePositionDense(int depth); void UpdatePositionSparse(int depth); void ColSampleTree(); void ColSampleLevel(); bool UpdatePredictionCache(const DMatrix *data, std::vector *p_out_preds); TrainParam param; GPUTrainingParam gpu_param; common::HistCutMatrix hmat_; common::GHistIndexMatrix gmat_; MetaInfo *info; bool initialised; bool is_dense; const DMatrix *p_last_fmat_; bool prediction_cache_initialised; // choose which memory type to use (DEVICE or DEVICE_MANAGED) dh::bulk_allocator ba; // dh::bulk_allocator ba; // can't be used // with NCCL dh::CubMemory cub_mem; std::vector feature_set_tree; std::vector feature_set_level; bst_uint num_rows; int n_devices; // below vectors are for each devices used std::vector dList; std::vector device_row_segments; std::vector device_element_segments; std::vector hist_vec; std::vector> nodes; std::vector> nodes_temp; std::vector> nodes_child_temp; std::vector> left_child_smallest; std::vector> left_child_smallest_temp; std::vector> feature_flags; std::vector> fidx_min_map; std::vector> feature_segments; std::vector> prediction_cache; std::vector> position; std::vector> position_tmp; std::vector device_matrix; std::vector> device_gpair; std::vector> gidx_feature_map; std::vector> gidx_fvalue_map; std::vector streams; #if (NCCL) std::vector comms; std::vector> find_split_comms; #endif }; } // namespace tree } // namespace xgboost