Is there a good random number generator available for OpenCL? I've looked at many, all are complicated, and I don't know which to use and which are good?
Thanks.
OpenCL random numbers
Started by Alienizer, Jan 10 2012 07:05 PM
9 replies to this topic
#1
Posted 10 January 2012 - 07:05 PM
#2
Posted 11 January 2012 - 11:41 AM
What we usually did in shaders for rendering was using noise textures. Basically just a buffer of precomputed random values. Can't you use something similar?
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#3
Posted 11 January 2012 - 01:14 PM
If you want a "stable" RNG that you can reproduce solutions with, then following .oisyn's suggestion is the way to go. I commonly use simplex noise due to its versatility. Another approach you can take is to implement a XORshift RNG (FYI I haven't tried this in OpenCL). It's simple to implement, but also unstable in a parallel environment. You would need to assign a seed to each work item to maintain stability.
http://www.nutty.ca - Being a nut has its advantages.
#4
Posted 11 January 2012 - 01:37 PM
Just a note, I've tried and successfully implemented XORshift RNG, that has been mentioned by The Nut in OpenCL - it works quite well
. Though as mentioned, you need to assign a seed to each work item (didn't do that first and it didn't work quite well).
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/
If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D
If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D
#5
Posted 11 January 2012 - 08:22 PM
Is there a way to use atom or anything so we don't have to pass a seed?
#6
Posted 12 January 2012 - 04:10 AM
Without seed you lose parallelism. Well, you can reduce size of seed array from one per work item to one per workgroup (local thread group, 1 compute unit, about 256 threads) and regenerate seeds with atomics, but it's nontrivial algorithm and you may lose performance and random quality.
Sorry my broken english!
#7
Posted 12 January 2012 - 06:04 PM
}:+()___ (Smile), on 12 January 2012 - 04:10 AM, said:
Without seed you lose parallelism. Well, you can reduce size of seed array from one per work item to one per workgroup (local thread group, 1 compute unit, about 256 threads) and regenerate seeds with atomics, but it's nontrivial algorithm and you may lose performance and random quality.
I see what you mean, but what I meant to say was, if there is a way to pass a seed on every call to the kernel so that the seed is global to all the work items and workgroup, and updated everytime the random function is called? More like a GPU thread safe seed update?
#8
Posted 12 January 2012 - 06:49 PM
It's possible but too slow. Work items in GPU execute single instruction at the exact same time. So it's easy to reach slowdown by factor ~100.
Sorry my broken english!
#9
Posted 13 January 2012 - 11:33 AM
Or you can build the seed into the structure you pass to the shaders.
It depends what you want to do, when I do my cloud simulations I use the old trick of using floating point textures and swapping buffers.
So you populate a texture with variables, run the shader on it and write the results to another texture. Then swap the textures.
You are limited in that you can only have 4 variables per pixel, so your equations have to be broken down into separate passes, but it's effective.
It depends what you want to do, when I do my cloud simulations I use the old trick of using floating point textures and swapping buffers.
So you populate a texture with variables, run the shader on it and write the results to another texture. Then swap the textures.
You are limited in that you can only have 4 variables per pixel, so your equations have to be broken down into separate passes, but it's effective.
#10
Posted 13 January 2012 - 04:24 PM
I now know the reason why GPUs don't have a random() function!
Thanks everyone.
Thanks everyone.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












