相关疑难解决方法(0)

使用CUDA运行时API检查错误的规范方法是什么?

查看有关CUDA问题的答案和评论,以及CUDA标记维基,我发现通常建议每个API调用的返回状态都应该检查错误.API文档包括像功能cudaGetLastError,cudaPeekAtLastError以及cudaGetErrorString,但什么是把这些结合在一起,以可靠地捕捉和无需大量额外的代码报告错误的最好方法?

cuda error-checking

252
推荐指数
4
解决办法
9万
查看次数

在Cuda实施Max Reduce

我一直在学习Cuda,我仍然在处理并行问题.我目前遇到的问题是对一组值实现最大减少.这是我的内核

__global__ void max_reduce(const float* const d_array,
                     float* d_max,
                     const size_t elements)
{
    extern __shared__ float shared[];

    int tid = threadIdx.x;
    int gid = (blockDim.x * blockIdx.x) + tid;

    if (gid < elements)
        shared[tid] = d_array[gid];
    __syncthreads();

    for (unsigned int s=blockDim.x/2; s>0; s>>=1) 
    {
        if (tid < s && gid < elements)
            shared[tid] = max(shared[tid], shared[tid + s]);
        __syncthreads();
    }

    if (gid == 0)
        *d_max = shared[tid];
}
Run Code Online (Sandbox Code Playgroud)

我已经使用相同的方法(用min替换max函数)实现了min reduce,这很好.

为了测试内核,我使用串行for循环找到了最小值和最大值.最小值和最大值在内核中总是相同,但只有min reduce匹配.

有什么明显的东西我错过了/做错了吗?

parallel-processing cuda

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

cuda ×2

error-checking ×1

parallel-processing ×1