在CURAND中播种QUASI_SCRAMBLED_SOBOL64

时间:2015-07-18 05:27:26

标签: random cuda gpu gpgpu nvidia

如何为CURAND_RNG_QUASI_SCRAMBLED_SOBOL64发电机播种?因为每次运行它时它都给我相同的数字,我不能使用curandSetPseudoRandomGeneratorSeedCURAND_RNG_QUASI_SCRAMBLED_SOBOL64来生成带有curandGenerateLongLong的64位随机整数。

如何在以下代码中播种生成器?

size_t n = 10;
curandGenerator_t gen;
unsigned long long *devData, *hostData;

hostData = (unsigned long long *)calloc(n, sizeof(unsigned long long));

cudaMalloc(&devData, n*sizeof(unsigned long long));
curandCreateGenerator(&gen, curandRngType_t::CURAND_RNG_QUASI_SCRAMBLED_SOBOL64);

for (size_t j = 0; j < 3; j++)
{
    curandGenerateLongLong(gen, devData, n);
    cudaMemcpy(hostData, devData, n * sizeof(unsigned long long), cudaMemcpyDeviceToHost);
    for (size_t i = 0; i < 3; i++) {
        printf("%llx\n", hostData[i]);
    }
    printf("\n\n");
}

curandDestroyGenerator(gen);
cudaFree(devData);
free(hostData);

1 个答案:

答案 0 :(得分:2)

根据docuementation,准随机生成器,如您正在使用的SOBOL生成器,不使用种子。它们使用偏移量和尺寸向量来初始化生成器。

因此,代码中的初始化序列应该类似于

curandCreateGenerator(&gen, curandRngType_t::CURAND_RNG_QUASI_SCRAMBLED_SOBOL64);
curandSetGeneratorOffset (gen, std::time(0));
curandSetQuasiRandomGeneratorDimensions(gen, 10);