Hello Forum,
I’m a raw beginner in CUDA programing. When I run the attached program the following error-messages occour:
When I change X and Y to:
the error messages change to:
Does anyone please can help me - or give me a hint to solve this error? Maybe it’s quite simple… but I can’t figure it out External Media
Enclosed I attached the source code.
Thank you very much for your help and your time.
Best regards,
Sandra
#include <cuda.h>
#include <stdio.h>
#include <cutil_inline.h>
// Kernel that executes on the CUDA device
__global__ void filter(int *grey[X][Y], int *color[X][Y])
{
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x > 1 && y > 1 && x < X-1 && y < Y-1)
{
color[x][y] = grey[x-1][y-1] +
grey[x][y-1] +
grey[x+1][y-1] +
grey[x-1][y] +
grey[x+1][y] +
grey[x-1][y+1] +
grey[x][y+1] +
grey[x+1][y+1];
}
}
int main(void)
{
int X = 10;
int Y = 10;
int elemente = X * Y;
int size = elemente * sizeof(int);
int** ENbayered_h = new int[X][Y]; // Allocate array on host
int** DEbayered_h = new int[X][Y]; // Allocate array on host
int** ENbayered_d;
int** DEbayered_d;
cudaMalloc((void **) &ENbayered_d, size); // Allocate array on device
cudaMalloc((void **) &DEbayered_d, size); // Allocate array on device
// blocksize
int block_size = 256;
// number of blocks
int n_blocks = elemente/block_size + (size%block_size == 0 ? 0:1);
// Initialize host array
for (int i=0; i<X; i++)
{
for (int j=0; j<Y; j++)
{
ENbayered_h[i][j] = 1; // enbayered grey values
}
}
cudaMemcpy(ENbayered_d, ENbayered_h, size, cudaMemcpyHostToDevice);
filter <<< n_blocks, block_size >>> (ENbayered_d, DEbayered_d);
cudaMemcpy(DEbayered_h, DEbayered_d, size, cudaMemcpyDeviceToHost);
free(ENbayered_h);
free(DEbayered_h);
cudaFree(ENbayered_d);
cudaFree(DEbayered_d);
}