From c0853967d5cb04bbf8e6ceebe7db32d01725cb5f Mon Sep 17 00:00:00 2001 From: yoori Date: Tue, 20 Oct 2015 00:06:00 +0400 Subject: [PATCH 1/3] GBTree::Predict performance fix: removed excess thread_temp initialization --- src/gbm/gbtree-inl.hpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/gbm/gbtree-inl.hpp b/src/gbm/gbtree-inl.hpp index 9335ef8e7..d6bbcc6d1 100644 --- a/src/gbm/gbtree-inl.hpp +++ b/src/gbm/gbtree-inl.hpp @@ -138,9 +138,12 @@ class GBTree : public IGradBooster { { nthread = omp_get_num_threads(); } - thread_temp.resize(nthread, tree::RegTree::FVec()); - for (int i = 0; i < nthread; ++i) { - thread_temp[i].Init(mparam.num_feature); + 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); + } } std::vector &preds = *out_preds; const size_t stride = info.num_row * mparam.num_output_group; @@ -194,9 +197,12 @@ class GBTree : public IGradBooster { { nthread = omp_get_num_threads(); } - thread_temp.resize(nthread, tree::RegTree::FVec()); - for (int i = 0; i < nthread; ++i) { - thread_temp[i].Init(mparam.num_feature); + 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); + } } this->PredPath(p_fmat, info, out_preds, ntree_limit); } From 49c1cb6990058daa7ee23e107bfff926a9d58ca3 Mon Sep 17 00:00:00 2001 From: yoori Date: Tue, 20 Oct 2015 00:52:37 +0400 Subject: [PATCH 2/3] GBTree::Predict performance fix: removed excess thread_temp initialization --- src/gbm/gbtree-inl.hpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/gbm/gbtree-inl.hpp b/src/gbm/gbtree-inl.hpp index d6bbcc6d1..f2d3001f4 100644 --- a/src/gbm/gbtree-inl.hpp +++ b/src/gbm/gbtree-inl.hpp @@ -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 &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 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 */ From 981f06b9d157799b4658590fe10a1e3b378b7362 Mon Sep 17 00:00:00 2001 From: yoori Date: Tue, 20 Oct 2015 00:58:11 +0400 Subject: [PATCH 3/3] style fix --- src/gbm/gbtree-inl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gbm/gbtree-inl.hpp b/src/gbm/gbtree-inl.hpp index f2d3001f4..c06dc51a1 100644 --- a/src/gbm/gbtree-inl.hpp +++ b/src/gbm/gbtree-inl.hpp @@ -388,7 +388,7 @@ 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) { + 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);