我在Stack Overflow上读了两篇文章,分别是Will the cublas kernel functions automatically be synchronized with the host?和CUDA Dynamic Parallelizm; stream synchronization from device,他们建议在调用cuBLAS函数后使用一些同步API,例如cudaDeviceSynchronize()
。我不确定使用这种通用功能是否合理。cuBLAS同步最佳实践
按照以下方法做更好吗? [纠正我,如果我错了]:
cublasHandle_t cublas_handle;
cudaStream_t stream;
// Initialize the matrices
CUBLAS_CALL(
cublasDgemm(cublas_handle, CUBLAS_OP_N, CUBLAS_OP_N, M, M,
M, &alpha, d_A, M, d_B, M, &beta, d_C, M));
// cublasDgemm is non-blocking!
cublasGetStream(cublas_handle, &stream);
cudaStreamSynchronize(stream);
// Now it is safe to copy the result (d_C) from the device
// to the host and use it
在另一方面,cudaDeviceSynchronize
可以优选如果大量流/手柄被用来执行并行CUBLAS操作使用。什么是cuBLAS手柄同步的“最佳实践”? cuBLAS句柄可以被认为是流的包装器,从同步的角度来看,它们可以达到同样的目的吗?
你不喜欢cudaDeviceSynchronize的原因是什么?另外,在你的例子中,你没有在cuBLAS调用之前设置流。最后,为什么要发挥流?对于只有一个流,将流同步pdrform不同于设备同步? – JackOLantern