-2
   __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]);
            }
        }
    }

}
talonmies
  • 70,661
  • 34
  • 192
  • 269
braigns10
  • 1
  • 1

1 Answers1

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