tree_learner.cpp 2.18 KB
Newer Older
1
2
3
4
/*!
 * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for license information.
 */
Guolin Ke's avatar
Guolin Ke committed
5
6
#include <LightGBM/tree_learner.h>

7
#include "gpu_tree_learner.h"
8
#include "linear_tree_learner.h"
Guolin Ke's avatar
Guolin Ke committed
9
#include "parallel_tree_learner.h"
10
#include "serial_tree_learner.h"
11
#include "cuda/cuda_single_gpu_tree_learner.hpp"
Guolin Ke's avatar
Guolin Ke committed
12
13
14

namespace LightGBM {

15
TreeLearner* TreeLearner::CreateTreeLearner(const std::string& learner_type, const std::string& device_type,
16
                                            const Config* config, const bool boosting_on_cuda) {
17
18
  if (device_type == std::string("cpu")) {
    if (learner_type == std::string("serial")) {
19
20
21
22
23
      if (config->linear_tree) {
        return new LinearTreeLearner(config);
      } else {
        return new SerialTreeLearner(config);
      }
24
    } else if (learner_type == std::string("feature")) {
Guolin Ke's avatar
Guolin Ke committed
25
      return new FeatureParallelTreeLearner<SerialTreeLearner>(config);
26
    } else if (learner_type == std::string("data")) {
Guolin Ke's avatar
Guolin Ke committed
27
      return new DataParallelTreeLearner<SerialTreeLearner>(config);
28
    } else if (learner_type == std::string("voting")) {
Guolin Ke's avatar
Guolin Ke committed
29
      return new VotingParallelTreeLearner<SerialTreeLearner>(config);
30
    }
31
  } else if (device_type == std::string("gpu")) {
32
    if (learner_type == std::string("serial")) {
Guolin Ke's avatar
Guolin Ke committed
33
      return new GPUTreeLearner(config);
34
    } else if (learner_type == std::string("feature")) {
Guolin Ke's avatar
Guolin Ke committed
35
      return new FeatureParallelTreeLearner<GPUTreeLearner>(config);
36
    } else if (learner_type == std::string("data")) {
Guolin Ke's avatar
Guolin Ke committed
37
      return new DataParallelTreeLearner<GPUTreeLearner>(config);
38
    } else if (learner_type == std::string("voting")) {
Guolin Ke's avatar
Guolin Ke committed
39
      return new VotingParallelTreeLearner<GPUTreeLearner>(config);
40
    }
41
  } else if (device_type == std::string("cuda")) {
42
43
    if (learner_type == std::string("serial")) {
      if (config->num_gpu == 1) {
44
        return new CUDASingleGPUTreeLearner(config, boosting_on_cuda);
45
      } else {
46
        Log::Fatal("Currently cuda version only supports training on a single GPU.");
47
48
      }
    } else {
49
      Log::Fatal("Currently cuda version only supports training on a single machine.");
50
    }
Guolin Ke's avatar
Guolin Ke committed
51
52
53
54
55
  }
  return nullptr;
}

}  // namespace LightGBM