cuda fortran sample code

Currently I’m evaluating a trial version of CUDA Fortran compiler. I have just tested a sample source code “cufinfo.cuf” that can be found in C:\Program Files\PGI\win32\10.5\samples after installation.

program cufinfo
use cudafor

integer istat, num, numdevices

type(cudadeviceprop) :: prop

istat = cudaGetDeviceCount(numdevices)

do num = 0, numdevices-1
  istat = cudaGetDeviceProperties(prop, num)
  call printDeviceProperties(prop, num)
end do

end
!
subroutine printDeviceProperties(prop, num)
use cudafor
type(cudadeviceprop) :: prop
integer num
ilen = verify(prop%name, ' ', .true.)
write (*,900) "Device Number: "      ,num
write (*,901) "Device Name: "        ,prop%name(1:ilen)
write (*,903) "Total Global Memory: ",real(prop%totalGlobalMem)/1e9," Gbytes"
write (*,902) "sharedMemPerBlock: "  ,prop%sharedMemPerBlock," bytes"
write (*,900) "regsPerBlock: "       ,prop%regsPerBlock
write (*,900) "warpSize: "           ,prop%warpSize
write (*,900) "maxThreadsPerBlock: " ,prop%maxThreadsPerBlock
write (*,904) "maxThreadsDim: "      ,prop%maxThreadsDim
write (*,904) "maxGridSize: "        ,prop%maxGridSize
write (*,903) "ClockRate: "          ,real(prop%clockRate)/1e6," GHz"
write (*,902) "Total Const Memory: " ,prop%totalConstMem," bytes"
write (*,905) "Compute Capability Revision: ",prop%major,prop%minor
write (*,902) "TextureAlignment: "   ,prop%textureAlignment," bytes"
write (*,906) "deviceOverlap: "      ,prop%deviceOverlap
write (*,900) "multiProcessorCount: ",prop%multiProcessorCount
write (*,906) "integrated: "         ,prop%integrated
write (*,906) "canMapHostMemory: "   ,prop%canMapHostMemory
900 format (a,i0)
901 format (a,a)
902 format (a,i0,a)
903 format (a,f5.3,a)
904 format (a,2(i0,1x,'x',1x),i0)
905 format (a,i0,'.',i0)
906 format (a,l0)
return
end

After I compile this code by “pgfortran -ta=nvidia cufinfo.cuf”, two output files (object file library, exports library file) are not generated. It seems there is a problem with compiling or linking cuda fortran code, because when I tried a standard fortran code (f3.f90 in C:\Program Files\PGI\win32\10.5\samples), it worked fine.
Please give me an advice on what’s wrong and what I’m missing.
I’d greatly appreciate for your answer.

odyssey

Hi Odyssey,

Since this is CUDA Fortran, replace “-ta=nvidia” with the “-Mcuda” flag. On Linux, we added beta support for mixing CUDA Fortran (-Mcuda) and the PGI Accelerator model (-ta=nvidia), but on Windows you still need to keep them separate.

Hope this helps,
Mat

Hi Mat,

Thanks for reply. The compiling command and option are indicated on the top of the sample source code so we can use it for test. Is the option -Mcuda required? The extension of filename is .cuf. Anyway I tried to compile with the command lines such as “pgfortran -ta=nvidia -Mcuda cufinfo.cuf”, and “pgfortran -Mcuda cufinfo.cuf”, but it doesn’t work.

Please help.

Odyssey

Hi Odyssey,

Is the option -Mcuda required?

No, not if the file suffix is “.cuf”. I was using “-Mcuda” to be explicit about the language being used.

“pgfortran -Mcuda cufinfo.cuf”, but it doesn’t work.

I’ll need more details such as the specific error you’re seeing.

  • Mat

It seems that the process of compilation or execution doesn’t recognize the GPU processors in my computer. I have two GPU’s (GeForce GTX 285 and Tesla C1060) in my machine. I simplified the original source code as below so that it counts the number of devices.

program cufinfo

use cudafor

integer :: istat, numdevices

type(cudadeviceprop) :: prop

istat = cudaGetDeviceCount(numdevices)

print *, numdevices

end

The compilation process created the execution file, and when I ran the exe file, it ouput “0”, which is actually supposed to be “2”.
Please help.

FYI, My computer is AMD phenom ™ 2 x4 940 based machine with windows xp professional (32bit).

Odyssey

Hi Odyssey,

My best guess is that there is a problem with your NVIDIA drivers. Try updating your drivers to version 197.13 which is the latest and supports CUDA 3.0. http://developer.nvidia.com/object/cuda_3_0_downloads.html

Note, that instead of compiling the cufinfo program, you can use the PGI utility “pgaccelinfo” to get information about the GPU devices attached to your system.

Hope this helps,
Mat