开发者

CUDA FORTRAN: function gives different answer if I pass variable instead of number

I'm trying to use the ISHFT() function to bitshift some 32-bit integers in parallel, using CUDA FORTRAN.

The problem is that I get different answers to ISHFT(-4,-1) and ISHFT(var,-1) even though var = -4. This is the test co开发者_StackOverflow中文版de I've written:

module testshift 

  integer :: test 
  integer, device :: d_test 

contains 

  attributes(global) subroutine testshft () 
    integer :: var
    var = -4
    d_test = ISHFT(var,-1)
  end subroutine testshft

end module testshift

program foo 
  use testshift 

  integer :: i
  call testshft<<<1,1>>>() ! carry out ishft on gpu
  test = d_test            ! copy device result to host
  i = ISHFT(-4,-1)         ! carry out ishft on cpu
  print *, i, test         ! print the results
end program foo

I then compile and execute:

pgf90 testishft.f90 -Mcuda
./a.out 
   2147483646           -2

Both should be 2147483646 if working correctly. I get the right answer if I replace var with 4.

How do I fix this problem? Thanks for the help


When I remove the GPU-specific code from the above program I get 2147483646 2147483646 from the g95 compiler, as you expect. Have you tried running a "scalar" version of the program using the pgf90 compiler? If the scalar version works but the GPU version does not, that helps to isolate the problem. If the problem is pgf90/CUDA specific, perhaps the best place to ask your question is

PGI User Forum Forum Index -> Programming and Compiling http://www.pgroup.com/userforum/viewforum.php?f=4 .


I've found a workaround, which is posted in this forum: http://www.pgroup.com/userforum/viewtopic.php?t=2455&postdays=0&postorder=asc&start=15

Instead of using ISHFT I use IBITS, which is described here: http://gcc.gnu.org/onlinedocs/gfortran/IBITS.html

Also the problem has since been fixed in version 11.3 of the PGI compiler http://www.pgroup.com/support/release_tprs_2011.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜