Hey guys, I’m new to cuda programming; below is my code for a game of life program. When I run it I get a Segmentation fault error, the debugger says the error is with the hBlockAll[i][j] = 0; line, but I’m not sure what this means or why I am getting this error.

#include <stdio.h>

#include <stdlib.h>

#include <cuda.h>

const int matrix = 10;

void gameOflifeOnDevice();

**global** void gameOfLifeOnGPU(int** dBlockAll,int** hBlockAll, int matrix);

int main(){

```
gameOflifeOnDevice();
getchar();
```

}

void gameOflifeOnDevice(){

```
int size = matrix * matrix * sizeof(float);
int **hBlockAll,**dBlockAll;
hBlockAll = (int**)malloc(size);
dBlockAll = (int**)malloc(size);
cudaMalloc(&hBlockAll,size);
cudaMalloc(&dBlockAll,size);
for(int i = 1 ; i < matrix ; i ++){
for(int j = 1 ; j < matrix ; j++){
hBlockAll[i][j] = 0;
}
}
cudaMemcpy(&dBlockAll, hBlockAll , size ,cudaMemcpyHostToDevice);
gameOfLifeOnGPU<<<1,100>>>(dBlockAll,hBlockAll,matrix);
cudaMemcpy(&hBlockAll, dBlockAll , size ,cudaMemcpyDeviceToHost);
for (int i = 1 ; i < matrix ; i++){
for (int j = 1 ; j < matrix ; j++){
printf("|%c",(hBlockAll[i][j] == 1)? 'x' : '-');
}
printf("|\n");
}
free(hBlockAll);
free(dBlockAll);
cudaFree(hBlockAll);
cudaFree(dBlockAll);
```

}

**global** void gameOfLifeOnGPU(int** dBlockAll,int** hBlockAll, int matrix){

```
int idx = (blockIdx.x * blockDim.x) + threadIdx.x;
int idy = (blockIdx.y * blockDim.y) + threadIdx.y;
int countx;
for(int x = 0 ; x <= idx ; x++)
{
for(int y = 0 ; y <= idy ; y++)
{
if (hBlockAll[x][y] == 1)
{
// check block around currsor
countx += hBlockAll[x][y+1];
countx += hBlockAll[x][y-1];
countx += hBlockAll[x+1][y];
countx += hBlockAll[x+1][y+1];
countx += hBlockAll[x+1][y-1];
countx += hBlockAll[x-1][y];
countx += hBlockAll[x-1][y-1];
countx += hBlockAll[x-1][y-1];
if (countx < 2) dBlockAll[x][y] = 0;
if (countx > 3) dBlockAll[x][y] = 0;
if (countx == 2 || countx == 3) dBlockAll[x][y] = 1;
}
else{
// check block around currsor
countx += hBlockAll[x][y+1];
countx += hBlockAll[x][y-1];
countx += hBlockAll[x+1][y];
countx += hBlockAll[x+1][y+1];
countx += hBlockAll[x+1][y-1];
countx += hBlockAll[x-1][y];
countx += hBlockAll[x-1][y-1];
countx += hBlockAll[x-1][y-1];
if (countx > 1 && countx < 4)
{
dBlockAll[x][y] = 1;
}
} // end if
}
}
```

}//gameOfLifeOnGPU