0

从 CUDA 内核调用 CUB 类后是否需要调用 cudaDeviceSynchronize?当使用设备中的 DeviceReduce::Sum() 时,存在隐式内存副本会阻止设备继续运行,但在使用 GPU 上调用的以下代码后遇到了一些不稳定性:

__device__ void calcMonomerFlux(double* fluxes, double* lengths, double* dt) //temp2 temp1
{

    void *d_temp_storage = NULL;
    size_t temp_storage_bytes = 0;

    arrInitToLengths<<< numBlocks, numThreads >>>(lengths); 
    cudaDeviceSynchronize();
    arrMult<<< numBlocks, numThreads >>>(fluxes, lengths, lengths);
    cudaDeviceSynchronize();
    double sum = 0;

    cub::DeviceReduce::Sum(d_temp_storage, temp_storage_bytes, lengths, lengths, maxlength);
    //cudaDeviceSynchronize();

    cudaMalloc(&d_temp_storage, temp_storage_bytes);
    //cudaDeviceSynchronize();

    cub::DeviceReduce::Sum(d_temp_storage, temp_storage_bytes, lengths, lengths, maxlength);
    //cudaDeviceSynchronize();

    cudaFree(d_temp_storage);

}

4

1 回答 1

0

是的,每次 CUB 调用后都需要 cudaDeviceSynchronize()。请注意注释的同步调用在问题中的位置。我花了很多时间来追查为什么我的总和计算不正确甚至不一致。最终,我在通过 NSIGHT 调试器前进时发现,只有当我在每个 CUB 函数之后放置断点时,计算才会正确。

于 2014-08-28T04:39:07.457 回答