【问题标题】:The type of random number generator in cuRAND kernelscuRAND 内核中随机数生成器的类型
【发布时间】:2019-08-12 03:47:01
【问题描述】:

问题How to generate random number inside pyCUDA kernel?中报道了一个CUDA或pyCUDA中随机数生成的典型例子,即

#include <curand_kernel.h>

const int nstates = %(NGENERATORS)s;
__device__ curandState_t* states[nstates];

__global__ void initkernel(int seed)
{
    int tidx = threadIdx.x + blockIdx.x * blockDim.x;

    if (tidx < nstates) {
        curandState_t* s = new curandState_t;
        if (s != 0) {
            curand_init(seed, tidx, 0, s);
        }

        states[tidx] = s;
    }
}

__global__ void randfillkernel(float *values, int N)
{
    int tidx = threadIdx.x + blockIdx.x * blockDim.x;

    if (tidx < nstates) {
        curandState_t s = *states[tidx];
        for(int i=tidx; i < N; i += blockDim.x * gridDim.x) {
            values[i] = curand_uniform(&s);
        }
        *states[tidx] = s;
    }
}

使用这个经典示例,激活的随机数生成器是什么(XORWOWMTGP32、其他)?

如何从内核中更改随机数生成器?

【问题讨论】:

  • 在 cuRand 设备 API 文档中有完整记录
  • @talonmies 据我了解,要强制cuRAND 使用Philox_4x32_10 生成器,将上面示例中的curandState_t 更改为curandStatePhilox4_32_10_t 就足够了。

标签: cuda curand


【解决方案1】:

curand 设备 API 中的默认生成器是 XORWOW,由

定义
typedef struct curandStateXORWOW curandState_t;

在设备 API 标头中。您可以通过将另一个状态类型替换为 curandInit 调用来更改为另一个生成器。请注意,与默认值相比,某些生成器需要 curandInit 例程的不同参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2021-09-11
    • 1970-01-01
    相关资源
    最近更新 更多