Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ranking utils to threading utils. #8785

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/common/ranking_utils.cuh → src/common/threading_utils.cuh
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
/*!
* Copyright 2021 by XGBoost Contributors
/**
* Copyright 2021-2023 by XGBoost Contributors
*/
#ifndef XGBOOST_COMMON_RANKING_UTILS_H_
#define XGBOOST_COMMON_RANKING_UTILS_H_
#ifndef XGBOOST_COMMON_THREADING_UTILS_CUH_
#define XGBOOST_COMMON_THREADING_UTILS_CUH_

#include <algorithm> // std::min
#include <cstddef> // std::size_t

#include <cub/cub.cuh>
#include "xgboost/base.h"
#include "device_helpers.cuh"
#include "./math.h"
#include "./math.h" // Sqr
#include "common.h"
#include "device_helpers.cuh" // LaunchN
#include "xgboost/base.h" // XGBOOST_DEVICE
#include "xgboost/span.h" // Span

namespace xgboost {
namespace common {
/**
* \param n Number of items (length of the base)
* \param h hight
*/
XGBOOST_DEVICE inline size_t DiscreteTrapezoidArea(size_t n, size_t h) {
n -= 1; // without diagonal entries
h = std::min(n, h); // Specific for ranking.
size_t total = ((n - (h - 1)) + n) * h / 2;
XGBOOST_DEVICE inline std::size_t DiscreteTrapezoidArea(std::size_t n, std::size_t h) {
n -= 1; // without diagonal entries
h = std::min(n, h); // Used for ranking, h <= n
std::size_t total = ((n - (h - 1)) + n) * h / 2;
return total;
}

Expand All @@ -29,12 +33,14 @@ XGBOOST_DEVICE inline size_t DiscreteTrapezoidArea(size_t n, size_t h) {
* Equivalent to loops like:
*
* \code
* for (size i = 0; i < h; ++i) {
* for (size_t j = i + 1; j < n; ++j) {
* for (std::size_t i = 0; i < h; ++i) {
* for (std::size_t j = i + 1; j < n; ++j) {
* do_something();
* }
* }
* \endcode
*
* with h <= n
*/
template <typename U>
inline size_t
Expand Down Expand Up @@ -79,6 +85,6 @@ XGBOOST_DEVICE inline void UnravelTrapeziodIdx(size_t i_idx, size_t n,

j = idx - n_elems + i + 1;
}
} // namespace common
} // namespace xgboost
#endif // XGBOOST_COMMON_RANKING_UTILS_H_
} // namespace common
} // namespace xgboost
#endif // XGBOOST_COMMON_THREADING_UTILS_CUH_
4 changes: 2 additions & 2 deletions src/metric/auc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <utility>

#include "../collective/device_communicator.cuh"
#include "../common/optional_weight.h" // OptionalWeights
#include "../common/ranking_utils.cuh"
#include "../common/optional_weight.h" // OptionalWeights
#include "../common/threading_utils.cuh" // UnravelTrapeziodIdx,SegmentedTrapezoidThreads
#include "auc.h"
#include "xgboost/data.h"
#include "xgboost/span.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* Copyright 2021 by XGBoost Contributors
* Copyright 2021-2023 by XGBoost Contributors
*/
#include <gtest/gtest.h>
#include "../../../src/common/ranking_utils.cuh"
#include <thrust/copy.h> // thrust::copy

#include "../../../src/common/device_helpers.cuh"
#include "../../../src/common/threading_utils.cuh"

namespace xgboost {
namespace common {

TEST(SegmentedTrapezoidThreads, Basic) {
size_t constexpr kElements = 24, kGroups = 3;
dh::device_vector<size_t> offset_ptr(kGroups + 1, 0);
Expand Down