我认为这可以节省一些配置时间,但我不确定这是否会导致意外行为。
最佳答案
如果您需要在任何类型的线程并发场景下发出调用,建议使用独立句柄:
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()
andcublasDestroy()
calls.
否则,即使在多个流之间共享,在属于同一设备和主机线程的 cublas 调用中使用单个句柄应该没问题。
CUDA batchCUBLAS
sample code 中给出了使用单个“全局”句柄进行多个流式 CUBLAS 调用(来自同一主机线程,在同一 GPU 设备上)的示例。 .
关于cuda - 我应该让 cublas 处理全局并在不同的(主机)函数中重用它们吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51506917/