问题描述
我尝试使用 ISHFT()
函数并行地对一些32位整数进行bithift转换,使用CUDA FORTRAN。
I'm trying to use the ISHFT()
function to bitshift some 32-bit integers in parallel, using CUDA FORTRAN.
问题是,我得到不同的答案 ISHFT(-4,-1)
和 ISHFT(var,-1)
,即使 var = -4
。这是我写的测试代码:
The problem is that I get different answers to ISHFT(-4,-1)
and ISHFT(var,-1)
even though var = -4
. This is the test code 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
然后编译并执行:
pgf90 testishft.f90 -Mcuda
./a.out
2147483646 -2
如果正常工作,两者都应该是2147483646。如果用 4
替换 var
,我得到正确的答案。
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
推荐答案
我找到一个解决方法,发布在此论坛:
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
而不是使用ISHFT我使用IBITS,其描述如下:
Instead of using ISHFT I use IBITS, which is described here: http://gcc.gnu.org/onlinedocs/gfortran/IBITS.html
此外,问题已经在PGI编译器的版本11.3中修复
Also the problem has since been fixed in version 11.3 of the PGI compilerhttp://www.pgroup.com/support/release_tprs_2011.htm
这篇关于CUDA FORTRAN:如果我传递变量而不是数字,函数给出不同的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!