From 5156be0f49238476511adfe541e643e65b4a897f Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Wed, 20 Jul 2022 12:28:49 +0800 Subject: [PATCH] Limit `max_depth` to 30 for GPU. (#8098) --- src/tree/param.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tree/param.h b/src/tree/param.h index c94437732..27ccb4ac9 100644 --- a/src/tree/param.h +++ b/src/tree/param.h @@ -207,12 +207,13 @@ struct TrainParam : public XGBoostParameter { n_nodes = this->max_leaves * 2 - 1; } else { // bst_node_t will overflow. - CHECK_LE(this->max_depth, 31) - << "max_depth can not be greater than 31 as that might generate 2 ** " - "32 - 1 nodes."; - n_nodes = (1 << (this->max_depth + 1)) - 1; + CHECK_LE(this->max_depth, 30) + << "max_depth can not be greater than 30 as that might generate 2^31 - 1" + "nodes."; + // same as: (1 << (max_depth + 1)) - 1, but avoids 1 << 31, which overflows. + n_nodes = (1 << this->max_depth) + ((1 << this->max_depth) - 1); } - CHECK_NE(n_nodes, 0); + CHECK_GT(n_nodes, 0); return n_nodes; } };