Skip to content

Fix stream ordering for brute-force L2 sqrt post-processing - #2509

Open
dantegd wants to merge 2 commits into
NVIDIA:mainfrom
dantegd:fix-lsqrtpost-stream-ordering
Open

Fix stream ordering for brute-force L2 sqrt post-processing#2509
dantegd wants to merge 2 commits into
NVIDIA:mainfrom
dantegd:fix-lsqrtpost-stream-ordering

Conversation

@dantegd

@dantegd dantegd commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Run the fused brute-force KNN distance post-processing on the same selected CUDA stream as fusedL2Knn.

Problem

In brute_force_knn_impl(), a stream is selected using:

auto stream = raft::resource::get_next_usable_stream(handle, i);

fusedL2Knn is launched on this selected stream. For L2SqrtExpanded and L2SqrtUnexpanded, the subsequent square-root map is instead launched using the original handle, whose main stream may differ from the selected stream:

fusedL2Knn(..., stream, ...);

raft::linalg::map(
  handle,
  ...);

There is no dependency making the main stream wait for the selected stream before the map reads the KNN output. The later stream-pool synchronization does not repair this read-before-write race.

Under concurrent cuML HDBSCAN workloads using managed memory on GB300, the corrupted CUDA context was subsequently reported by RAFT MST as:

copy_if failed on 2nd step: cudaErrorIllegalAddress

Related cuML issue: NVIDIA/cuml#8510
Companion RAFT PR: NVIDIA/raft#3125

@dantegd
dantegd requested a review from a team as a code owner August 26, 2026 15:03
@dantegd dantegd added bug Something isn't working non-breaking Introduces a non-breaking change labels Aug 26, 2026
rapids-bot Bot pushed a commit to NVIDIA/raft that referenced this pull request Aug 26, 2026
Assign the cuRAND generator used by `MST_solver::alteration()` to the MST CUDA stream.

## Problem

`MST_solver::alteration()` allocates `rand_values` on the supplied stream and launches the alteration kernel on that stream, but the cuRAND generator is left on its default stream.

This permits the following ordering:

1. cuRAND starts writing `rand_values` on stream 0.
2. The alteration kernel starts reading `rand_values` on the MST stream.
3. There is no dependency between those streams.

Under concurrent HDBSCAN workloads using managed memory on GB300, this can eventually surface as an illegal address in a later operation. The downstream error observed by cuML was:

```cpp
copy_if failed on 2nd step: cudaErrorIllegalAddress
```

Related cuML issue: NVIDIA/cuml#8510
Companion cuVS PR: NVIDIA/cuvs#2509

Authors:
  - Dante Gama Dessavre (https://github.com/dantegd)

Approvers:
  - Divye Gala (https://github.com/divyegala)

URL: #3125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants