MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / WaitAndGetHistograms

Method WaitAndGetHistograms

src/treelearner/gpu_tree_learner.cpp:194–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193template <typename HistType>
194void GPUTreeLearner::WaitAndGetHistograms(HistogramBinEntry* histograms) {
195 HistType* hist_outputs = reinterpret_cast<HistType*>(host_histogram_outputs_);
196 // when the output is ready, the computation is done
197 histograms_wait_obj_.wait();
198 #pragma omp parallel for schedule(static)
199 for (int i = 0; i < num_dense_feature_groups_; ++i) {
200 if (!feature_masks_[i]) {
201 continue;
202 }
203 int dense_group_index = dense_feature_group_map_[i];
204 auto old_histogram_array = histograms + train_data_->GroupBinBoundary(dense_group_index);
205 int bin_size = train_data_->FeatureGroupNumBin(dense_group_index);
206 if (device_bin_mults_[i] == 1) {
207 for (int j = 0; j < bin_size; ++j) {
208 old_histogram_array[j].sum_gradients = hist_outputs[i * device_bin_size_+ j].sum_gradients;
209 old_histogram_array[j].sum_hessians = hist_outputs[i * device_bin_size_ + j].sum_hessians;
210 old_histogram_array[j].cnt = (data_size_t)hist_outputs[i * device_bin_size_ + j].cnt;
211 }
212 } else {
213 // values of this feature has been redistributed to multiple bins; need a reduction here
214 int ind = 0;
215 for (int j = 0; j < bin_size; ++j) {
216 double sum_g = 0.0, sum_h = 0.0;
217 size_t cnt = 0;
218 for (int k = 0; k < device_bin_mults_[i]; ++k) {
219 sum_g += hist_outputs[i * device_bin_size_+ ind].sum_gradients;
220 sum_h += hist_outputs[i * device_bin_size_+ ind].sum_hessians;
221 cnt += hist_outputs[i * device_bin_size_ + ind].cnt;
222 ind++;
223 }
224 old_histogram_array[j].sum_gradients = sum_g;
225 old_histogram_array[j].sum_hessians = sum_h;
226 old_histogram_array[j].cnt = (data_size_t)cnt;
227 }
228 }
229 }
230 queue_.enqueue_unmap_buffer(device_histogram_outputs_, host_histogram_outputs_);
231}
232
233void GPUTreeLearner::AllocateGPUMemory() {
234 num_dense_feature_groups_ = 0;

Callers

nothing calls this directly

Calls 4

enqueue_unmap_bufferMethod · 0.80
waitMethod · 0.45
GroupBinBoundaryMethod · 0.45
FeatureGroupNumBinMethod · 0.45

Tested by

no test coverage detected