tree_learner.cpp 2.05 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 "cuda_tree_learner.h"
8
#include "gpu_tree_learner.h"
Guolin Ke's avatar
Guolin Ke committed
9
#include "parallel_tree_learner.h"
10
#include "serial_tree_learner.h"
Guolin Ke's avatar
Guolin Ke committed
11
12
13

namespace LightGBM {

Guolin Ke's avatar
Guolin Ke committed
14
TreeLearner* TreeLearner::CreateTreeLearner(const std::string& learner_type, const std::string& device_type, const Config* config) {
15
16
  if (device_type == std::string("cpu")) {
    if (learner_type == std::string("serial")) {
Guolin Ke's avatar
Guolin Ke committed
17
      return new SerialTreeLearner(config);
18
    } else if (learner_type == std::string("feature")) {
Guolin Ke's avatar
Guolin Ke committed
19
      return new FeatureParallelTreeLearner<SerialTreeLearner>(config);
20
    } else if (learner_type == std::string("data")) {
Guolin Ke's avatar
Guolin Ke committed
21
      return new DataParallelTreeLearner<SerialTreeLearner>(config);
22
    } else if (learner_type == std::string("voting")) {
Guolin Ke's avatar
Guolin Ke committed
23
      return new VotingParallelTreeLearner<SerialTreeLearner>(config);
24
    }
25
  } else if (device_type == std::string("gpu")) {
26
    if (learner_type == std::string("serial")) {
Guolin Ke's avatar
Guolin Ke committed
27
      return new GPUTreeLearner(config);
28
    } else if (learner_type == std::string("feature")) {
Guolin Ke's avatar
Guolin Ke committed
29
      return new FeatureParallelTreeLearner<GPUTreeLearner>(config);
30
    } else if (learner_type == std::string("data")) {
Guolin Ke's avatar
Guolin Ke committed
31
      return new DataParallelTreeLearner<GPUTreeLearner>(config);
32
    } else if (learner_type == std::string("voting")) {
Guolin Ke's avatar
Guolin Ke committed
33
      return new VotingParallelTreeLearner<GPUTreeLearner>(config);
34
    }
35
36
37
38
39
40
41
42
43
44
  } else if (device_type == std::string("cuda")) {
    if (learner_type == std::string("serial")) {
      return new CUDATreeLearner(config);
    } else if (learner_type == std::string("feature")) {
      return new FeatureParallelTreeLearner<CUDATreeLearner>(config);
    } else if (learner_type == std::string("data")) {
      return new DataParallelTreeLearner<CUDATreeLearner>(config);
    } else if (learner_type == std::string("voting")) {
      return new VotingParallelTreeLearner<CUDATreeLearner>(config);
    }
Guolin Ke's avatar
Guolin Ke committed
45
46
47
48
49
  }
  return nullptr;
}

}  // namespace LightGBM