Repository navigation
Simplify RF lower-bound and index types #8383
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
Merged
rapids-bot
merged 23 commits into
NVIDIA:main
from
RAMitchell:codex/enh-rf-idxt-lower-bound-cleanup
Jul 25, 2026
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0057de3
Use standard lower_bound for RF bin lookup
RAMitchell 8658088
Use int for RF internal index types
RAMitchell 0d9c7ec
Merge remote-tracking branch 'upstream/main' into codex/enh-rf-idxt-l…
RAMitchell 582b3cc
Use int64_t for RF internal indexes
RAMitchell 2bd6786
Merge remote-tracking branch 'upstream/main' into codex/enh-rf-idxt-l…
RAMitchell 570152e
Merge remote-tracking branch 'upstream/main' into codex/enh-rf-idxt-l…
RAMitchell e7711b6
Hard-code SparseTreeNode indexes to int64
RAMitchell d1574cd
Trim RF index template cleanup
RAMitchell 96d0d3d
Drop RF dataset header churn
RAMitchell d969d6d
Hard-code RF dataset and objective indexes
RAMitchell 7339254
Simplify RF split signatures
RAMitchell 809bd9e
Use int for RF num outputs
RAMitchell e8a94c2
Remove redundant RF int64 casts
RAMitchell f4f48eb
Address RF cleanup review comments
RAMitchell ad2a356
Address RF checked arithmetic review comments
RAMitchell 6d66390
Merge remote-tracking branch 'upstream/main' into codex/enh-rf-idxt-l…
RAMitchell 137d99a
Merge remote-tracking branch 'upstream/main' into codex/enh-rf-idxt-l…
RAMitchell 2c8ec70
Merge remote-tracking branch 'upstream/main' into codex/enh-rf-idxt-l…
RAMitchell 93e85ab
Merge branch 'main' into codex/enh-rf-idxt-lower-bound-cleanup
RAMitchell 251699a
Use int64 row counts in RF row sampler
RAMitchell d6d7df5
Merge branch 'main' into codex/enh-rf-idxt-lower-bound-cleanup
chyunsu3 38c40b3
Merge branch 'main' into codex/enh-rf-idxt-lower-bound-cleanup
chyunsu3 7e89e34
Set strict=false to test_voting::test_sample_weight[42] in cuml.accel…
chyunsu3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,10 @@ | |
| #include "../quantiles.h" | ||
| #include "../random_utils.cuh" | ||
|
|
||
| #include <cuml/common/checked_arithmetic.hpp> | ||
| #include <cuml/common/utils.hpp> | ||
|
|
||
| #include <raft/core/error.hpp> | ||
| #include <raft/linalg/unary_op.cuh> | ||
|
|
||
| #include <cuda/iterator> | ||
|
|
@@ -43,12 +45,11 @@ struct NodeWorkItem { | |
| * This struct has information about workload of a single threadblock of | ||
| * computeSplit kernels of classification and regression | ||
| */ | ||
| template <typename IdxT> | ||
| struct WorkloadInfo { | ||
| IdxT nodeid; // Node in the batch on which the threadblock needs to work | ||
| IdxT offset_blockid; // Offset threadblock id among all the blocks that are | ||
| // working on this node | ||
| IdxT num_blocks; // Total number of blocks that are working on the node | ||
| std::int64_t nodeid; // Node in the batch on which the threadblock needs to work | ||
| std::int64_t offset_blockid; // Offset threadblock id among all the blocks that are | ||
| // working on this node | ||
| std::int64_t num_blocks; // Total number of blocks that are working on the node | ||
| }; | ||
|
|
||
| struct SharedMemoryConfig { | ||
|
|
@@ -63,44 +64,47 @@ DI OutT* alignPointer(InT dataset) | |
| return reinterpret_cast<OutT*>(raft::alignTo(reinterpret_cast<size_t>(dataset), sizeof(OutT))); | ||
| } | ||
|
|
||
| template <typename IdxT> | ||
| void sample_features(IdxT* column_samples, | ||
| const NodeWorkItem* work_items, | ||
| size_t work_items_size, | ||
| IdxT treeid, | ||
| uint64_t seed, | ||
| IdxT sample_offset, | ||
| IdxT n, | ||
| IdxT k, | ||
| cudaStream_t stream) | ||
| inline void sample_features(std::int64_t* column_samples, | ||
| const NodeWorkItem* work_items, | ||
| size_t work_items_size, | ||
| std::int64_t treeid, | ||
| uint64_t seed, | ||
| std::int64_t sample_offset, | ||
| std::int64_t n, | ||
| std::int64_t k, | ||
| cudaStream_t stream) | ||
| { | ||
| auto n_column_samples = work_items_size * size_t(k); | ||
| auto counting = thrust::make_counting_iterator<size_t>(0); | ||
| RAFT_EXPECTS(k >= 0, "k must be non-negative"); | ||
| RAFT_EXPECTS(n >= k, "k must not exceed n"); | ||
|
|
||
| auto sampled_cols = ML::narrow_cast<std::size_t>(k); | ||
| auto n_column_samples = ML::checked_mul<std::size_t>(work_items_size, sampled_cols); | ||
| auto counting = thrust::make_counting_iterator<std::size_t>(0); | ||
|
|
||
| thrust::for_each(thrust::cuda::par.on(stream), | ||
| counting, | ||
| counting + n_column_samples, | ||
| [=] __device__(size_t sample_idx) { | ||
| auto node_idx = sample_idx / size_t(k); | ||
| IdxT column_index = static_cast<IdxT>(sample_idx % size_t(k)); | ||
| [=] __device__(std::size_t sample_idx) { | ||
| auto node_idx = sample_idx / sampled_cols; | ||
| auto column_index = static_cast<std::int64_t>(sample_idx % sampled_cols); | ||
|
|
||
| const uint32_t nodeid = work_items[node_idx].idx; | ||
| uint32_t rng_seed = fnv1a32_hash(seed, treeid, nodeid); | ||
| auto nodeid = work_items[node_idx].idx; | ||
| uint32_t rng_seed = fnv1a32_hash(seed, treeid, nodeid); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar issue over here with |
||
|
|
||
| cuda::shuffle_iterator<IdxT> shuffled_features( | ||
| cuda::shuffle_iterator<std::int64_t> shuffled_features( | ||
| n, cuda::std::minstd_rand(rng_seed), sample_offset); | ||
| column_samples[sample_idx] = shuffled_features[column_index]; | ||
| }); | ||
| } | ||
|
|
||
| template <typename DataT, typename LabelT, typename IdxT, int TPB> | ||
| void launchNodeSplitKernel(const Dataset<DataT, LabelT, IdxT>& dataset, | ||
| template <typename DataT, typename LabelT, int TPB> | ||
| void launchNodeSplitKernel(const Dataset<DataT, LabelT>& dataset, | ||
| const NodeWorkItem* work_items, | ||
| Split<DataT, IdxT>* splits, | ||
| const WorkloadInfo<IdxT>* workload_info, | ||
| Split<DataT>* splits, | ||
| const WorkloadInfo* workload_info, | ||
| size_t n_blocks_dimx, | ||
| size_t n_work_items, | ||
| IdxT* partition_row_ids, | ||
| std::int64_t* partition_row_ids, | ||
| cudaStream_t builder_stream); | ||
|
|
||
| template <typename DatasetT, typename NodeT, typename ObjectiveT, typename DataT> | ||
|
|
@@ -112,49 +116,29 @@ void launchLeafKernel(ObjectiveT objective, | |
| int batch_size, | ||
| size_t smem_size, | ||
| cudaStream_t builder_stream); | ||
| // Returns the lowest index in `array` whose value is greater or equal to `element`. | ||
| // Values outside the quantile range are clamped to the edge bins: values below the | ||
| // first quantile return 0, and values above the last quantile return len - 1. | ||
| template <typename DataT, typename IdxT> | ||
| HDI IdxT lower_bound(DataT const* array, IdxT len, DataT element) | ||
| { | ||
| IdxT start = 0; | ||
| IdxT end = len - 1; | ||
| IdxT mid; | ||
| while (start < end) { | ||
| mid = (start + end) / 2; | ||
| if (array[mid] < element) { | ||
| start = mid + 1; | ||
| } else { | ||
| end = mid; | ||
| } | ||
| } | ||
| return start; | ||
| } | ||
|
|
||
| template <typename DataT, typename LabelT, typename IdxT, int TPB, typename ObjectiveT> | ||
| template <typename DataT, typename LabelT, int TPB, typename ObjectiveT> | ||
| void launchBuildHistogramsKernel(typename ObjectiveT::BinT* histograms, | ||
| IdxT n_bins, | ||
| const Dataset<DataT, LabelT, IdxT>& dataset, | ||
| const Quantiles<DataT, IdxT>& quantiles, | ||
| std::int64_t n_bins, | ||
| const Dataset<DataT, LabelT>& dataset, | ||
| const Quantiles<DataT>& quantiles, | ||
| const NodeWorkItem* work_items, | ||
| IdxT colStart, | ||
| const IdxT* column_samples, | ||
| std::int64_t colStart, | ||
| const std::int64_t* column_samples, | ||
| ObjectiveT& objective, | ||
| const WorkloadInfo<IdxT>* workload_info, | ||
| const WorkloadInfo* workload_info, | ||
| dim3 histogram_grid, | ||
| const SharedMemoryConfig& split_smem_config, | ||
| cudaStream_t builder_stream); | ||
|
|
||
| template <typename DataT, typename LabelT, typename IdxT, int TPB, typename ObjectiveT> | ||
| template <typename DataT, typename LabelT, int TPB, typename ObjectiveT> | ||
| void launchFindBestSplitsKernel(typename ObjectiveT::BinT* histograms, | ||
| IdxT n_bins, | ||
| const Dataset<DataT, LabelT, IdxT>& dataset, | ||
| const Quantiles<DataT, IdxT>& quantiles, | ||
| IdxT colStart, | ||
| const IdxT* column_samples, | ||
| std::int64_t n_bins, | ||
| const Dataset<DataT, LabelT>& dataset, | ||
| const Quantiles<DataT>& quantiles, | ||
| std::int64_t colStart, | ||
| const std::int64_t* column_samples, | ||
| int* mutex, | ||
| volatile Split<DataT, IdxT>* splits, | ||
| volatile Split<DataT>* splits, | ||
| ObjectiveT& objective, | ||
| dim3 split_grid, | ||
| cudaStream_t builder_stream); | ||
|
|
@@ -168,7 +152,7 @@ inline void packHistograms(const BinT* in, double* out, std::size_t len, cudaStr | |
| { | ||
| // Counts are packed as doubles so each bin can use one homogeneous arithmetic buffer. This is | ||
| // exact for current RF problem sizes: integer values up to 2^53 are exactly representable by | ||
| // double, and IdxT row indexing is far below that limit. | ||
| // double, and RF row indexing is far below that limit. | ||
| auto op = [in] __device__(double* out, std::size_t i) { | ||
| auto const bin_idx = i / reduction_buffer_size_v<BinT>; | ||
| auto const field = i % reduction_buffer_size_v<BinT>; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.