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

Method BeforeTrain

src/treelearner/gpu_tree_learner.cpp:760–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

758}
759
760void GPUTreeLearner::BeforeTrain() {
761 #if GPU_DEBUG >= 2
762 printf("Copying intial full gradients and hessians to device\n");
763 #endif
764 // Copy initial full hessians and gradients to GPU.
765 // We start copying as early as possible, instead of at ConstructHistogram().
766 if (!use_bagging_ && num_dense_feature_groups_) {
767 if (!is_constant_hessian_) {
768 hessians_future_ = queue_.enqueue_write_buffer_async(device_hessians_, 0, num_data_ * sizeof(score_t), hessians_);
769 } else {
770 // setup hessian parameters only
771 score_t const_hessian = hessians_[0];
772 for (int i = 0; i <= kMaxLogWorkgroupsPerFeature; ++i) {
773 // hessian is passed as a parameter
774 histogram_kernels_[i].set_arg(6, const_hessian);
775 histogram_allfeats_kernels_[i].set_arg(6, const_hessian);
776 histogram_fulldata_kernels_[i].set_arg(6, const_hessian);
777 }
778 }
779 gradients_future_ = queue_.enqueue_write_buffer_async(device_gradients_, 0, num_data_ * sizeof(score_t), gradients_);
780 }
781
782 SerialTreeLearner::BeforeTrain();
783
784 // use bagging
785 if (data_partition_->leaf_count(0) != num_data_ && num_dense_feature_groups_) {
786 // On GPU, we start copying indices, gradients and hessians now, instead at ConstructHistogram()
787 // copy used gradients and hessians to ordered buffer
788 const data_size_t* indices = data_partition_->indices();
789 data_size_t cnt = data_partition_->leaf_count(0);
790 #if GPU_DEBUG > 0
791 printf("Using bagging, examples count = %d\n", cnt);
792 #endif
793 // transfer the indices to GPU
794 indices_future_ = boost::compute::copy_async(indices, indices + cnt, device_data_indices_->begin(), queue_);
795 if (!is_constant_hessian_) {
796 #pragma omp parallel for schedule(static)
797 for (data_size_t i = 0; i < cnt; ++i) {
798 ordered_hessians_[i] = hessians_[indices[i]];
799 }
800 // transfer hessian to GPU
801 hessians_future_ = queue_.enqueue_write_buffer_async(device_hessians_, 0, cnt * sizeof(score_t), ordered_hessians_.data());
802 } else {
803 // setup hessian parameters only
804 score_t const_hessian = hessians_[indices[0]];
805 for (int i = 0; i <= kMaxLogWorkgroupsPerFeature; ++i) {
806 // hessian is passed as a parameter
807 histogram_kernels_[i].set_arg(6, const_hessian);
808 histogram_allfeats_kernels_[i].set_arg(6, const_hessian);
809 histogram_fulldata_kernels_[i].set_arg(6, const_hessian);
810 }
811 }
812 #pragma omp parallel for schedule(static)
813 for (data_size_t i = 0; i < cnt; ++i) {
814 ordered_gradients_[i] = gradients_[indices[i]];
815 }
816 // transfer gradients to GPU
817 gradients_future_ = queue_.enqueue_write_buffer_async(device_gradients_, 0, cnt * sizeof(score_t), ordered_gradients_.data());

Callers

nothing calls this directly

Calls 7

copy_asyncFunction · 0.85
dataMethod · 0.80
set_argMethod · 0.45
leaf_countMethod · 0.45
indicesMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected