cuda_regression_objective.hpp 4.51 KB
Newer Older
1
2
3
4
5
6
/*!
 * Copyright (c) 2021 Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for
 * license information.
 */

7
8
#ifndef LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_
#define LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_
9

10
#ifdef USE_CUDA
11
12
13
14
15
16
17
18
19
20
21
22

#define GET_GRADIENTS_BLOCK_SIZE_REGRESSION (1024)

#include <LightGBM/cuda/cuda_objective_function.hpp>

#include <string>
#include <vector>

#include "../regression_objective.hpp"

namespace LightGBM {

23
24
template <typename HOST_OBJECTIVE>
class CUDARegressionObjectiveInterface: public CUDAObjectiveInterface<HOST_OBJECTIVE> {
25
 public:
26
  explicit CUDARegressionObjectiveInterface(const Config& config): CUDAObjectiveInterface<HOST_OBJECTIVE>(config) {}
27

28
  explicit CUDARegressionObjectiveInterface(const std::vector<std::string>& strs): CUDAObjectiveInterface<HOST_OBJECTIVE>(strs) {}
29
30
31

  void Init(const Metadata& metadata, data_size_t num_data) override;

32
33
 protected:
  double LaunchCalcInitScoreKernel(const int class_id) const override;
34

35
36
37
  CUDAVector<double> cuda_block_buffer_;
  CUDAVector<label_t> cuda_trans_label_;
};
38

39
40
41
class CUDARegressionL2loss : public CUDARegressionObjectiveInterface<RegressionL2loss> {
 public:
  explicit CUDARegressionL2loss(const Config& config);
42

43
  explicit CUDARegressionL2loss(const std::vector<std::string>& strs);
44

45
  ~CUDARegressionL2loss();
46

47
  void Init(const Metadata& metadata, data_size_t num_data) override;
48
49

 protected:
50
  void LaunchGetGradientsKernel(const double* score, score_t* gradients, score_t* hessians) const override;
51

52
  const double* LaunchConvertOutputCUDAKernel(const data_size_t num_data, const double* input, double* output) const override;
53
54

  bool NeedConvertOutputCUDA() const override { return sqrt_; }
55
56
57
};


58
class CUDARegressionL1loss : public CUDARegressionObjectiveInterface<RegressionL1loss> {
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 public:
  explicit CUDARegressionL1loss(const Config& config);

  explicit CUDARegressionL1loss(const std::vector<std::string>& strs);

  ~CUDARegressionL1loss();

  void Init(const Metadata& metadata, data_size_t num_data) override;

 protected:
  CUDAVector<data_size_t> cuda_data_indices_buffer_;
  CUDAVector<double> cuda_weights_prefix_sum_;
  CUDAVector<double> cuda_weights_prefix_sum_buffer_;
  CUDAVector<double> cuda_residual_buffer_;
  CUDAVector<label_t> cuda_weight_by_leaf_buffer_;
  CUDAVector<label_t> cuda_percentile_result_;

76
  double LaunchCalcInitScoreKernel(const int class_id) const override;
77
78
79
80
81

  void LaunchGetGradientsKernel(const double* score, score_t* gradients, score_t* hessians) const override;

  void LaunchRenewTreeOutputCUDAKernel(
    const double* score, const data_size_t* data_indices_in_leaf, const data_size_t* num_data_in_leaf,
82
    const data_size_t* data_start_in_leaf, const int num_leaves, double* leaf_value) const override;
83
84
85
};


86
class CUDARegressionHuberLoss : public CUDARegressionObjectiveInterface<RegressionHuberLoss> {
87
88
89
90
91
92
93
94
95
96
97
98
 public:
  explicit CUDARegressionHuberLoss(const Config& config);

  explicit CUDARegressionHuberLoss(const std::vector<std::string>& strs);

  ~CUDARegressionHuberLoss();

 private:
  void LaunchGetGradientsKernel(const double* score, score_t* gradients, score_t* hessians) const override;
};


99
// http://research.microsoft.com/en-us/um/people/zhang/INRIA/Publis/Tutorial-Estim/node24.html
100
class CUDARegressionFairLoss : public CUDARegressionObjectiveInterface<RegressionFairLoss> {
101
102
103
104
105
106
107
108
109
 public:
  explicit CUDARegressionFairLoss(const Config& config);

  explicit CUDARegressionFairLoss(const std::vector<std::string>& strs);

  ~CUDARegressionFairLoss();

 private:
  void LaunchGetGradientsKernel(const double* score, score_t* gradients, score_t* hessians) const override;
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
};


class CUDARegressionPoissonLoss : public CUDARegressionObjectiveInterface<RegressionPoissonLoss> {
 public:
  explicit CUDARegressionPoissonLoss(const Config& config);

  explicit CUDARegressionPoissonLoss(const std::vector<std::string>& strs);

  ~CUDARegressionPoissonLoss();

  void Init(const Metadata& metadata, data_size_t num_data) override;

 protected:
  void LaunchGetGradientsKernel(const double* score, score_t* gradients, score_t* hessians) const override;

126
  const double* LaunchConvertOutputCUDAKernel(const data_size_t num_data, const double* input, double* output) const override;
127

128
129
  bool NeedConvertOutputCUDA() const override { return true; }

130
  double LaunchCalcInitScoreKernel(const int class_id) const override;
131

132
  void LaunchCheckLabelKernel() const;
133
134
135
};


136
137
}  // namespace LightGBM

138
#endif  // USE_CUDA
139
#endif  // LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_