使用 thrust::reduce 捕获 CUDA 图形流

CUDA graph stream capture with thrust::reduce

当我尝试捕获流执行以构建 CUDA 图形时,调用 thrust::reduce 会导致运行时错误 cudaErrorStreamCaptureUnsupported: operation not permitted when stream is capturing。我已经尝试将缩减结果返回到主机和设备变量,并且我正在通过 thrust::cuda::par.on(stream) 的方式在适当的流中调用缩减。有什么方法可以将 thrust 函数执行添加到 CUDA 图形中吗?

Thrust的reduction操作是host端的阻塞操作。我假设您将缩减结果用作以下内核之一的参数。因此,当您捕获 CUDA 图时,它无法实例化图可执行文件,因为您依赖于主机端的变量,但在缩减内核完成执行之前不可用。作为一种解决方案,您可以尝试将一个主机节点添加到您的图形中,该节点 returns 是缩减的结果。