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  private:
17  // cached value for CFS CPU limit. (used in containerized env)
18  int32_t cfs_cpu_count_; // NOLINT
19 
20  public:
21  // Constant representing the device ID of CPU.
22  static int32_t constexpr kCpuId = -1;
23  static int64_t constexpr kDefaultSeed = 0;
24 
25  public:
27 
28  // stored random seed
29  int64_t seed { kDefaultSeed };
30  // whether seed the PRNG each iteration
31  bool seed_per_iteration{false};
32  // number of threads to use if OpenMP is enabled
33  // if equals 0, use system default
34  int nthread{0};
35  // primary device, -1 means no gpu.
36  int gpu_id{kCpuId};
37  // fail when gpu_id is invalid
38  bool fail_on_invalid_gpu_id {false};
39  bool validate_parameters {false};
40 
46  void ConfigureGpuId(bool require_gpu);
50  int32_t Threads() const;
51 
52  bool IsCPU() const { return gpu_id == kCpuId; }
53 
54  // declare parameters
56  DMLC_DECLARE_FIELD(seed).set_default(kDefaultSeed).describe(
57  "Random number seed during training.");
58  DMLC_DECLARE_ALIAS(seed, random_state);
59  DMLC_DECLARE_FIELD(seed_per_iteration)
60  .set_default(false)
61  .describe("Seed PRNG determnisticly via iterator number.");
62  DMLC_DECLARE_FIELD(nthread).set_default(0).describe(
63  "Number of threads to use.");
64  DMLC_DECLARE_ALIAS(nthread, n_jobs);
65 
66  DMLC_DECLARE_FIELD(gpu_id)
67  .set_default(-1)
68  .set_lower_bound(-1)
69  .describe("The primary GPU device ordinal.");
70  DMLC_DECLARE_FIELD(fail_on_invalid_gpu_id)
71  .set_default(false)
72  .describe("Fail with error when gpu_id is invalid.");
73  DMLC_DECLARE_FIELD(validate_parameters)
74  .set_default(false)
75  .describe("Enable checking whether parameters are used or not.");
76  }
77 };
78 
80 } // namespace xgboost
81 
82 #endif // XGBOOST_GENERIC_PARAMETERS_H_
xgboost::GenericParameter::gpu_id
int gpu_id
Definition: generic_parameters.h:36
xgboost::GenericParameter::DMLC_DECLARE_PARAMETER
DMLC_DECLARE_PARAMETER(GenericParameter)
Definition: generic_parameters.h:55
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:31
xgboost::GenericParameter::fail_on_invalid_gpu_id
bool fail_on_invalid_gpu_id
Definition: generic_parameters.h:38
xgboost::XGBoostParameter
Definition: parameter.h:84
xgboost::GenericParameter::kDefaultSeed
static constexpr int64_t kDefaultSeed
Definition: generic_parameters.h:23
xgboost::GenericParameter::ConfigureGpuId
void ConfigureGpuId(bool require_gpu)
Configure the parameter ‘gpu_id’.
xgboost::GenericParameter::validate_parameters
bool validate_parameters
Definition: generic_parameters.h:39
xgboost::GenericParameter::nthread
int nthread
Definition: generic_parameters.h:34
xgboost::GenericParameter::Threads
int32_t Threads() const
xgboost::GenericParameter::IsCPU
bool IsCPU() const
Definition: generic_parameters.h:52
xgboost::GenericParameter::GenericParameter
GenericParameter()
xgboost::GenericParameter::kCpuId
static constexpr int32_t kCpuId
Definition: generic_parameters.h:22
xgboost::GenericParameter::seed
int64_t seed
Definition: generic_parameters.h:29
xgboost
namespace of xgboost
Definition: base.h:110