Fix compiler warnings. (#8703)

Fix warnings about signed/unsigned comparisons.
This commit is contained in:
Jiaming Yuan 2023-01-21 15:16:23 +08:00 committed by GitHub
parent e49e0998c0
commit 34eee56256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*! /**
* Copyright by XGBoost Contributors 2017-2022 * Copyright 2017-2023 by XGBoost Contributors
*/ */
#include <dmlc/any.h> #include <dmlc/any.h>
#include <dmlc/omp.h> #include <dmlc/omp.h>
@ -326,13 +326,13 @@ class ColumnSplitHelper {
auto const n_trees = tree_end_ - tree_begin_; auto const n_trees = tree_end_ - tree_begin_;
tree_sizes_.resize(n_trees); tree_sizes_.resize(n_trees);
tree_offsets_.resize(n_trees); tree_offsets_.resize(n_trees);
for (auto i = 0; i < n_trees; i++) { for (decltype(tree_begin) i = 0; i < n_trees; i++) {
auto const &tree = *model_.trees[tree_begin_ + i]; auto const &tree = *model_.trees[tree_begin_ + i];
tree_sizes_[i] = tree.GetNodes().size(); tree_sizes_[i] = tree.GetNodes().size();
} }
// std::exclusive_scan (only available in c++17) equivalent to get tree offsets. // std::exclusive_scan (only available in c++17) equivalent to get tree offsets.
tree_offsets_[0] = 0; tree_offsets_[0] = 0;
for (auto i = 1; i < n_trees; i++) { for (decltype(tree_begin) i = 1; i < n_trees; i++) {
tree_offsets_[i] = tree_offsets_[i - 1] + tree_sizes_[i - 1]; tree_offsets_[i] = tree_offsets_[i - 1] + tree_sizes_[i - 1];
} }
bits_per_row_ = tree_offsets_.back() + tree_sizes_.back(); bits_per_row_ = tree_offsets_.back() + tree_sizes_.back();
@ -390,8 +390,9 @@ class ColumnSplitHelper {
auto const &tree = *model_.trees[tree_id]; auto const &tree = *model_.trees[tree_id];
auto const &cats = tree.GetCategoriesMatrix(); auto const &cats = tree.GetCategoriesMatrix();
auto const has_categorical = tree.HasCategoricalSplit(); auto const has_categorical = tree.HasCategoricalSplit();
bst_node_t n_nodes = tree.GetNodes().size();
for (auto nid = 0; nid < tree.GetNodes().size(); nid++) { for (bst_node_t nid = 0; nid < n_nodes; nid++) {
auto const &node = tree[nid]; auto const &node = tree[nid];
if (node.IsDeleted() || node.IsLeaf()) { if (node.IsDeleted() || node.IsLeaf()) {
continue; continue;
@ -539,7 +540,7 @@ class ColumnSplitHelper {
* The first two dimensions are fixed length, while the last dimension is variable length since * The first two dimensions are fixed length, while the last dimension is variable length since
* each tree may have a different number of nodes. We precompute the tree offsets, which are the * each tree may have a different number of nodes. We precompute the tree offsets, which are the
* cumulative sums of tree sizes. The index of tree t, row r, node n is: * cumulative sums of tree sizes. The index of tree t, row r, node n is:
* index(t, r, n) = tree_offsets[t] * n_rows + r * tree_sizes[t] + n * index(t, r, n) = tree_offsets[t] * n_rows + r * tree_sizes[t] + n
*/ */
std::vector<BitVector::value_type> decision_storage_{}; std::vector<BitVector::value_type> decision_storage_{};
BitVector decision_bits_{}; BitVector decision_bits_{};

View File

@ -1,9 +1,10 @@
/*! /**
* Copyright 2017-2022 XGBoost contributors * Copyright 2017-2023 by XGBoost contributors
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <xgboost/predictor.h> #include <xgboost/predictor.h>
#include <cstdint>
#include <thread> #include <thread>
#include "../../../src/collective/communicator-inl.h" #include "../../../src/collective/communicator-inl.h"
@ -95,7 +96,7 @@ TEST(CpuPredictor, ColumnSplit) {
auto dmat = RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix(); auto dmat = RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix();
std::vector<std::thread> threads; std::vector<std::thread> threads;
size_t constexpr kWorldSize = 2; std::int32_t constexpr kWorldSize = 2;
size_t constexpr kSliceSize = (kCols + 1) / kWorldSize; size_t constexpr kSliceSize = (kCols + 1) / kWorldSize;
for (auto rank = 0; rank < kWorldSize; rank++) { for (auto rank = 0; rank < kWorldSize; rank++) {
threads.emplace_back([=, &dmat]() { threads.emplace_back([=, &dmat]() {