I have a project where I have to create a program in Visual Studio/CUDA using GPU Threads and Blocks that contain 2 random Arrays A
and B
used for computation before storing the result in a third Array C
the values based on this equation:
C(1,j)=max(A(:,j)+max(B(:,j))
(Note: the ":" operator means for all the lines)
Here is my Kernel function
__global__ void mykernel(int **a, int **b,int **c,const int width)
{
int col= threadIdx.x;
int tempa=0;
int tempb=0;
for(int k=0;k<width;k++){
int maxA=a[k][col];
if (maxA>tempa){
tempa=maxA;
}
int maxB=b[k][col];
if (maxB>tempb){
tempb=maxB;
}
}
c[0][col] =tempa+tempb;
}
And my main
int main()
{
const int dim= 5;
const int rows=5;
const int columns=5;
size_t dsize = rows*columns*sizeof(int);
//Αντίγραφα πινάκων δεδομένων της CPU
int *A[dim][dim];
int *B[dim][dim];
int *C[1][dim];
//Αντίγραφα πινάκων δεδομένων της GPU
int *d_A[dim][dim],*d_B[dim][dim],*d_C[1][dim];
//Εξασφάλιση μνήμης για τα αντίγραφα δεδομένων της CPU
A[dim][dim]= (int *)malloc(dsize);
B[dim][dim] = (int *)malloc(dsize);
C[1][dim]= (int *)malloc(dsize);
//Γέμισμα των πινάκων με τυχαίες τιμές μεταξυ
for (int i=0;i<rows;i++)
for (int j=0;j<columns;j++){
*A[i][j]=rand() %5+1;
*B[i][j]=rand() %5+1;
}
//Εξασφάλιση μνήμης για τα αντίγραφα δεδομένων της GPU και αντιγραφή δεδομένων CPU προς GPU
cudaMalloc((void **)&d_A, dsize);
cudaMemcpy(d_A, A, dsize, cudaMemcpyHostToDevice);
cudaMalloc((void **)&d_B, dsize);
cudaMemcpy(d_B, B, dsize, cudaMemcpyHostToDevice);
cudaMalloc((void **)&d_C, dsize);
//Κλήση Kernel συνάρτησης στην GPU με χρήση 5 Threads σε 1 Block
mykernel<<<1,5>>>(d_A,d_B,d_C,dim);
//Αντιγραφή αποτελέσματος στην μνήμη της CPU
cudaMemcpy(C, d_C, dsize, cudaMemcpyDeviceToHost);
//Εκκαθάριση Μνήμης για CPU και GPU
free(A);
free(B);
free(C);
cudaFree(d_A); cudaFree(d_B); cudaFree(d_C);
while(1){};
return 0;
}
I think I got the algorithm right but in this line I get the following error:
Line
mykernel<<<1,5>>>(d_A,d_B,d_C,dim);
Error
argument of type "int *(*)[5]" is incompatible with parameter of type "int **"
Any suggestions on what I should do?