如何在 CUDA FORTRAN 中生成随机数?
我正在寻找一种简单的方法来为并行的多个线程生成 0.0 和 1.0 之间的随机浮点数。到目前为止,这是我的内核..
attributes(global) subroutine rand_kernel()
implicit none
integer :: tid
real :: r
! Thread ID
tid = threadIdx%x
! Generate random number
call <some random number generator> (r)
! Randomise array
d_array(tid) = r
end subroutine rand_kernel
我一直在论坛中查找并阅读 CURAND 手册,但我仍然不知道该怎么做。我什至不确定是否有 CUDA FORTRAN 的随机数库。 我只需要朝着正确的方向推动,然后我就可以为自己编写一个像样的随机数生成器。
感谢您的帮助
I'm looking for a simple way to generate a random floats between 0.0 and 1.0 for multiple threads in parallel. This is my kernel so far..
attributes(global) subroutine rand_kernel()
implicit none
integer :: tid
real :: r
! Thread ID
tid = threadIdx%x
! Generate random number
call <some random number generator> (r)
! Randomise array
d_array(tid) = r
end subroutine rand_kernel
I've been looking around in forums and reading the CURAND manual, but I still can't figure out what to do. I'm not even sure if there are any random number libraries for CUDA FORTRAN.
I just need a push in a right direction then I can write myself a decent random number generator.
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现一篇文章解释了如何从 CUDA Fortran 代码调用 CUDA C 实现的伪随机数生成器(CUDA SDK 中的 Mersenne Twister 实现)。
详细信息可以参见本文的“调用 CUDA C 随机数生成器”部分:
http://www.pgroup.com/lit/articles/insider/v2n1a4.htm
I found an article explaining how to call a CUDA C implemented pseudo-random number generator (the Mersenne Twister implementation from the CUDA SDK) from a CUDA Fortran code.
Details can be found in the section "Calling a CUDA C Random Number Generator" of this article:
http://www.pgroup.com/lit/articles/insider/v2n1a4.htm
您必须在 FORTRAN 中生成随机数并将其传输到设备。
you have to generate random numbers in FORTRAN and transfer it to device.