cuda - 我应该让 cublas 处理全局并在不同的(主机)函数中重用它们吗?

标签 cuda cublas

我认为这可以节省一些配置时间,但我不确定这是否会导致意外行为。

最佳答案

如果您需要在任何类型的线程并发场景下发出调用,建议使用独立句柄:

https://docs.nvidia.com/cuda/cublas/index.html#thread-safety2

The library is thread safe and its functions can be called from multiple host threads, as long as threads do not share the same cuBLAS handle simultaneously.

另请注意,与特定 cublas handle 关联的设备预计在 handle 使用期间保持不变:

https://docs.nvidia.com/cuda/cublas/index.html#cublas-context

The device associated with a particular cuBLAS context is assumed to remain unchanged between the corresponding cublasCreate() and cublasDestroy() calls.

否则,即使在多个流之间共享,在属于同一设备和主机线程的 cublas 调用中使用单个句柄应该没问题。

CUDA batchCUBLAS sample code 中给出了使用单个“全局”句柄进行多个流式 CUBLAS 调用(来自同一主机线程,在同一 GPU 设备上)的示例。 .

关于cuda - 我应该让 cublas 处理全局并在不同的(主机)函数中重用它们吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51506917/

相关文章:

c++ - Ptx 程序集因错误而中止

c++ - 将 cuBLAS 与来自 Thrust 的复数结合使用

cuda - CUBLAS 中的异步和内存所有权

c++ - 蒙特卡罗横扫 Cuda

c - 尝试设置 QT Creator 和 Cuda 时“链接器输入文件未使用,因为链接未完成”

c++ - 为什么将函数传递给内核会导致数据变得不可变?

c++ - cuSolver 不返回正确的解决方案

c++ - 为 cublasSgemm 使用指向 vector<T>::data() 的指针

cuda - 内核中的新运算符..奇怪的行为