__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]);
}
}
}
}
答案 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
。