GBTree::Predict performance fix: removed excess thread_temp initialization

This commit is contained in:
yoori 2015-10-20 00:52:37 +04:00
parent c0853967d5
commit 49c1cb6990

View File

@ -138,13 +138,7 @@ class GBTree : public IGradBooster {
{
nthread = omp_get_num_threads();
}
int prev_thread_temp_size = thread_temp.size();
if(prev_thread_temp_size < nthread) {
thread_temp.resize(nthread, tree::RegTree::FVec());
for (int i = prev_thread_temp_size; i < nthread; ++i) {
thread_temp[i].Init(mparam.num_feature);
}
}
InitThreadTemp(nthread);
std::vector<float> &preds = *out_preds;
const size_t stride = info.num_row * mparam.num_output_group;
preds.resize(stride * (mparam.size_leaf_vector+1));
@ -197,13 +191,7 @@ class GBTree : public IGradBooster {
{
nthread = omp_get_num_threads();
}
int prev_thread_temp_size = thread_temp.size();
if(prev_thread_temp_size < nthread) {
thread_temp.resize(nthread, tree::RegTree::FVec());
for (int i = prev_thread_temp_size; i < nthread; ++i) {
thread_temp[i].Init(mparam.num_feature);
}
}
InitThreadTemp(nthread);
this->PredPath(p_fmat, info, out_preds, ntree_limit);
}
virtual std::vector<std::string> DumpModel(const utils::FeatMap& fmap, int option) {
@ -397,6 +385,16 @@ class GBTree : public IGradBooster {
}
}
}
// init thread buffers
inline void InitThreadTemp(int nthread) {
int prev_thread_temp_size = thread_temp.size();
if(prev_thread_temp_size < nthread) {
thread_temp.resize(nthread, tree::RegTree::FVec());
for (int i = prev_thread_temp_size; i < nthread; ++i) {
thread_temp[i].Init(mparam.num_feature);
}
}
}
// --- data structure ---
/*! \brief training parameters */