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

Method InitGPU

src/treelearner/gpu_tree_learner.cpp:677–736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

675}
676
677void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
678 // Get the max bin size, used for selecting best GPU kernel
679 max_num_bin_ = 0;
680 #if GPU_DEBUG >= 1
681 printf("bin size: ");
682 #endif
683 for (int i = 0; i < num_feature_groups_; ++i) {
684 #if GPU_DEBUG >= 1
685 printf("%d, ", train_data_->FeatureGroupNumBin(i));
686 #endif
687 max_num_bin_ = std::max(max_num_bin_, train_data_->FeatureGroupNumBin(i));
688 }
689 #if GPU_DEBUG >= 1
690 printf("\n");
691 #endif
692 // initialize GPU
693 dev_ = boost::compute::system::default_device();
694 if (platform_id >= 0 && device_id >= 0) {
695 const std::vector<boost::compute::platform> platforms = boost::compute::system::platforms();
696 if (static_cast<int>(platforms.size()) > platform_id) {
697 const std::vector<boost::compute::device> platform_devices = platforms[platform_id].devices();
698 if (static_cast<int>(platform_devices.size()) > device_id) {
699 Log::Info("Using requested OpenCL platform %d device %d", platform_id, device_id);
700 dev_ = platform_devices[device_id];
701 }
702 }
703 }
704 // determine which kernel to use based on the max number of bins
705 if (max_num_bin_ <= 16) {
706 kernel_source_ = kernel16_src_;
707 kernel_name_ = "histogram16";
708 device_bin_size_ = 16;
709 dword_features_ = 8;
710 } else if (max_num_bin_ <= 64) {
711 kernel_source_ = kernel64_src_;
712 kernel_name_ = "histogram64";
713 device_bin_size_ = 64;
714 dword_features_ = 4;
715 } else if (max_num_bin_ <= 256) {
716 kernel_source_ = kernel256_src_;
717 kernel_name_ = "histogram256";
718 device_bin_size_ = 256;
719 dword_features_ = 4;
720 } else {
721 Log::Fatal("bin size %d cannot run on GPU", max_num_bin_);
722 }
723 if (max_num_bin_ == 65) {
724 Log::Warning("Setting max_bin to 63 is sugguested for best performance");
725 }
726 if (max_num_bin_ == 17) {
727 Log::Warning("Setting max_bin to 15 is sugguested for best performance");
728 }
729 ctx_ = boost::compute::context(dev_);
730 queue_ = boost::compute::command_queue(ctx_, dev_);
731 Log::Info("Using GPU Device: %s, Vendor: %s", dev_.name().c_str(), dev_.vendor().c_str());
732 BuildGPUKernels();
733 AllocateGPUMemory();
734 // setup GPU kernel arguments after we allocating all the buffers

Callers

nothing calls this directly

Calls 7

contextClass · 0.50
command_queueClass · 0.50
FeatureGroupNumBinMethod · 0.45
sizeMethod · 0.45
devicesMethod · 0.45
nameMethod · 0.45
vendorMethod · 0.45

Tested by

no test coverage detected