Random number for GPU

来源:互联网 发布:新网域名证书生成 编辑:程序博客网 时间:2024/04/30 01:46

Efficient random number generation and application using CUDA

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch37.html


cuRAND: Nvidia random number generation library

https://developer.nvidia.com/cuRAND


Quick and easy gpu random numbers in D3D11:

http://www.reedbeta.com/blog/2013/01/12/quick-and-easy-gpu-random-numbers-in-d3d11/


A Fast high quality pseudo random number generator for nVidia CUDA

http://www0.cs.ucl.ac.uk/staff/ucacbbl/ftp/papers/langdon_2009_CIGPU.pdf


GPU pseudo random number: GPU TEA

http://www.csee.umbc.edu/~olano/papers/GPUTEA.pdf


/*
* Pseudo random number generator, based on "TEA, a tiny Encrytion Algorithm"
* http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.45.281&rep=rep1&type=pdf
* @param v - old seed (full 32bit range)
* @param IterationCount - >=1, bigger numbers cost more performance but improve quality
* @return new seed
*/
uint2 ScrambleTEA(uint2 v, uint IterationCount = 3)
{
    // Start with some random data (numbers can be arbitrary but those have been used by others and seem to work well)
    uint k[4] = { 0xA341316Cu, 0xC8013EA4u, 0xAD90777Du, 0x7E95761Eu };


    uint y = v[0];
    uint z = v[1];
    uint sum = 0;


    for (uint i = 0; i < IterationCount; ++i)
    {
        sum += 0x9e3779b9;
        y += (z << 4u) + k[0] ^ z + sum ^ (z >> 5u) + k[1];
        z += (y << 4u) + k[2] ^ y + sum ^ (y >> 5u) + k[3];
    }


    return uint2(y, z);
}



uint MortonCode(uint x)
{
    x = (x ^ (x << 2)) & 0x33333333;
    x = (x ^ (x << 1)) & 0x55555555;
    return x;
}




uint ReverseUIntBits(uint bits)
{
    bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2);
    bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1);
    return bits;
}

0 0
原创粉丝点击