Syntax errors?

Hi, I’m trying to debug some of my cudafortran code and keep getting this error:

PGF90-S-0034 Syntax error at or near device (and then the file/line number)

and it occurs for each of the following lines:

real, device, allocatable, DIMENSION(:):: val1
real, device, allocatable, DIMENSION(:):: val2

(and again for like 10 more variable all declared in this way but with different names)

Is this not the correct way to declare allocatable variables for use on the GPU?

It looks right. What compiler options are you using? Does your source file have the .cuf suffix?

Ah, in the Makefile I hadn’t set up the suffixes so there was no rule to build the .cuf file.

I do however have another question. When using CUDA in C, the command cudaMalloc would look like

cudaMalloc((void**)&rd, sizex); //for example

how would I call this in cudaFortran? I keep getting syntax errors when I try doing it in this fashion. I’m not particularly well versed in FORTRAN so I’m not sure how I would use this command. Thanks for the help!!

You have two choices, either the Fortran way or the cuda way.

If you want a real array, for instance, you can declare it like this:

real, device, allocatable, dimension(:) :: rd
integer sizex

and allocate it like this

sizex = 1000
allocate(rd(sizex))

Or, you can use the CUDA way:

istat = cudaMalloc(rd, sizex)

There are some subtle differences that have to do with Fortran allocatable semantics. Check out the section on allocating device and pinned arrays in the CUDA Fortran Programming Guide and Reference

Thanks! That helps a ton! I’ve been getting confused between the two languages. Which method would be preferable for allocating just variables (not arrays)?