Hi to everybody,
I’m compiling the following codes:
1.main.f90
program main
implicit none
integer, parameter :: N=512
integer :: k,i
! loop
do k = 1, N
end do
! Do the same computation with CUDA.
! Fortran -> C -> CUDA ->C ->Fortran
call cudafunction(valore,N)
Results
print , “valore=”, valore_[k]
end program main
2.Cuda_function.cu
#include
#include
#include “cuda.h”
/ Define CUDA kernel that fixes valore[k] = k /
global void square_complex(int valore[512][512], int k, int N)
{
const int i = blockIdx.xblockDim.x+threadIdx.x;
if( i<N )
{
valore[k] = k;
}
}
/*
Fortran subroutine arguments are passed by references.
*/
extern “C” void cudafunction_(int *valore, int *Np)
{
int block_size=4;
int *valore_d;
int N=Np;
/ Allocate complex array on device */
cudaMalloc ((void **) &valore_d , sizeof(int)N);
/ Copy array from host memory to device memory */
cudaMemcpy( valore_d, valore, sizeof(int)N ,cudaMemcpyHostToDevice);
/ Compute execution configuration /
dim3 dimBlock(block_size);
dim3 dimGrid (N/dimBlock.x);
if( N % block_size != 0 ) dimGrid.x+=1;
/ Execute the kernel /
square_complex<<>>(valore_d,Np);
/ Copy the result back */
cudaMemcpy(valore_d, sizeof(int)N,cudaMemcpyDeviceToHost);
/ Free memory on the device */
cudaFree(valore_d);
return;
}
The output of the compilation is:
Cuda_function.cu(45): error: argument of type “int " is incompatible with parameter of type "int ()[512]”
Cuda_function.cu(45): error: argument of type “int *” is incompatible with parameter of type “int”
Cuda_function.cu(45): error: too few arguments in function call
Cuda_function.cu(48): error: argument of type “unsigned long” is incompatible with parameter of type “const void *”
Cuda_function.cu(48): error: too few arguments in function call
5 errors detected in the compilation of “/tmp/tmpxft_00006dfd_00000000-4_Cuda_function.cpp1.ii”.
make: *** [Cuda_function.o] Error 2
Is there anybody that knows what is the problem?
Silvio._