小编Dar*_*ane的帖子

CUDA索引不能按预期工作

我正在尝试使用PyCUDA处理2D数组,我需要每个线程的x,y坐标.

这里这里已经提出并回答这个问题,但链接的解决方案对我来说对于超过块大小的2D数据不起作用.为什么?

这是我用来帮助解决这个问题的SourceModule:

mod = SourceModule("""
  __global__ void kIndexTest(float *M, float *X, float*Y)
  {
    int bIdx = blockIdx.x + blockIdx.y * gridDim.x; 
    int idx = bIdx * (blockDim.x * blockDim.y) + (threadIdx.y * blockDim.x) + threadIdx.x;

    /* this array shows me the unique thread indices */
    M[idx] = idx;

    /* these arrays should capture x, y for each unique index */    
    X[idx] = (blockDim.x * blockIdx.x) + threadIdx.x;
    Y[idx] = (blockDim.y * blockIdx.y) + threadIdx.y; …
Run Code Online (Sandbox Code Playgroud)

indexing cuda nvidia pycuda

2
推荐指数
1
解决办法
751
查看次数

标签 统计

cuda ×1

indexing ×1

nvidia ×1

pycuda ×1