PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

cudaSetDevice seems completely broken
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
JeremyAppleyard27093



Joined: 20 Apr 2010
Posts: 4

PostPosted: Thu Apr 29, 2010 6:35 am    Post subject: cudaSetDevice seems completely broken Reply with quote

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.

test.f90:
Code:

program test
      use cudafor
      implicit none

      integer istat
      istat = cudaSetDevice(0)
      print *,cudaGetErrorString(iStat)
end program test


module.cuf:
Code:
module breaker
      integer, device :: itWillNotWork

contains
      attributes(global) subroutine EMPTY

      end subroutine EMPTY
end module breaker


And the output:
Code:

$ 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.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6129
Location: The Portland Group Inc.

PostPosted: Thu Apr 29, 2010 4:42 pm    Post subject: Reply with quote

Hi Jeremy,

Thank you for bring this problem to our attention. The problem is that in order to support data initialization of module device variables, allocation of all module device variables needs to occur at during the program's initialization phase at start-up. As you have discovered, this will prevent a user from being able change the device. I have sent a report to our engineers (TPR#16895) and they agree that this is a serious problem. We will give it our highest priority.


Quote:
In CUDA C it is possible to allocate device memory at any point in the program and use it at any other point.
I don't believe this is entirely correct. It's my understanding that CUDA C only allows you do this only within the same file scope. Granted, you can include all your source files into a single file. Fortran doesn't have file scoping. The closest approximation to file scope is module scope.

Unfortunately, there isn't a linker for device code. Hence, there is no way to associate external device symbols. This is why you can not call device function contained in different modules or directly access device data from other modules.

Device data managed by the host code can be passed to any CUDA Fortran or CUDA C global routine. Can you rearrange the code so that the shared device data be managed by the host?

- Mat
Back to top
View user's profile
JeremyAppleyard27093



Joined: 20 Apr 2010
Posts: 4

PostPosted: Fri Apr 30, 2010 10:09 am    Post subject: Reply with quote

Thanks. I think I must have got confused somewhere with respect to moving device data around. I'm not quite sure why I thought it worked like I thought it worked. I think I understand now though!

Another thing that is currently annoying me is that there seems to be an odd glitch when passing scaler variables by reference from a device subprogram with attributes global to one with attributes device. The variable declaration on the global side for some reason needs to be declared with a double colon otherwise you get a type mismatch error.

Code:

module test
contains
        attributes(device) subroutine dTest(a)
                real a !or real :: a
                a = a + 1
        end subroutine


        attributes(global) subroutine gTEST
                ! Comment as required
                !real :: a ! Works
                real    a ! Fails
                call dTEST(a)
        end subroutine
end module


Code:
$ pgfortran -c refdevpass.cuf
PGF90-S-0188-Argument number 1 to dtest: type mismatch (refdevpass.cuf: 12)
  0 inform,   0 warnings,   1 severes, 0 fatal for gtest


As previously mentioned I'm not as fluent in Fortran as I perhaps could be but I was under the impression that the double colon wasn't necessary in such a case. I have some host code that compiles fine without the double colon.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6129
Location: The Portland Group Inc.

PostPosted: Fri Apr 30, 2010 12:03 pm    Post subject: Reply with quote

Hi Jeremy,

Thanks, you found another one. Yes we should still be supporting the F77 syntax. I've sent a report to our engineers (TPR#16898). We've missed the cut-off to get fixes into the May release (10.5), but hopefully we can have it be fixed by 10.6 (June).

We definitely appreciate the feed-back so if you have any other things that don't seem quite right, please let up know.

- Mat
Back to top
View user's profile
JeremyAppleyard27093



Joined: 20 Apr 2010
Posts: 4

PostPosted: Wed May 05, 2010 9:21 am    Post subject: Reply with quote

Just another small one - the -C compiler flag seems to cause:

Code:
PGF90-F-0000-Internal compiler error. unsupported procedure


When compiling a file containing CUDA kernels. Tested it on the matrix multiply example.

If I notice any more should I just tack them on to this thread or should I make new threads?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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