我在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