curandGenerateNormalDouble 因生成大量随机数而崩溃

发布于 2024-10-01 12:27:11 字数 223 浏览 7 评论 0原文

是否有任何限制

curandGenerateNormal( curandGenerator_t 生成器, 浮动*outputPtr,size_t n, float 意味着,float stddev)

函数? curandGenerateNormal 在循环内调用,当我增加 size_t n 参数的大小时,代码在调用几次后开始崩溃。

有什么想法吗?

Is there any limitation of the

curandGenerateNormal(
curandGenerator_t generator,
float *outputPtr, size_t n,
float mean, float stddev)

function?
curandGenerateNormal is called inside a loop, when I increase the size of the size_t n parameter, the code started to crash when it has been called a few times.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

德意的啸 2024-10-08 12:27:11

您能详细说明崩溃时实际发生的情况吗?您检查所有错误值吗?

您的循环应该类似于下面的代码。 cudaMalloc 是否有可能在您不知情的情况下失败,因此您传递了无效的指针或类似的东西?

curandGenerator_t gen;
curandResult = curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
if (curandResult != CURAND_STATUS_SUCCESS)
{
    // throw or whatever
}

curandResult = curandSetPseudoRandomGeneratorSeed(gen, 1234ULL));
if (curandResult != CURAND_STATUS_SUCCESS)
{
    // throw or whatever
}

cudaResult = cudaMalloc((void **)&data, szend * sizeof(float));
if (cudaResult != cudaSuccess)
{
    // throw or whatever
}

for (unsigned int sz = szstart ; sz <= szend ; sz += szstep)
{
    float *data = 0;

    /* Could allocate and free the memory on each iteration,
       instead of allocating for the maximum size upfront...
    cudaResult = cudaMalloc((void **)&data, sz * sizeof(float));
    if (cudaResult != cudaSuccess)
    {
        // throw or whatever
    }
    */
    curandResult = curandGenerateNormal(gen, data, sz, mean, stddev);
    if (curandResult != CURAND_STATUS_SUCCESS)
    {
        // throw or whatever
    }
    /* If allocating on each iteration, need to free...
    cudaResult = cudaFree(data);
    if (cudaResult != cudaSuccess)
    {
        // throw or whatever
    }
    */
}
cudaResult = cudaFree(data);
if (cudaResult != cudaSuccess)
{
    // throw or whatever
}

curandResult = curandDestroyGenerator(&gen));
if (curandResult != CURAND_STATUS_SUCCESS)
{
    // throw or whatever
}

关于您的评论,请注意 curandGenerateNormalDouble 将生成具有给定平均值和标准差的正态分布数字,这与您要求它们在 0 和 1 之间的要求相冲突。您需要什么分布?

Can you elaborate on what actually happens when it crashes? Do you check all the error values?

Your loop should look something like the code below. Is it possible that the cudaMalloc is failing without your knowledge and hence you are passing an invalid pointer, or something similar?

curandGenerator_t gen;
curandResult = curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
if (curandResult != CURAND_STATUS_SUCCESS)
{
    // throw or whatever
}

curandResult = curandSetPseudoRandomGeneratorSeed(gen, 1234ULL));
if (curandResult != CURAND_STATUS_SUCCESS)
{
    // throw or whatever
}

cudaResult = cudaMalloc((void **)&data, szend * sizeof(float));
if (cudaResult != cudaSuccess)
{
    // throw or whatever
}

for (unsigned int sz = szstart ; sz <= szend ; sz += szstep)
{
    float *data = 0;

    /* Could allocate and free the memory on each iteration,
       instead of allocating for the maximum size upfront...
    cudaResult = cudaMalloc((void **)&data, sz * sizeof(float));
    if (cudaResult != cudaSuccess)
    {
        // throw or whatever
    }
    */
    curandResult = curandGenerateNormal(gen, data, sz, mean, stddev);
    if (curandResult != CURAND_STATUS_SUCCESS)
    {
        // throw or whatever
    }
    /* If allocating on each iteration, need to free...
    cudaResult = cudaFree(data);
    if (cudaResult != cudaSuccess)
    {
        // throw or whatever
    }
    */
}
cudaResult = cudaFree(data);
if (cudaResult != cudaSuccess)
{
    // throw or whatever
}

curandResult = curandDestroyGenerator(&gen));
if (curandResult != CURAND_STATUS_SUCCESS)
{
    // throw or whatever
}

With regard to your comment, note that curandGenerateNormalDouble will generate Normally distributed numbers with a given mean and standard deviation, that conflicts with your requirement that they be between 0 and 1. What distribution do you need?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文