与CUDA C卷积,错误:表达式必须是可修改的左值

时间:2015-05-07 23:50:10

标签: c cuda convolution hpc

   __global__ void conv(const float *a, const float *a1,
        const size_t n) {
    // compute the global element index this thread should process
    unsigned int i = threadIdx.x + blockDim.x * blockIdx.x;
    unsigned int j = threadIdx.y + blockDim.y * blockIdx.y;
    // avoid accessing out of bounds elements

    float filter[9] = { -1, -1, -1, -1, 9, -1, -1, -1, -1 };
    if (i < n) {
        for (int k = 0; k < 3; k++) {
            printf("%d", filter[k]);
            for (int l = 0; l < 3; l++) {
                //printf("%d",a[((i-1) + k)*n + (j+1-l)]);
                a1[i*n + j] = a[(i-1 + k)*n + (j+1-l)]*filter[k*3 + l];
                printf("%d", a[i]);
            }
        }
    }

}

1 个答案:

答案 0 :(得分:3)

您已将变量(内核参数)a1标记为const

__global__ void conv(const float *a, const float *a1,
                                     ^^^^^        ^^

如果这样做,则无法修改内核中a1指向的值:

 a1[i*n + j] = a[(i-1 + k)*n + (j+1-l)]*filter[k*3 + l];
 ^^

如果要修改内核中a1引用的任何内容,请从参数列表中删除const