Skip to content

[Fix][Runtime] Run thrust sequence on the TVM CUDA stream - #21117

Open
yhna940 wants to merge 1 commit into
apache:mainfrom
yhna940:fix/issue-21116
Open

yhna940 wants to merge 1 commit into
apache:mainfrom
yhna940:fix/issue-21116

Conversation

@yhna940

@yhna940 yhna940 commented Dec 3, 2026

Copy link
Copy Markdown

thrust_sort called thrust::sequence without the TVM CUDA execution policy. As a result, sequence ran on the legacy default stream and synchronized. That races later par_nosync work and makes CUDA graph capture fail with cudaErrorStreamCaptureInvalidated.

On the segmented path, the argsort-order and segment-id buffers were allocated from the Thrust caching pool and never released. Each segmented sort without an explicit workspace kept 12 * size bytes of device memory.

Both sequence calls now take the stream policy. A scoped allocator owns the temporary buffers and returns them to the pool on every exit, including when a later Thrust call throws.

A Thrust contrib test checks three things: segmented sort results, that repeated segmented sorts do not grow device memory, and that 1D and 2D sorts can be captured on the TVM stream. The test skips when Thrust or CUDA is unavailable.

Fixes #21116

thrust::sequence in thrust_sort ignored the TVM stream policy, so it
synchronized the legacy default stream and invalidated CUDA graph
capture. Segmented sort also left its argsort-order and segment-id
buffers allocated in the thrust pool.

Pass the execution policy into both sequence calls and free those
buffers when the sort returns. Cover segmented results, repeated-call
GPU memory, and stream capture in the thrust tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant