I’ve been programming using CUDA C for several years now and I’ve just been given the task of porting a large program over to CUDA from fortran, so I decided to give CUDA Fortran a go, however I have pretty much instantly hit a rather large roadblock.
As far as I can tell cudaSetDevice becomes inoperable as soon as I link a module which uses device memory. As far as I can tell I’m not doing anything particularly strange - just linking a module which never even gets used. Really struggling to understand how anybody could have successfully done this.
program test use cudafor implicit none integer istat istat = cudaSetDevice(0) print *,cudaGetErrorString(iStat) end program test
module breaker integer, device :: itWillNotWork contains attributes(global) subroutine EMPTY end subroutine EMPTY end module breaker
And the output:
$ pgfortran -o test -Mcuda test.f90 module.cuf $ ./test setting the device when a process is active is not allowed $ pgfortran -o test -Mcuda test.f90 $ ./test no error
In a slightly unrelated thing I’m finding the memory management and scoping to be really quite restrictive. In CUDA C it is possible to allocate device memory at any point in the program and use it at any other point. It seems in Fortran I have to have all my CUDA memory and all my CUDA kernels contained within one module, which clashes badly with how the code is currently structured. I should point out it’s inherited and I’m not a native Fortran programmer, but the current structure seems sane… except completely incompatible with the how CUDA Fortran wants my modules to be organised.