[backport] Limit max_depth to 30 for GPU. (#8098) (#8169)

This commit is contained in:
Jiaming Yuan 2022-08-15 15:16:58 +08:00 committed by GitHub
parent 0e2b5c467e
commit 2e6444b342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,12 +211,13 @@ struct TrainParam : public XGBoostParameter<TrainParam> {
n_nodes = this->max_leaves * 2 - 1; n_nodes = this->max_leaves * 2 - 1;
} else { } else {
// bst_node_t will overflow. // bst_node_t will overflow.
CHECK_LE(this->max_depth, 31) CHECK_LE(this->max_depth, 30)
<< "max_depth can not be greater than 31 as that might generate 2 ** " << "max_depth can not be greater than 30 as that might generate 2^31 - 1"
"32 - 1 nodes."; "nodes.";
n_nodes = (1 << (this->max_depth + 1)) - 1; // 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; return n_nodes;
} }
}; };