Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
90127b52
Commit
90127b52
authored
Feb 02, 2019
by
Nikita Titov
Committed by
Guolin Ke
Feb 02, 2019
Browse files
cpplint whitespaces and new lines (#1986)
parent
6f548ada
Changes
79
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
108 additions
and
137 deletions
+108
-137
src/network/socket_wrapper.hpp
src/network/socket_wrapper.hpp
+3
-4
src/objective/binary_objective.hpp
src/objective/binary_objective.hpp
+5
-5
src/objective/multiclass_objective.hpp
src/objective/multiclass_objective.hpp
+2
-4
src/objective/objective_function.cpp
src/objective/objective_function.cpp
+1
-1
src/objective/rank_objective.hpp
src/objective/rank_objective.hpp
+0
-2
src/objective/regression_objective.hpp
src/objective/regression_objective.hpp
+6
-13
src/objective/xentropy_objective.hpp
src/objective/xentropy_objective.hpp
+3
-5
src/treelearner/data_parallel_tree_learner.cpp
src/treelearner/data_parallel_tree_learner.cpp
+0
-1
src/treelearner/data_partition.hpp
src/treelearner/data_partition.hpp
+0
-1
src/treelearner/feature_histogram.hpp
src/treelearner/feature_histogram.hpp
+8
-14
src/treelearner/feature_parallel_tree_learner.cpp
src/treelearner/feature_parallel_tree_learner.cpp
+0
-1
src/treelearner/gpu_tree_learner.cpp
src/treelearner/gpu_tree_learner.cpp
+54
-57
src/treelearner/gpu_tree_learner.h
src/treelearner/gpu_tree_learner.h
+11
-10
src/treelearner/leaf_splits.hpp
src/treelearner/leaf_splits.hpp
+1
-1
src/treelearner/parallel_tree_learner.h
src/treelearner/parallel_tree_learner.h
+3
-1
src/treelearner/serial_tree_learner.cpp
src/treelearner/serial_tree_learner.cpp
+9
-11
src/treelearner/serial_tree_learner.h
src/treelearner/serial_tree_learner.h
+1
-2
src/treelearner/split_info.hpp
src/treelearner/split_info.hpp
+0
-2
src/treelearner/voting_parallel_tree_learner.cpp
src/treelearner/voting_parallel_tree_learner.cpp
+1
-2
No files found.
src/network/socket_wrapper.hpp
View file @
90127b52
...
@@ -51,8 +51,7 @@ const int INVALID_SOCKET = -1;
...
@@ -51,8 +51,7 @@ const int INVALID_SOCKET = -1;
#ifdef _WIN32
#ifdef _WIN32
#ifndef _MSC_VER
#ifndef _MSC_VER
// not using visual studio in windows
// not using visual studio in windows
inline
int
inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
)
inline
int
inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
)
{
{
struct
sockaddr_storage
ss
;
struct
sockaddr_storage
ss
;
int
size
=
sizeof
(
ss
);
int
size
=
sizeof
(
ss
);
char
src_copy
[
INET6_ADDRSTRLEN
+
1
];
char
src_copy
[
INET6_ADDRSTRLEN
+
1
];
...
...
src/objective/binary_objective.hpp
View file @
90127b52
...
@@ -19,7 +19,7 @@ public:
...
@@ -19,7 +19,7 @@ public:
}
}
is_unbalance_
=
config
.
is_unbalance
;
is_unbalance_
=
config
.
is_unbalance
;
scale_pos_weight_
=
static_cast
<
double
>
(
config
.
scale_pos_weight
);
scale_pos_weight_
=
static_cast
<
double
>
(
config
.
scale_pos_weight
);
if
(
is_unbalance_
&&
std
::
fabs
(
scale_pos_weight_
-
1.0
f
)
>
1e-6
)
{
if
(
is_unbalance_
&&
std
::
fabs
(
scale_pos_weight_
-
1.0
f
)
>
1e-6
)
{
Log
::
Fatal
(
"Cannot set is_unbalance and scale_pos_weight at the same time"
);
Log
::
Fatal
(
"Cannot set is_unbalance and scale_pos_weight at the same time"
);
}
}
is_pos_
=
is_pos
;
is_pos_
=
is_pos
;
...
@@ -129,7 +129,7 @@ public:
...
@@ -129,7 +129,7 @@ public:
double
suml
=
0.0
f
;
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml,
sumw)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
is_pos_
(
label_
[
i
])
*
weights_
[
i
];
suml
+=
is_pos_
(
label_
[
i
])
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
sumw
+=
weights_
[
i
];
...
...
src/objective/multiclass_objective.hpp
View file @
90127b52
...
@@ -35,7 +35,6 @@ public:
...
@@ -35,7 +35,6 @@ public:
}
}
~
MulticlassSoftmax
()
{
~
MulticlassSoftmax
()
{
}
}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
...
@@ -197,7 +196,6 @@ public:
...
@@ -197,7 +196,6 @@ public:
}
}
~
MulticlassOVA
()
{
~
MulticlassOVA
()
{
}
}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
...
...
src/objective/objective_function.cpp
View file @
90127b52
src/objective/rank_objective.hpp
View file @
90127b52
...
@@ -34,11 +34,9 @@ public:
...
@@ -34,11 +34,9 @@ public:
}
}
explicit
LambdarankNDCG
(
const
std
::
vector
<
std
::
string
>&
)
{
explicit
LambdarankNDCG
(
const
std
::
vector
<
std
::
string
>&
)
{
}
}
~
LambdarankNDCG
()
{
~
LambdarankNDCG
()
{
}
}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
num_data_
=
num_data
;
num_data_
=
num_data
;
...
...
src/objective/regression_objective.hpp
View file @
90127b52
...
@@ -146,7 +146,7 @@ public:
...
@@ -146,7 +146,7 @@ public:
double
suml
=
0.0
f
;
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml,
sumw)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
]
*
weights_
[
i
];
suml
+=
label_
[
i
]
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
sumw
+=
weights_
[
i
];
...
@@ -362,7 +362,6 @@ public:
...
@@ -362,7 +362,6 @@ public:
}
}
explicit
RegressionFairLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL2loss
(
strs
)
{
explicit
RegressionFairLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL2loss
(
strs
)
{
}
}
~
RegressionFairLoss
()
{}
~
RegressionFairLoss
()
{}
...
@@ -414,7 +413,6 @@ public:
...
@@ -414,7 +413,6 @@ public:
}
}
explicit
RegressionPoissonLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL2loss
(
strs
)
{
explicit
RegressionPoissonLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL2loss
(
strs
)
{
}
}
~
RegressionPoissonLoss
()
{}
~
RegressionPoissonLoss
()
{}
...
@@ -492,7 +490,6 @@ public:
...
@@ -492,7 +490,6 @@ public:
}
}
explicit
RegressionQuantileloss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL2loss
(
strs
)
{
explicit
RegressionQuantileloss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL2loss
(
strs
)
{
}
}
~
RegressionQuantileloss
()
{}
~
RegressionQuantileloss
()
{}
...
@@ -620,7 +617,6 @@ public:
...
@@ -620,7 +617,6 @@ public:
}
}
explicit
RegressionMAPELOSS
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL1loss
(
strs
)
{
explicit
RegressionMAPELOSS
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionL1loss
(
strs
)
{
}
}
~
RegressionMAPELOSS
()
{}
~
RegressionMAPELOSS
()
{}
...
@@ -727,7 +723,6 @@ public:
...
@@ -727,7 +723,6 @@ public:
private:
private:
std
::
vector
<
label_t
>
label_weight_
;
std
::
vector
<
label_t
>
label_weight_
;
};
};
...
@@ -741,7 +736,6 @@ public:
...
@@ -741,7 +736,6 @@ public:
}
}
explicit
RegressionGammaLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionPoissonLoss
(
strs
)
{
explicit
RegressionGammaLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionPoissonLoss
(
strs
)
{
}
}
~
RegressionGammaLoss
()
{}
~
RegressionGammaLoss
()
{}
...
@@ -766,7 +760,6 @@ public:
...
@@ -766,7 +760,6 @@ public:
const
char
*
GetName
()
const
override
{
const
char
*
GetName
()
const
override
{
return
"gamma"
;
return
"gamma"
;
}
}
};
};
/*!
/*!
...
@@ -779,7 +772,6 @@ public:
...
@@ -779,7 +772,6 @@ public:
}
}
explicit
RegressionTweedieLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionPoissonLoss
(
strs
)
{
explicit
RegressionTweedieLoss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
RegressionPoissonLoss
(
strs
)
{
}
}
~
RegressionTweedieLoss
()
{}
~
RegressionTweedieLoss
()
{}
...
@@ -806,6 +798,7 @@ public:
...
@@ -806,6 +798,7 @@ public:
const
char
*
GetName
()
const
override
{
const
char
*
GetName
()
const
override
{
return
"tweedie"
;
return
"tweedie"
;
}
}
private:
private:
double
rho_
;
double
rho_
;
};
};
...
...
src/objective/xentropy_objective.hpp
View file @
90127b52
...
@@ -65,7 +65,6 @@ public:
...
@@ -65,7 +65,6 @@ public:
Log
::
Fatal
(
"[%s]: sum of weights is zero"
,
GetName
());
Log
::
Fatal
(
"[%s]: sum of weights is zero"
,
GetName
());
}
}
}
}
}
}
void
GetGradients
(
const
double
*
score
,
score_t
*
gradients
,
score_t
*
hessians
)
const
override
{
void
GetGradients
(
const
double
*
score
,
score_t
*
gradients
,
score_t
*
hessians
)
const
override
{
...
@@ -108,7 +107,7 @@ public:
...
@@ -108,7 +107,7 @@ public:
double
suml
=
0.0
f
;
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml,
sumw)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
]
*
weights_
[
i
];
suml
+=
label_
[
i
]
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
sumw
+=
weights_
[
i
];
...
@@ -161,7 +160,6 @@ public:
...
@@ -161,7 +160,6 @@ public:
Log
::
Info
(
"[%s:%s]: (objective) labels passed interval [0, 1] check"
,
GetName
(),
__func__
);
Log
::
Info
(
"[%s:%s]: (objective) labels passed interval [0, 1] check"
,
GetName
(),
__func__
);
if
(
weights_
!=
nullptr
)
{
if
(
weights_
!=
nullptr
)
{
Common
::
ObtainMinMaxSum
(
weights_
,
num_data_
,
&
min_weight_
,
&
max_weight_
,
(
label_t
*
)
nullptr
);
Common
::
ObtainMinMaxSum
(
weights_
,
num_data_
,
&
min_weight_
,
&
max_weight_
,
(
label_t
*
)
nullptr
);
if
(
min_weight_
<=
0.0
f
)
{
if
(
min_weight_
<=
0.0
f
)
{
Log
::
Fatal
(
"[%s]: at least one weight is non-positive"
,
GetName
());
Log
::
Fatal
(
"[%s]: at least one weight is non-positive"
,
GetName
());
...
@@ -235,7 +233,7 @@ public:
...
@@ -235,7 +233,7 @@ public:
double
suml
=
0.0
f
;
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml,
sumw)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
]
*
weights_
[
i
];
suml
+=
label_
[
i
]
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
sumw
+=
weights_
[
i
];
...
...
src/treelearner/data_parallel_tree_learner.cpp
View file @
90127b52
...
@@ -14,7 +14,6 @@ DataParallelTreeLearner<TREELEARNER_T>::DataParallelTreeLearner(const Config* co
...
@@ -14,7 +14,6 @@ DataParallelTreeLearner<TREELEARNER_T>::DataParallelTreeLearner(const Config* co
template
<
typename
TREELEARNER_T
>
template
<
typename
TREELEARNER_T
>
DataParallelTreeLearner
<
TREELEARNER_T
>::~
DataParallelTreeLearner
()
{
DataParallelTreeLearner
<
TREELEARNER_T
>::~
DataParallelTreeLearner
()
{
}
}
template
<
typename
TREELEARNER_T
>
template
<
typename
TREELEARNER_T
>
...
...
src/treelearner/data_partition.hpp
View file @
90127b52
...
@@ -48,7 +48,6 @@ public:
...
@@ -48,7 +48,6 @@ public:
temp_right_indices_
.
resize
(
num_data_
);
temp_right_indices_
.
resize
(
num_data_
);
}
}
~
DataPartition
()
{
~
DataPartition
()
{
}
}
/*!
/*!
...
...
src/treelearner/feature_histogram.hpp
View file @
90127b52
...
@@ -9,8 +9,7 @@
...
@@ -9,8 +9,7 @@
#include <cstring>
#include <cstring>
#include <cmath>
#include <cmath>
namespace
LightGBM
namespace
LightGBM
{
{
class
FeatureMetainfo
{
class
FeatureMetainfo
{
public:
public:
...
@@ -83,7 +82,6 @@ public:
...
@@ -83,7 +82,6 @@ public:
void
FindBestThresholdNumerical
(
double
sum_gradient
,
double
sum_hessian
,
data_size_t
num_data
,
double
min_constraint
,
double
max_constraint
,
void
FindBestThresholdNumerical
(
double
sum_gradient
,
double
sum_hessian
,
data_size_t
num_data
,
double
min_constraint
,
double
max_constraint
,
SplitInfo
*
output
)
{
SplitInfo
*
output
)
{
is_splittable_
=
false
;
is_splittable_
=
false
;
double
gain_shift
=
GetLeafSplitGain
(
sum_gradient
,
sum_hessian
,
double
gain_shift
=
GetLeafSplitGain
(
sum_gradient
,
sum_hessian
,
meta_
->
config
->
lambda_l1
,
meta_
->
config
->
lambda_l2
,
meta_
->
config
->
max_delta_step
);
meta_
->
config
->
lambda_l1
,
meta_
->
config
->
lambda_l2
,
meta_
->
config
->
max_delta_step
);
...
@@ -336,7 +334,7 @@ public:
...
@@ -336,7 +334,7 @@ public:
output
->
gain
=
kMinScore
;
output
->
gain
=
kMinScore
;
Log
::
Warning
(
"'Forced Split' will be ignored since the gain getting worse. "
);
Log
::
Warning
(
"'Forced Split' will be ignored since the gain getting worse. "
);
return
;
return
;
}
;
}
// update split information
// update split information
output
->
threshold
=
threshold
;
output
->
threshold
=
threshold
;
...
@@ -452,7 +450,6 @@ public:
...
@@ -452,7 +450,6 @@ public:
}
}
private:
private:
static
double
GetSplitGains
(
double
sum_left_gradients
,
double
sum_left_hessians
,
static
double
GetSplitGains
(
double
sum_left_gradients
,
double
sum_left_hessians
,
double
sum_right_gradients
,
double
sum_right_hessians
,
double
sum_right_gradients
,
double
sum_right_hessians
,
double
l1
,
double
l2
,
double
max_delta_step
,
double
l1
,
double
l2
,
double
max_delta_step
,
...
@@ -502,7 +499,6 @@ private:
...
@@ -502,7 +499,6 @@ private:
void
FindBestThresholdSequence
(
double
sum_gradient
,
double
sum_hessian
,
data_size_t
num_data
,
double
min_constraint
,
double
max_constraint
,
void
FindBestThresholdSequence
(
double
sum_gradient
,
double
sum_hessian
,
data_size_t
num_data
,
double
min_constraint
,
double
max_constraint
,
double
min_gain_shift
,
SplitInfo
*
output
,
int
dir
,
bool
skip_default_bin
,
bool
use_na_as_missing
)
{
double
min_gain_shift
,
SplitInfo
*
output
,
int
dir
,
bool
skip_default_bin
,
bool
use_na_as_missing
)
{
const
int8_t
bias
=
meta_
->
bias
;
const
int8_t
bias
=
meta_
->
bias
;
double
best_sum_left_gradient
=
NAN
;
double
best_sum_left_gradient
=
NAN
;
...
@@ -512,7 +508,6 @@ private:
...
@@ -512,7 +508,6 @@ private:
uint32_t
best_threshold
=
static_cast
<
uint32_t
>
(
meta_
->
num_bin
);
uint32_t
best_threshold
=
static_cast
<
uint32_t
>
(
meta_
->
num_bin
);
if
(
dir
==
-
1
)
{
if
(
dir
==
-
1
)
{
double
sum_right_gradient
=
0.0
f
;
double
sum_right_gradient
=
0.0
f
;
double
sum_right_hessian
=
kEpsilon
;
double
sum_right_hessian
=
kEpsilon
;
data_size_t
right_count
=
0
;
data_size_t
right_count
=
0
;
...
@@ -522,7 +517,6 @@ private:
...
@@ -522,7 +517,6 @@ private:
// from right to left, and we don't need data in bin0
// from right to left, and we don't need data in bin0
for
(;
t
>=
t_end
;
--
t
)
{
for
(;
t
>=
t_end
;
--
t
)
{
// need to skip default bin
// need to skip default bin
if
(
skip_default_bin
&&
(
t
+
bias
)
==
static_cast
<
int
>
(
meta_
->
default_bin
))
{
continue
;
}
if
(
skip_default_bin
&&
(
t
+
bias
)
==
static_cast
<
int
>
(
meta_
->
default_bin
))
{
continue
;
}
...
@@ -581,7 +575,6 @@ private:
...
@@ -581,7 +575,6 @@ private:
}
}
for
(;
t
<=
t_end
;
++
t
)
{
for
(;
t
<=
t_end
;
++
t
)
{
// need to skip default bin
// need to skip default bin
if
(
skip_default_bin
&&
(
t
+
bias
)
==
static_cast
<
int
>
(
meta_
->
default_bin
))
{
continue
;
}
if
(
skip_default_bin
&&
(
t
+
bias
)
==
static_cast
<
int
>
(
meta_
->
default_bin
))
{
continue
;
}
if
(
t
>=
0
)
{
if
(
t
>=
0
)
{
...
@@ -645,7 +638,7 @@ private:
...
@@ -645,7 +638,7 @@ private:
const
FeatureMetainfo
*
meta_
;
const
FeatureMetainfo
*
meta_
;
/*! \brief sum of gradient of each bin */
/*! \brief sum of gradient of each bin */
HistogramBinEntry
*
data_
;
HistogramBinEntry
*
data_
;
//std::vector<HistogramBinEntry> data_;
//
std::vector<HistogramBinEntry> data_;
bool
is_splittable_
=
true
;
bool
is_splittable_
=
true
;
std
::
function
<
void
(
double
,
double
,
data_size_t
,
double
,
double
,
SplitInfo
*
)
>
find_best_threshold_fun_
;
std
::
function
<
void
(
double
,
double
,
data_size_t
,
double
,
double
,
SplitInfo
*
)
>
find_best_threshold_fun_
;
...
@@ -701,7 +694,7 @@ public:
...
@@ -701,7 +694,7 @@ public:
if
(
feature_metas_
.
empty
())
{
if
(
feature_metas_
.
empty
())
{
int
num_feature
=
train_data
->
num_features
();
int
num_feature
=
train_data
->
num_features
();
feature_metas_
.
resize
(
num_feature
);
feature_metas_
.
resize
(
num_feature
);
#pragma omp parallel for schedule(static, 512) if(num_feature >= 1024)
#pragma omp parallel for schedule(static, 512) if
(num_feature >= 1024)
for
(
int
i
=
0
;
i
<
num_feature
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_feature
;
++
i
)
{
feature_metas_
[
i
].
num_bin
=
train_data
->
FeatureNumBin
(
i
);
feature_metas_
[
i
].
num_bin
=
train_data
->
FeatureNumBin
(
i
);
feature_metas_
[
i
].
default_bin
=
train_data
->
FeatureBinMapper
(
i
)
->
GetDefaultBin
();
feature_metas_
[
i
].
default_bin
=
train_data
->
FeatureBinMapper
(
i
)
->
GetDefaultBin
();
...
@@ -751,7 +744,7 @@ public:
...
@@ -751,7 +744,7 @@ public:
void
ResetConfig
(
const
Config
*
config
)
{
void
ResetConfig
(
const
Config
*
config
)
{
int
size
=
static_cast
<
int
>
(
feature_metas_
.
size
());
int
size
=
static_cast
<
int
>
(
feature_metas_
.
size
());
#pragma omp parallel for schedule(static, 512) if(size >= 1024)
#pragma omp parallel for schedule(static, 512) if
(size >= 1024)
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
feature_metas_
[
i
].
config
=
config
;
feature_metas_
[
i
].
config
=
config
;
}
}
...
@@ -810,6 +803,7 @@ public:
...
@@ -810,6 +803,7 @@ public:
last_used_time_
[
slot
]
=
++
cur_time_
;
last_used_time_
[
slot
]
=
++
cur_time_
;
inverse_mapper_
[
slot
]
=
dst_idx
;
inverse_mapper_
[
slot
]
=
dst_idx
;
}
}
private:
private:
std
::
vector
<
std
::
unique_ptr
<
FeatureHistogram
[]
>>
pool_
;
std
::
vector
<
std
::
unique_ptr
<
FeatureHistogram
[]
>>
pool_
;
std
::
vector
<
std
::
vector
<
HistogramBinEntry
>>
data_
;
std
::
vector
<
std
::
vector
<
HistogramBinEntry
>>
data_
;
...
...
src/treelearner/feature_parallel_tree_learner.cpp
View file @
90127b52
...
@@ -14,7 +14,6 @@ FeatureParallelTreeLearner<TREELEARNER_T>::FeatureParallelTreeLearner(const Conf
...
@@ -14,7 +14,6 @@ FeatureParallelTreeLearner<TREELEARNER_T>::FeatureParallelTreeLearner(const Conf
template
<
typename
TREELEARNER_T
>
template
<
typename
TREELEARNER_T
>
FeatureParallelTreeLearner
<
TREELEARNER_T
>::~
FeatureParallelTreeLearner
()
{
FeatureParallelTreeLearner
<
TREELEARNER_T
>::~
FeatureParallelTreeLearner
()
{
}
}
template
<
typename
TREELEARNER_T
>
template
<
typename
TREELEARNER_T
>
...
...
src/treelearner/gpu_tree_learner.cpp
View file @
90127b52
...
@@ -56,8 +56,7 @@ void PrintHistograms(HistogramBinEntry* h, size_t size) {
...
@@ -56,8 +56,7 @@ void PrintHistograms(HistogramBinEntry* h, size_t size) {
printf
(
"
\n
Total examples: %lu
\n
"
,
total
);
printf
(
"
\n
Total examples: %lu
\n
"
,
total
);
}
}
union
Float_t
union
Float_t
{
{
int64_t
i
;
int64_t
i
;
double
f
;
double
f
;
static
int64_t
ulp_diff
(
Float_t
a
,
Float_t
b
)
{
static
int64_t
ulp_diff
(
Float_t
a
,
Float_t
b
)
{
...
@@ -196,7 +195,7 @@ void GPUTreeLearner::WaitAndGetHistograms(HistogramBinEntry* histograms) {
...
@@ -196,7 +195,7 @@ void GPUTreeLearner::WaitAndGetHistograms(HistogramBinEntry* histograms) {
// when the output is ready, the computation is done
// when the output is ready, the computation is done
histograms_wait_obj_
.
wait
();
histograms_wait_obj_
.
wait
();
#pragma omp parallel for schedule(static)
#pragma omp parallel for schedule(static)
for
(
int
i
=
0
;
i
<
num_dense_feature_groups_
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_dense_feature_groups_
;
++
i
)
{
if
(
!
feature_masks_
[
i
])
{
if
(
!
feature_masks_
[
i
])
{
continue
;
continue
;
}
}
...
@@ -596,7 +595,7 @@ void GPUTreeLearner::BuildGPUKernels() {
...
@@ -596,7 +595,7 @@ void GPUTreeLearner::BuildGPUKernels() {
OMP_LOOP_EX_BEGIN
();
OMP_LOOP_EX_BEGIN
();
boost
::
compute
::
program
program
;
boost
::
compute
::
program
program
;
std
::
ostringstream
opts
;
std
::
ostringstream
opts
;
// compile the GPU kernel depending if double precision is used, constant hessian is used, etc
// compile the GPU kernel depending if double precision is used, constant hessian is used, etc
.
opts
<<
" -D POWER_FEATURE_WORKGROUPS="
<<
i
opts
<<
" -D POWER_FEATURE_WORKGROUPS="
<<
i
<<
" -D USE_CONSTANT_BUF="
<<
use_constants
<<
" -D USE_DP_FLOAT="
<<
int
(
config_
->
gpu_use_dp
)
<<
" -D USE_CONSTANT_BUF="
<<
use_constants
<<
" -D USE_DP_FLOAT="
<<
int
(
config_
->
gpu_use_dp
)
<<
" -D CONST_HESSIAN="
<<
int
(
is_constant_hessian_
)
<<
" -D CONST_HESSIAN="
<<
int
(
is_constant_hessian_
)
...
@@ -727,7 +726,7 @@ void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
...
@@ -727,7 +726,7 @@ void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
device_bin_size_
=
64
;
device_bin_size_
=
64
;
dword_features_
=
4
;
dword_features_
=
4
;
}
}
else
if
(
max_num_bin_
<=
256
)
{
else
if
(
max_num_bin_
<=
256
)
{
kernel_source_
=
kernel256_src_
;
kernel_source_
=
kernel256_src_
;
kernel_name_
=
"histogram256"
;
kernel_name_
=
"histogram256"
;
device_bin_size_
=
256
;
device_bin_size_
=
256
;
...
@@ -736,10 +735,10 @@ void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
...
@@ -736,10 +735,10 @@ void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
else
{
else
{
Log
::
Fatal
(
"bin size %d cannot run on GPU"
,
max_num_bin_
);
Log
::
Fatal
(
"bin size %d cannot run on GPU"
,
max_num_bin_
);
}
}
if
(
max_num_bin_
==
65
)
{
if
(
max_num_bin_
==
65
)
{
Log
::
Warning
(
"Setting max_bin to 63 is sugguested for best performance"
);
Log
::
Warning
(
"Setting max_bin to 63 is sugguested for best performance"
);
}
}
if
(
max_num_bin_
==
17
)
{
if
(
max_num_bin_
==
17
)
{
Log
::
Warning
(
"Setting max_bin to 15 is sugguested for best performance"
);
Log
::
Warning
(
"Setting max_bin to 15 is sugguested for best performance"
);
}
}
ctx_
=
boost
::
compute
::
context
(
dev_
);
ctx_
=
boost
::
compute
::
context
(
dev_
);
...
@@ -774,7 +773,6 @@ void GPUTreeLearner::ResetTrainingData(const Dataset* train_data) {
...
@@ -774,7 +773,6 @@ void GPUTreeLearner::ResetTrainingData(const Dataset* train_data) {
}
}
void
GPUTreeLearner
::
BeforeTrain
()
{
void
GPUTreeLearner
::
BeforeTrain
()
{
#if GPU_DEBUG >= 2
#if GPU_DEBUG >= 2
printf
(
"Copying intial full gradients and hessians to device
\n
"
);
printf
(
"Copying intial full gradients and hessians to device
\n
"
);
#endif
#endif
...
@@ -861,7 +859,7 @@ bool GPUTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int ri
...
@@ -861,7 +859,7 @@ bool GPUTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int ri
// copy indices to the GPU:
// copy indices to the GPU:
#if GPU_DEBUG >= 2
#if GPU_DEBUG >= 2
Log
::
Info
(
"Copying indices, gradients and hessians to GPU..."
);
Log
::
Info
(
"Copying indices, gradients and hessians to GPU..."
);
printf
(
"Indices size %d being copied (left = %d, right = %d)
\n
"
,
end
-
begin
,
num_data_in_left_child
,
num_data_in_right_child
);
printf
(
"Indices size %d being copied (left = %d, right = %d)
\n
"
,
end
-
begin
,
num_data_in_left_child
,
num_data_in_right_child
);
#endif
#endif
indices_future_
=
boost
::
compute
::
copy_async
(
indices
+
begin
,
indices
+
end
,
device_data_indices_
->
begin
(),
queue_
);
indices_future_
=
boost
::
compute
::
copy_async
(
indices
+
begin
,
indices
+
end
,
device_data_indices_
->
begin
(),
queue_
);
...
@@ -893,7 +891,6 @@ bool GPUTreeLearner::ConstructGPUHistogramsAsync(
...
@@ -893,7 +891,6 @@ bool GPUTreeLearner::ConstructGPUHistogramsAsync(
const
data_size_t
*
data_indices
,
data_size_t
num_data
,
const
data_size_t
*
data_indices
,
data_size_t
num_data
,
const
score_t
*
gradients
,
const
score_t
*
hessians
,
const
score_t
*
gradients
,
const
score_t
*
hessians
,
score_t
*
ordered_gradients
,
score_t
*
ordered_hessians
)
{
score_t
*
ordered_gradients
,
score_t
*
ordered_hessians
)
{
if
(
num_data
<=
0
)
{
if
(
num_data
<=
0
)
{
return
false
;
return
false
;
}
}
...
@@ -934,15 +931,15 @@ bool GPUTreeLearner::ConstructGPUHistogramsAsync(
...
@@ -934,15 +931,15 @@ bool GPUTreeLearner::ConstructGPUHistogramsAsync(
}
}
// converted indices in is_feature_used to feature-group indices
// converted indices in is_feature_used to feature-group indices
std
::
vector
<
int8_t
>
is_feature_group_used
(
num_feature_groups_
,
0
);
std
::
vector
<
int8_t
>
is_feature_group_used
(
num_feature_groups_
,
0
);
#pragma omp parallel for schedule(static,1024) if (num_features_ >= 2048)
#pragma omp parallel for schedule(static,
1024) if (num_features_ >= 2048)
for
(
int
i
=
0
;
i
<
num_features_
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_features_
;
++
i
)
{
if
(
is_feature_used
[
i
])
{
if
(
is_feature_used
[
i
])
{
is_feature_group_used
[
train_data_
->
Feature2Group
(
i
)]
=
1
;
is_feature_group_used
[
train_data_
->
Feature2Group
(
i
)]
=
1
;
}
}
}
}
// construct the feature masks for dense feature-groups
// construct the feature masks for dense feature-groups
int
used_dense_feature_groups
=
0
;
int
used_dense_feature_groups
=
0
;
#pragma omp parallel for schedule(static,1024) reduction(+:used_dense_feature_groups) if (num_dense_feature_groups_ >= 2048)
#pragma omp parallel for schedule(static,
1024) reduction(+:used_dense_feature_groups) if (num_dense_feature_groups_ >= 2048)
for
(
int
i
=
0
;
i
<
num_dense_feature_groups_
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_dense_feature_groups_
;
++
i
)
{
if
(
is_feature_group_used
[
dense_feature_group_map_
[
i
]])
{
if
(
is_feature_group_used
[
dense_feature_group_map_
[
i
]])
{
feature_masks_
[
i
]
=
1
;
feature_masks_
[
i
]
=
1
;
...
...
src/treelearner/gpu_tree_learner.h
View file @
90127b52
...
@@ -63,6 +63,7 @@ protected:
...
@@ -63,6 +63,7 @@ protected:
void
FindBestSplits
()
override
;
void
FindBestSplits
()
override
;
void
Split
(
Tree
*
tree
,
int
best_Leaf
,
int
*
left_leaf
,
int
*
right_leaf
)
override
;
void
Split
(
Tree
*
tree
,
int
best_Leaf
,
int
*
left_leaf
,
int
*
right_leaf
)
override
;
void
ConstructHistograms
(
const
std
::
vector
<
int8_t
>&
is_feature_used
,
bool
use_subtract
)
override
;
void
ConstructHistograms
(
const
std
::
vector
<
int8_t
>&
is_feature_used
,
bool
use_subtract
)
override
;
private:
private:
/*! \brief 4-byte feature tuple used by GPU kernels */
/*! \brief 4-byte feature tuple used by GPU kernels */
struct
Feature4
{
struct
Feature4
{
...
@@ -276,7 +277,7 @@ public:
...
@@ -276,7 +277,7 @@ public:
}
}
};
};
}
}
// namespace LightGBM
#endif // USE_GPU
#endif // USE_GPU
...
...
src/treelearner/leaf_splits.hpp
View file @
90127b52
src/treelearner/parallel_tree_learner.h
View file @
90127b52
...
@@ -51,6 +51,7 @@ public:
...
@@ -51,6 +51,7 @@ public:
~
DataParallelTreeLearner
();
~
DataParallelTreeLearner
();
void
Init
(
const
Dataset
*
train_data
,
bool
is_constant_hessian
)
override
;
void
Init
(
const
Dataset
*
train_data
,
bool
is_constant_hessian
)
override
;
void
ResetConfig
(
const
Config
*
config
)
override
;
void
ResetConfig
(
const
Config
*
config
)
override
;
protected:
protected:
void
BeforeTrain
()
override
;
void
BeforeTrain
()
override
;
void
FindBestSplits
()
override
;
void
FindBestSplits
()
override
;
...
@@ -104,6 +105,7 @@ public:
...
@@ -104,6 +105,7 @@ public:
~
VotingParallelTreeLearner
()
{
}
~
VotingParallelTreeLearner
()
{
}
void
Init
(
const
Dataset
*
train_data
,
bool
is_constant_hessian
)
override
;
void
Init
(
const
Dataset
*
train_data
,
bool
is_constant_hessian
)
override
;
void
ResetConfig
(
const
Config
*
config
)
override
;
void
ResetConfig
(
const
Config
*
config
)
override
;
protected:
protected:
void
BeforeTrain
()
override
;
void
BeforeTrain
()
override
;
bool
BeforeFindBestSplit
(
const
Tree
*
tree
,
int
left_leaf
,
int
right_leaf
)
override
;
bool
BeforeFindBestSplit
(
const
Tree
*
tree
,
int
left_leaf
,
int
right_leaf
)
override
;
...
...
src/treelearner/serial_tree_learner.cpp
View file @
90127b52
...
@@ -253,7 +253,6 @@ Tree* SerialTreeLearner::FitByExistingTree(const Tree* old_tree, const std::vect
...
@@ -253,7 +253,6 @@ Tree* SerialTreeLearner::FitByExistingTree(const Tree* old_tree, const std::vect
}
}
void
SerialTreeLearner
::
BeforeTrain
()
{
void
SerialTreeLearner
::
BeforeTrain
()
{
// reset histogram pool
// reset histogram pool
histogram_pool_
.
ResetMap
();
histogram_pool_
.
ResetMap
();
...
@@ -322,7 +321,7 @@ void SerialTreeLearner::BeforeTrain() {
...
@@ -322,7 +321,7 @@ void SerialTreeLearner::BeforeTrain() {
const
data_size_t
*
indices
=
data_partition_
->
indices
();
const
data_size_t
*
indices
=
data_partition_
->
indices
();
data_size_t
begin
=
data_partition_
->
leaf_begin
(
0
);
data_size_t
begin
=
data_partition_
->
leaf_begin
(
0
);
data_size_t
end
=
begin
+
data_partition_
->
leaf_count
(
0
);
data_size_t
end
=
begin
+
data_partition_
->
leaf_count
(
0
);
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if
(end - begin >= 1024)
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
is_data_in_leaf_
[
indices
[
i
]]
=
1
;
is_data_in_leaf_
[
indices
[
i
]]
=
1
;
}
}
...
@@ -335,7 +334,7 @@ void SerialTreeLearner::BeforeTrain() {
...
@@ -335,7 +334,7 @@ void SerialTreeLearner::BeforeTrain() {
OMP_LOOP_EX_END
();
OMP_LOOP_EX_END
();
}
}
OMP_THROW_EX
();
OMP_THROW_EX
();
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if
(end - begin >= 1024)
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
is_data_in_leaf_
[
indices
[
i
]]
=
0
;
is_data_in_leaf_
[
indices
[
i
]]
=
0
;
}
}
...
@@ -401,7 +400,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
...
@@ -401,7 +400,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
end
=
begin
+
right_cnt
;
end
=
begin
+
right_cnt
;
mark
=
0
;
mark
=
0
;
}
}
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if
(end - begin >= 1024)
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
is_data_in_leaf_
[
indices
[
i
]]
=
1
;
is_data_in_leaf_
[
indices
[
i
]]
=
1
;
}
}
...
@@ -414,7 +413,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
...
@@ -414,7 +413,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
OMP_LOOP_EX_END
();
OMP_LOOP_EX_END
();
}
}
OMP_THROW_EX
();
OMP_THROW_EX
();
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if
(end - begin >= 1024)
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
for
(
data_size_t
i
=
begin
;
i
<
end
;
++
i
)
{
is_data_in_leaf_
[
indices
[
i
]]
=
0
;
is_data_in_leaf_
[
indices
[
i
]]
=
0
;
}
}
...
@@ -427,7 +426,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
...
@@ -427,7 +426,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
void
SerialTreeLearner
::
FindBestSplits
()
{
void
SerialTreeLearner
::
FindBestSplits
()
{
std
::
vector
<
int8_t
>
is_feature_used
(
num_features_
,
0
);
std
::
vector
<
int8_t
>
is_feature_used
(
num_features_
,
0
);
#pragma omp parallel for schedule(static,1024) if (num_features_ >= 2048)
#pragma omp parallel for schedule(static,
1024) if (num_features_ >= 2048)
for
(
int
feature_index
=
0
;
feature_index
<
num_features_
;
++
feature_index
)
{
for
(
int
feature_index
=
0
;
feature_index
<
num_features_
;
++
feature_index
)
{
if
(
!
is_feature_used_
[
feature_index
])
continue
;
if
(
!
is_feature_used_
[
feature_index
])
continue
;
if
(
parent_leaf_histogram_array_
!=
nullptr
if
(
parent_leaf_histogram_array_
!=
nullptr
...
@@ -553,8 +552,7 @@ int32_t SerialTreeLearner::ForceSplits(Tree* tree, Json& forced_split_json, int*
...
@@ -553,8 +552,7 @@ int32_t SerialTreeLearner::ForceSplits(Tree* tree, Json& forced_split_json, int*
bool
left_smaller
=
true
;
bool
left_smaller
=
true
;
std
::
unordered_map
<
int
,
SplitInfo
>
forceSplitMap
;
std
::
unordered_map
<
int
,
SplitInfo
>
forceSplitMap
;
q
.
push
(
std
::
make_pair
(
forced_split_json
,
*
left_leaf
));
q
.
push
(
std
::
make_pair
(
forced_split_json
,
*
left_leaf
));
while
(
!
q
.
empty
())
{
while
(
!
q
.
empty
())
{
// before processing next node from queue, store info for current left/right leaf
// before processing next node from queue, store info for current left/right leaf
// store "best split" for left and right, even if they might be overwritten by forced split
// store "best split" for left and right, even if they might be overwritten by forced split
if
(
BeforeFindBestSplit
(
tree
,
*
left_leaf
,
*
right_leaf
))
{
if
(
BeforeFindBestSplit
(
tree
,
*
left_leaf
,
*
right_leaf
))
{
...
...
src/treelearner/serial_tree_learner.h
View file @
90127b52
...
@@ -106,7 +106,6 @@ protected:
...
@@ -106,7 +106,6 @@ protected:
int
*
right_leaf
,
int
*
cur_depth
,
int
*
right_leaf
,
int
*
cur_depth
,
bool
*
aborted_last_force_split
);
bool
*
aborted_last_force_split
);
/*!
/*!
* \brief Get the number of data in a leaf
* \brief Get the number of data in a leaf
* \param leaf_idx The index of leaf
* \param leaf_idx The index of leaf
...
...
src/treelearner/split_info.hpp
View file @
90127b52
...
@@ -185,7 +185,6 @@ public:
...
@@ -185,7 +185,6 @@ public:
return
local_feature
==
other_feature
;
return
local_feature
==
other_feature
;
}
}
}
}
};
};
struct
LightSplitInfo
{
struct
LightSplitInfo
{
...
@@ -280,7 +279,6 @@ public:
...
@@ -280,7 +279,6 @@ public:
return
local_feature
==
other_feature
;
return
local_feature
==
other_feature
;
}
}
}
}
};
};
}
// namespace LightGBM
}
// namespace LightGBM
...
...
src/treelearner/voting_parallel_tree_learner.cpp
View file @
90127b52
...
@@ -370,7 +370,6 @@ void VotingParallelTreeLearner<TREELEARNER_T>::FindBestSplits() {
...
@@ -370,7 +370,6 @@ void VotingParallelTreeLearner<TREELEARNER_T>::FindBestSplits() {
template
<
typename
TREELEARNER_T
>
template
<
typename
TREELEARNER_T
>
void
VotingParallelTreeLearner
<
TREELEARNER_T
>::
FindBestSplitsFromHistograms
(
const
std
::
vector
<
int8_t
>&
,
bool
)
{
void
VotingParallelTreeLearner
<
TREELEARNER_T
>::
FindBestSplitsFromHistograms
(
const
std
::
vector
<
int8_t
>&
,
bool
)
{
std
::
vector
<
SplitInfo
>
smaller_bests_per_thread
(
this
->
num_threads_
);
std
::
vector
<
SplitInfo
>
smaller_bests_per_thread
(
this
->
num_threads_
);
std
::
vector
<
SplitInfo
>
larger_best_per_thread
(
this
->
num_threads_
);
std
::
vector
<
SplitInfo
>
larger_best_per_thread
(
this
->
num_threads_
);
// find best split from local aggregated histograms
// find best split from local aggregated histograms
...
@@ -506,4 +505,4 @@ void VotingParallelTreeLearner<TREELEARNER_T>::Split(Tree* tree, int best_Leaf,
...
@@ -506,4 +505,4 @@ void VotingParallelTreeLearner<TREELEARNER_T>::Split(Tree* tree, int best_Leaf,
// instantiate template classes, otherwise linker cannot find the code
// instantiate template classes, otherwise linker cannot find the code
template
class
VotingParallelTreeLearner
<
GPUTreeLearner
>;
template
class
VotingParallelTreeLearner
<
GPUTreeLearner
>;
template
class
VotingParallelTreeLearner
<
SerialTreeLearner
>;
template
class
VotingParallelTreeLearner
<
SerialTreeLearner
>;
}
// namespace
FTLBoost
}
// namespace
LightGBM
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment