Skip to content
Closed
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
13 changes: 10 additions & 3 deletions cpp/include/nvforest/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ struct handle_t {
handle_t(raft::handle_t const& raft_handle) : raft_handle_{&raft_handle} {}
auto get_next_usable_stream() const
{
if (!raft_handle_) { return cuda_stream{}; }
return cuda_stream{raft_handle_->get_next_usable_stream().value()};
}
auto get_stream_pool_size() const { return raft_handle_->get_stream_pool_size(); }
auto get_stream_pool_size() const
{
if (!raft_handle_) { return std::size_t{}; }
return raft_handle_->get_stream_pool_size();
}
auto get_usable_stream_count() const { return std::max(get_stream_pool_size(), std::size_t{1}); }
void synchronize() const
{
raft_handle_->sync_stream_pool();
raft_handle_->sync_stream();
if (raft_handle_) {
raft_handle_->sync_stream_pool();
raft_handle_->sync_stream();
}
Comment on lines 30 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 6 'using[[:space:]]+cuda_stream|cudaStreamSynchronize|handle_t[[:space:]]*\{\}|get_next_usable_stream|\.synchronize[[:space:]]*\(' cpp

Repository: rapidsai/nvforest

Length of output: 9917


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- handle.hpp ---'
cat -n cpp/include/nvforest/handle.hpp

printf '%s\n' '--- cuda_stream.hpp ---'
cat -n cpp/include/nvforest/cuda_stream.hpp

printf '%s\n' '--- forest_model.hpp focused API and prediction ---'
sed -n '1,280p' cpp/include/nvforest/forest_model.hpp | cat -n

printf '%s\n' '--- README GPU example ---'
sed -n '70,130p' cpp/include/nvforest/README.md | cat -n

printf '%s\n' '--- synchronization and prediction call sites ---'
rg -n -C 5 'synchronize[[:space:]]*\(|get_next_usable_stream|predict\(' cpp/tests cpp/include/nvforest -g '*.{h,hpp,cpp,cu,md}'

Repository: rapidsai/nvforest

Length of output: 35447


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- copy implementation ---'
cat -n cpp/include/nvforest/detail/copy.hpp

printf '%s\n' '--- prediction implementations and CUDA launches ---'
rg -n -C 8 'cudaMemcpy|cudaMemcpyAsync|cudaMemcpy2D|cudaMemcpy2DAsync|<<<|cudaStream|stream[), ]' cpp/include/nvforest -g '*.{h,hpp,cu,cpp}'

printf '%s\n' '--- focused source invariant verifier ---'
python3 - <<'PY'
from pathlib import Path

handle = Path("cpp/include/nvforest/handle.hpp").read_text()
streams = Path("cpp/include/nvforest/cuda_stream.hpp").read_text()
model = Path("cpp/include/nvforest/forest_model.hpp").read_text()
readme = Path("cpp/include/nvforest/README.md").read_text()
copy = Path("cpp/include/nvforest/detail/copy.hpp").read_text()

checks = {
    "null handle returns default cuda stream": "if (!raft_handle_) { return cuda_stream{}; }" in handle,
    "null handle synchronize path has no sync call": (
        "if (raft_handle_) {" in handle
        and "raft_handle_->sync_stream_pool();" in handle
        and "raft_handle_->sync_stream();" in handle
    ),
    "cuda stream is CUDA stream in GPU builds": "using cuda_stream = cudaStream_t;" in streams,
    "stream synchronization uses cudaStreamSynchronize": "cudaStreamSynchronize(stream);" in streams,
    "handle stream reaches direct inference": "handle.get_next_usable_stream(), predict_type" in model,
    "handle stream reaches partition inference": "partition_out, partition_in, stream, predict_type" in model,
    "handle stream reaches partition copy": "partition_out.size(),\n                                            stream);" in model,
    "GPU README uses null handle": "auto handle = nvforest::handle_t{};" in readme,
    "copy API accepts explicit stream": "cuda_stream stream" in copy,
}

for name, result in checks.items():
    print(f"{'PASS' if result else 'FAIL'}: {name}")

if not all(checks.values()):
    raise SystemExit("source invariant check failed")
PY

Repository: rapidsai/nvforest

Length of output: 50373


Synchronize the default CUDA stream for null handles.

handle_t{} is used for GPU inference, and forest_model::predict submits inference and copy operations to its default CUDA stream. handle_t::synchronize() does nothing when raft_handle_ is null, so callers can read incomplete output after synchronization. Synchronize cuda_stream{} on this path, or reject null handles for GPU execution and document that contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/include/nvforest/handle.hpp` around lines 30 - 35, Update
handle_t::synchronize() so the null raft_handle_ path synchronizes the default
CUDA stream via cuda_stream{}; preserve the existing raft stream-pool and stream
synchronization when raft_handle_ is present.

}

private:
Expand Down
Loading