PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

How to use the "PRINT" statements

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
steve.xu



Joined: 20 Feb 2012
Posts: 25

PostPosted: Wed Mar 21, 2012 7:22 am    Post subject: How to use the "PRINT" statements Reply with quote

I try to use the "print" statements, and write the test program like this:
Code:

   attributes(global) subroutine dev_test()
      print *, 'dev'
   end subroutine dev_test

   program main_test
      use cudafor
      call dev_test<<<1>>>()
      print *, cudaGetErrorString(cudaGetLastError())
   end program main_test

I use "pgfortran -Mcuda -ta=nvidia:cc20,cuda4.0 test.f90" to compile the program. But when I run it on Tesla M2050, I only get the "no error" message. what's wrong with it?
Back to top
View user's profile
mkcolg



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

PostPosted: Thu Mar 22, 2012 11:32 am    Post subject: Reply with quote

Hi Steve,

Your program is ending before it can get the print back from the device. Kernel calls are asynchronous to the host code and you have nothing to block the host's execution. Try adding a "cudaThreadSynchronize" just after the kernel call.

Note that also put your routine into a module since all global device routines must have an implicit or explicit interface. It's not causing the print problems, but would causing issues later if you tried to pass in any arguments.

Finally, you should avoid printing from the device since it will severely limit your performance.

- Mat

Code:
% cat prt.cuf
   module foo
   contains
   
   attributes(global) subroutine dev_test()
      print *, 'dev'
   end subroutine dev_test

   end module foo

   program main_test
      use cudafor
      use foo
      call dev_test<<<1>>>()
      ierr = cudaThreadSynchronize()
      print *, cudaGetErrorString(cudaGetLastError())
   end program main_test
% pgf90 prt.cuf; a.out
 dev
 no error
Back to top
View user's profile
steve.xu



Joined: 20 Feb 2012
Posts: 25

PostPosted: Thu Mar 22, 2012 6:26 pm    Post subject: Reply with quote

Thanks, Mat.
It works. But in my machine, the code
Code:

call dev_test<<<1>>>()

should be " call dev_test<<<1>>>() " . :-)

Quote:

- Mat

Code:
% cat prt.cuf
   module foo
   contains
   
   attributes(global) subroutine dev_test()
      print *, 'dev'
   end subroutine dev_test

   end module foo

   program main_test
      use cudafor
      use foo
      call dev_test<<<1>>>()
      ierr = cudaThreadSynchronize()
      print *, cudaGetErrorString(cudaGetLastError())
   end program main_test
% pgf90 prt.cuf; a.out
 dev
 no error
Back to top
View user's profile
steve.xu



Joined: 20 Feb 2012
Posts: 25

PostPosted: Fri Mar 23, 2012 8:04 am    Post subject: Reply with quote

I have an other question. In device code, how to print the value of a variable, which is a kind of real(8)? In my code, when I use the "print *" clause, it only print 6 decimals.
Back to top
View user's profile
mkcolg



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

PostPosted: Fri Mar 30, 2012 2:32 pm    Post subject: Reply with quote

Hi Steve,

I did some digging but there's not much we can do right now. We don't have a formatted print available, just list directed, and we're at the mercy of the underlying NVIDIA CUDA print, which looks to be giving only 6 decimals.

- Mat
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
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