xgboost

generic_parameters.h
Go to the documentation of this file.
1
5 #ifndef XGBOOST_GENERIC_PARAMETERS_H_
6 #define XGBOOST_GENERIC_PARAMETERS_H_
7
8 #include <xgboost/logging.h>
9 #include <xgboost/parameter.h>
10
11 #include <string>
12
13 namespace xgboost {
14
15 struct GenericParameter : public XGBoostParameter<GenericParameter> {
16 // Constant representing the device ID of CPU.
17 static int32_t constexpr kCpuId = -1;
18 static int64_t constexpr kDefaultSeed = 0;
19
20 public:
21 // stored random seed
22 int64_t seed { kDefaultSeed };
23 // whether seed the PRNG each iteration
24 bool seed_per_iteration;
25 // number of threads to use if OpenMP is enabled
26 // if equals 0, use system default
27 int nthread;
28 // primary device, -1 means no gpu.
29 int gpu_id;
30 // fail when gpu_id is invalid
31 bool fail_on_invalid_gpu_id {false};
32 // gpu page size in external memory mode, 0 means using the default.
33 size_t gpu_page_size;
34 bool validate_parameters {false};
35
36 void CheckDeprecated() {
37 if (this->n_gpus != 0) {
38 LOG(WARNING)
39 << "\nn_gpus: "
40 << this->__MANAGER__()->Find("n_gpus")->GetFieldInfo().description;
41 }
42 }
48 void ConfigureGpuId(bool require_gpu);
49
50 // declare parameters
51 DMLC_DECLARE_PARAMETER(GenericParameter) {
52 DMLC_DECLARE_FIELD(seed).set_default(kDefaultSeed).describe(
53 "Random number seed during training.");
54 DMLC_DECLARE_ALIAS(seed, random_state);
55 DMLC_DECLARE_FIELD(seed_per_iteration)
56 .set_default(false)
57 .describe(
58 "Seed PRNG determnisticly via iterator number, "
59 "this option will be switched on automatically on distributed "
60 "mode.");
61 DMLC_DECLARE_FIELD(nthread).set_default(0).describe(
62 "Number of threads to use.");
63 DMLC_DECLARE_ALIAS(nthread, n_jobs);
64
65 DMLC_DECLARE_FIELD(gpu_id)
66 .set_default(-1)
67 .set_lower_bound(-1)
68 .describe("The primary GPU device ordinal.");
69 DMLC_DECLARE_FIELD(fail_on_invalid_gpu_id)
70 .set_default(false)
71 .describe("Fail with error when gpu_id is invalid.");
72 DMLC_DECLARE_FIELD(gpu_page_size)
73 .set_default(0)
74 .set_lower_bound(0)
75 .describe("GPU page size when running in external memory mode.");
76 DMLC_DECLARE_FIELD(validate_parameters)
77 .set_default(false)
78 .describe("Enable checking whether parameters are used or not.");
79 DMLC_DECLARE_FIELD(n_gpus)
80 .set_default(0)
81 .set_range(0, 1)
82 .describe(
83 "\n\tDeprecated. Single process multi-GPU training is no longer supported."
84 "\n\tPlease switch to distributed training with one process per GPU."
85 "\n\tThis can be done using Dask or Spark. See documentation for details.");
86 }
87
88 private:
89 // number of devices to use (deprecated).
90 int n_gpus {0}; // NOLINT
91 };
92 } // namespace xgboost
93
94 #endif // XGBOOST_GENERIC_PARAMETERS_H_
xgboost::GenericParameter::gpu_id
int gpu_id
Definition: generic_parameters.h:29
xgboost::GenericParameter::DMLC_DECLARE_PARAMETER
DMLC_DECLARE_PARAMETER(GenericParameter)
Definition: generic_parameters.h:51
xgboost::GenericParameter
Definition: generic_parameters.h:15
parameter.h
macro for using C++11 enum class as DMLC parameter
xgboost::GenericParameter::seed_per_iteration
bool seed_per_iteration
Definition: generic_parameters.h:24
xgboost::GenericParameter::CheckDeprecated
void CheckDeprecated()
Definition: generic_parameters.h:36
xgboost::GenericParameter::fail_on_invalid_gpu_id
bool fail_on_invalid_gpu_id
Definition: generic_parameters.h:31
xgboost::XGBoostParameter
Definition: parameter.h:84
xgboost::GenericParameter::kDefaultSeed
static constexpr int64_t kDefaultSeed
Definition: generic_parameters.h:18
xgboost::GenericParameter::ConfigureGpuId
void ConfigureGpuId(bool require_gpu)
Configure the parameter ‘gpu_id’.
xgboost::GenericParameter::gpu_page_size
size_t gpu_page_size
Definition: generic_parameters.h:33
xgboost::GenericParameter::validate_parameters
bool validate_parameters
Definition: generic_parameters.h:34
xgboost::GenericParameter::nthread
int nthread
Definition: generic_parameters.h:27
xgboost::GenericParameter::kCpuId
static constexpr int32_t kCpuId
Definition: generic_parameters.h:17
xgboost::GenericParameter::seed
int64_t seed
Definition: generic_parameters.h:22
xgboost
namespace of xgboost
Definition: base.h:110