PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Cuda_fortran_loop

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
polisilvio



Joined: 21 Feb 2012
Posts: 3

PostPosted: Wed Feb 22, 2012 8:13 am    Post subject: Cuda_fortran_loop Reply with quote

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[i][k]
end program main


2.Cuda_function.cu

#include <stdio>
#include <cuComplex>
#include "cuda.h"

/* Define CUDA kernel that fixes valore[i][k] = k */
__global__ void square_complex(int valore[512][512], int k, int N)
{

const int i = blockIdx.x*blockDim.x+threadIdx.x;

if( i<N )
{
valore[i][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<<<dimGrid>>>(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:
[color=red]
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.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group