__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]);
}
}
}
}
Asked
Active
Viewed 1,212 times
-2
-
4What is your question? – syntagma May 07 '15 at 23:50
-
1You have failed to ask a question. – David Hoelzer May 07 '15 at 23:52
1 Answers
4
You have marked the variable (kernel parameter) a1
as const
:
__global__ void conv(const float *a, const float *a1,
^^^^^ ^^
If you do that, you cannot modify the value pointed to by a1 in the kernel:
a1[i*n + j] = a[(i-1 + k)*n + (j+1-l)]*filter[k*3 + l];
^^
If you want to modify the contents of anything referenced by a1
in your kernel, then drop the const
from the parameter list.

Robert Crovella
- 143,785
- 11
- 213
- 257