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

Method BuildGPUKernels

src/treelearner/gpu_tree_learner.cpp:569–642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567}
568
569void GPUTreeLearner::BuildGPUKernels() {
570 Log::Info("Compiling OpenCL Kernel with %d bins...", device_bin_size_);
571 // destroy any old kernels
572 histogram_kernels_.clear();
573 histogram_allfeats_kernels_.clear();
574 histogram_fulldata_kernels_.clear();
575 // create OpenCL kernels for different number of workgroups per feature
576 histogram_kernels_.resize(kMaxLogWorkgroupsPerFeature+1);
577 histogram_allfeats_kernels_.resize(kMaxLogWorkgroupsPerFeature+1);
578 histogram_fulldata_kernels_.resize(kMaxLogWorkgroupsPerFeature+1);
579 // currently we don't use constant memory
580 int use_constants = 0;
581 OMP_INIT_EX();
582 #pragma omp parallel for schedule(guided)
583 for (int i = 0; i <= kMaxLogWorkgroupsPerFeature; ++i) {
584 OMP_LOOP_EX_BEGIN();
585 boost::compute::program program;
586 std::ostringstream opts;
587 // compile the GPU kernel depending if double precision is used, constant hessian is used, etc.
588 opts << " -D POWER_FEATURE_WORKGROUPS=" << i
589 << " -D USE_CONSTANT_BUF=" << use_constants << " -D USE_DP_FLOAT=" << int(config_->gpu_use_dp)
590 << " -D CONST_HESSIAN=" << int(is_constant_hessian_)
591 << " -cl-mad-enable -cl-no-signed-zeros -cl-fast-relaxed-math";
592 #if GPU_DEBUG >= 1
593 std::cout << "Building GPU kernels with options: " << opts.str() << std::endl;
594 #endif
595 // kernel with indices in an array
596 try {
597 program = boost::compute::program::build_with_source(kernel_source_, ctx_, opts.str());
598 }
599 catch (boost::compute::opencl_error &e) {
600 #pragma omp critical
601 {
602 std::cerr << "Build Options:" << opts.str() << std::endl;
603 std::cerr << "Build Log:" << std::endl << GetBuildLog(opts.str()) << std::endl;
604 Log::Fatal("Cannot build GPU program: %s", e.what());
605 }
606 }
607 histogram_kernels_[i] = program.create_kernel(kernel_name_);
608
609 // kernel with all features enabled, with elimited branches
610 opts << " -D ENABLE_ALL_FEATURES=1";
611 try {
612 program = boost::compute::program::build_with_source(kernel_source_, ctx_, opts.str());
613 }
614 catch (boost::compute::opencl_error &e) {
615 #pragma omp critical
616 {
617 std::cerr << "Build Options:" << opts.str() << std::endl;
618 std::cerr << "Build Log:" << std::endl << GetBuildLog(opts.str()) << std::endl;
619 Log::Fatal("Cannot build GPU program: %s", e.what());
620 }
621 }
622 histogram_allfeats_kernels_[i] = program.create_kernel(kernel_name_);
623
624 // kernel with all data indices (for root node, and assumes that root node always uses all features)
625 opts << " -D IGNORE_INDICES=1";
626 try {

Callers

nothing calls this directly

Calls 4

create_kernelMethod · 0.80
clearMethod · 0.45
resizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected